반응형
php-fpm 프레임과 swoole 프레임 성능 대비
환경
deepin15.11, php7.2.9, nginx1.16.1, mysql5.7, ab2.3
대비틀
FPM 프레임워크: laravel6, swoole 프레임워크: easyswoole3, golang 1.14.2
대비 차원
1:단회 계산 능력
php-cli
<?php
$stime = microtime(true);
for ($a=1;$a<=1000;$a++){
for ($b=1;$b<=1000;$b++){
for ($c=1;$c<=1000;$c++){
if ($a == $b && $b==$c){
}
}
}
}
$etime = microtime(true);
$ret = bcsub($etime,$stime,4);
var_dump($ret);
golang
func main() {
start :=time.Now()
for a:=1; a<=1000 ; a++ {
for b:=1; b<=1000;b++ {
for c:=1;c<=1000 ;c++ {
if a== b&& b==c {
//fmt.Println(a*c*c)
}
}
}
}
end := time.Now().Sub(start)
fmt.Println(end)
}
실행 결과:
php-cli:13.5324 s
골랑:314.06603ms
2:합병 계산 능력
ab-c 100-n 10000 계산 실행, 실행링 100000회
easyswoole: Time taken for tests: 47.550 seconds
golang: Time taken for tests: 1.337 seconds
3: 운영 데이터베이스
//easyswoole
$model = new UserModel();
$model->name = "easyswoole".mt_rand(1,99999999);
$model->create_at = date('Y-m-d H:i:s');
$model->update_at = date('Y-m-d H:i:s');
$model->save();
//laravel
$model = new User();
$model->name = "laravel".mt_rand(1,99999999);
$model->save();
return $model->id;
매번 100건의 청구가 있는데, 모두 만 건을 청구하고 있다.
ab-n 10000-c 100
테스트 결과
이지스울
Server Software: nginx
Server Hostname: easyswoole3.wlz.me
Server Port: 80
Document Path: /user/index
Document Length: 0 bytes
Concurrency Level: 100
Time taken for tests: 1.774 seconds
Complete requests: 10000
Failed requests: 0
Total transferred: 1340000 bytes
HTML transferred: 0 bytes
Requests per second: 5637.87 [#/sec] (mean)
Time per request: 17.737 [ms] (mean)
Time per request: 0.177 [ms] (mean, across all concurrent requests)
Transfer rate: 737.77 [Kbytes/sec] received
Connection Times (ms)
min mean[+/-sd] median max
Connect: 0 1 0.5 1 3
Processing: 8 17 5.1 16 73
Waiting: 8 16 5.1 15 72
Total: 8 18 5.1 17 73
Percentage of the requests served within a certain time (ms)
50% 17
66% 17
75% 18
80% 18
90% 19
95% 22
98% 35
99% 42
100% 73 (longest request)
laravel
Server Software: nginx
Server Hostname: la6.wlz.me
Server Port: 80
Document Path: /test/abtest1
Document Length: 5 bytes
Concurrency Level: 100
Time taken for tests: 149.231 seconds
Complete requests: 10000
Failed requests: 0
Total transferred: 9106338 bytes
HTML transferred: 50000 bytes
Requests per second: 67.01 [#/sec] (mean)
Time per request: 1492.314 [ms] (mean)
Time per request: 14.923 [ms] (mean, across all concurrent requests)
Transfer rate: 59.59 [Kbytes/sec] received
Connection Times (ms)
min mean[+/-sd] median max
Connect: 0 0 0.2 0 3
Processing: 66 1485 574.9 1423 7027
Waiting: 63 1485 574.9 1423 7027
Total: 66 1485 574.9 1423 7027
Percentage of the requests served within a certain time (ms)
50% 1423
66% 1471
75% 1503
80% 1524
90% 1585
95% 1656
98% 2056
99% 5498
100% 7027 (longest request)
golang
func save(w http.ResponseWriter, r *http.Request) {
defer r.Body.Close()
mysql_sqx.InsertRow()
w.Write([]byte("ok"))
}
// 데이터 삽입
func InsertRow() {
sqlStr := "insert into w_users(name, created_at,updated_at) values (?,?,?)"
ret, err := db.Exec(sqlStr, "wlz11", "2020-04-09 11:51:59","2020-04-09 11:51:59")
if err != nil {
fmt.Printf("insert failed, err:%v\n", err)
return
}
theID, err := ret.LastInsertId() // 데이터를 새로 삽입한 id
if err != nil {
fmt.Printf("get lastinsert ID failed, err:%v\n", err)
return
}
fmt.Printf("insert success, the id is %d.\n", theID)
}
```bash
Server Software:
Server Hostname: 127.0.0.1
Server Port: 9090
Document Path: /save
Document Length: 2 bytes
Concurrency Level: 100
Time taken for tests: 1.687 seconds
Complete requests: 10000
Failed requests: 0
Total transferred: 1180000 bytes
HTML transferred: 20000 bytes
Requests per second: 5925.95 [#/sec] (mean)
Time per request: 16.875 [ms] (mean)
Time per request: 0.169 [ms] (mean, across all concurrent requests)
Transfer rate: 682.87 [Kbytes/sec] received
Connection Times (ms)
min mean[+/-sd] median max
Connect: 0 1 0.4 1 3
Processing: 5 16 2.0 16 34
Waiting: 5 16 2.0 15 34
Total: 7 17 2.0 16 35
Percentage of the requests served within a certain time (ms)
50% 16
66% 17
75% 17
80% 18
90% 18
95% 19
98% 23
99% 25
100% 35 (longest request)
데이터를 읽다
100개의 데이터를 수집하다
//easyswoole
$data = UserModel::create()->where("id >=30000")->limit(100)->all();
$this->response()->write(json_encode($data));
//laravel
return DB::table('users')
->where('id', '>=',30000)
->limit(100)
->get();
매번 100건의 청구가 있는데, 모두 만 건을 청구하고 있다.
ab-n 10000-c 100
테스트 결과
이지스울
Server Software: nginx
Server Hostname: easyswoole3.wlz.me
Server Port: 80
Document Path: /user/index
Document Length: 10807 bytes
Concurrency Level: 100
Time taken for tests: 3.898 seconds
Complete requests: 10000
Failed requests: 0
Total transferred: 109680000 bytes
HTML transferred: 108070000 bytes
Requests per second: 2565.20 [#/sec] (mean)
Time per request: 38.983 [ms] (mean)
Time per request: 0.390 [ms] (mean, across all concurrent requests)
Transfer rate: 27475.72 [Kbytes/sec] received
Connection Times (ms)
min mean[+/-sd] median max
Connect: 0 0 0.6 0 7
Processing: 5 39 12.6 36 192
Waiting: 2 38 12.6 35 187
Total: 5 39 12.6 36 192
Percentage of the requests served within a certain time (ms)
50% 36
66% 39
75% 41
80% 43
90% 55
95% 64
98% 75
99% 82
100% 192 (longest request)
laravel
Server Software: nginx
Server Hostname: la6.wlz.me
Server Port: 80
Document Path: /test/abtest1
Document Length: 10807 bytes
Concurrency Level: 100
Time taken for tests: 148.857 seconds
Complete requests: 10000
Failed requests: 0
Total transferred: 117046492 bytes
HTML transferred: 108070000 bytes
Requests per second: 67.18 [#/sec] (mean)
Time per request: 1488.570 [ms] (mean)
Time per request: 14.886 [ms] (mean, across all concurrent requests)
Transfer rate: 767.87 [Kbytes/sec] received
Connection Times (ms)
min mean[+/-sd] median max
Connect: 0 0 0.4 0 5
Processing: 67 1480 799.2 1380 8338
Waiting: 60 1480 799.2 1380 8338
Total: 67 1480 799.2 1380 8338
Percentage of the requests served within a certain time (ms)
50% 1380
66% 1426
75% 1456
80% 1477
90% 1542
95% 1615
98% 1935
99% 7050
100% 8338 (longest request)
골랑
매번 100건의 요청모두 만 번을 청하다
ab-n 10000-c 100
func main() {
http.HandleFunc("/find",findAll)
http.HandleFunc("/",index)
http.ListenAndServe("127.0.0.1:9090",nil)
}
func findAll(w http.ResponseWriter, r *http.Request) {
defer r.Body.Close()
userList,err := mysql_sqx.FindAll()
if err != nil {
fmt.Printf("query failed, err:%v\n", err)
}
userListStr,_ := json.Marshal(userList)
w.Write([]byte(userListStr))
}
func FindAll() ([]WUser, error) {
sqlStr := "select * from w_users where id>? limit ?"
userList := make([]WUser,0,2)
err := db.Select(&userList, sqlStr,30000,100)
if err != nil {
return nil, nil
}
return userList,err
}
테스트 결과
Server Software:
Server Hostname: 127.0.0.1
Server Port: 9090
Document Path: /find
Document Length: 10604 bytes
Concurrency Level: 100
Time taken for tests: 1.408 seconds
Complete requests: 10000
Failed requests: 0
Total transferred: 107010000 bytes
HTML transferred: 106040000 bytes
Requests per second: 7100.29 [#/sec] (mean)
Time per request: 14.084 [ms] (mean)
Time per request: 0.141 [ms] (mean, across all concurrent requests)
Transfer rate: 74199.43 [Kbytes/sec] received
Connection Times (ms)
min mean[+/-sd] median max
Connect: 0 0 0.3 0 3
Processing: 1 14 8.0 13 62
Waiting: 0 13 8.0 12 62
Total: 1 14 8.0 13 63
Percentage of the requests served within a certain time (ms)
50% 13
66% 16
75% 19
80% 20
90% 25
95% 29
98% 33
99% 37
100% 63 (longest request)
결론
1. 계산능력시험
– 1회 요청, 100억회 루프 계산
easyswoole 소요시간:13.5324초
golang 소요시간: 0.314초
– 동시수 100, 요청수 1만회, 싱글2차 계산 내용 100만 회 순환
easyswoole:타임트aken for tests:47.550 세컨즈
golang:Timeaken for tests: 1.337 세컨즈
2. 운영 데이터베이스
데이터를 삽입하는 데 시간이 걸리다:
golang :1.687초
easyswoole: 1.774초
laravel :149.231 초
데이터를 읽는 데 시간이 걸리다:
golang :1.408초
easyswoole: 3.898 초
laravel :148.857 초
계산능력 해석형 언어와 컴파일형 차이는 여전히 크고, mysql 읽기·쓰기 easyswoole과 golang은 비슷했다.라라벨 차이가 많이 나네요
반응형
'개발 꿀팁 > PHP' 카테고리의 다른 글
PHP에서 페이지 점프 (0) | 2022.09.19 |
---|---|
PHP 객체 지향 요점 (0) | 2022.09.19 |
PhpSpreadsheet 중국어 문서 | Spreadsheet 작업 튜토리얼 예제 (0) | 2022.09.16 |
php 생성 PDF에 사용되는 클래스 MPDF (1) | 2022.09.16 |
PHP 조작 Excel – PHP Excel 기본 사용법 상세 (0) | 2022.09.15 |