php5.5/php7/swoole/openresty 压测性能对比
2017-01-22
5064
本次压测仅比较hello world,均为同一机器配置:单核i5-5287U CPU @ 2.90GHz
+1G内存,php-fpm和swoole应用服务器均启用了4个进程,php7开启 opcache, php5.5未开启,压测参考:
Shell
ab -n1000 -c100
1
ab-n1000-c100
php5.5:
Shell
[root@vagrant-centos64 nginx]# ab -n1000 -c100 http://192.168.33.10/index.php
Server Software: nginx/1.0.15
Server Hostname: 192.168.33.10
Server Port: 80
Document Path: /index.php
Document Length: 11 bytes
Concurrency Level: 100
Time taken for tests: 1.157 seconds
Complete requests: 1000
Failed requests: 0
Write errors: 0
Total transferred: 182000 bytes
HTML transferred: 11000 bytes
Requests per second: 864.41 [#/sec] (mean)
Time per request: 115.685 [ms] (mean)
Time per request: 1.157 [ms] (mean, across all concurrent requests)
Transfer rate: 153.64 [Kbytes/sec] received
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
[root@vagrant-centos64nginx]# ab -n1000 -c100 http://192.168.33.10/index.php
ServerSoftware:nginx/1.0.15
ServerHostname:192.168.33.10
ServerPort:80
DocumentPath:/index.php
DocumentLength:11bytes
ConcurrencyLevel:100
Timetakenfortests:1.157seconds
Completerequests:1000
Failedrequests:0
Writeerrors:0
Totaltransferred:182000bytes
HTMLtransferred:11000bytes
Requestspersecond:864.41[#/sec] (mean)
Timeperrequest:115.685[ms](mean)
Timeperrequest:1.157[ms](mean,acrossallconcurrentrequests)
Transferrate:153.64[Kbytes/sec]received
php7:
Shell
[root@bogon conf]# ab -n1000 -c100 http://192.168.33.11/index.php
Server Software: nginx/1.11.1
Server Hostname: 192.168.33.11
Server Port: 80
Document Path: /index.php
Document Length: 11 bytes
Concurrency Level: 100
Time taken for tests: 0.583 seconds
Complete requests: 1000
Failed requests: 0
Write errors: 0
Total transferred: 173000 bytes
HTML transferred: 11000 bytes
Requests per second: 1715.17 [#/sec] (mean)
Time per request: 58.303 [ms] (mean)
Time per request: 0.583 [ms] (mean, across all concurrent requests)
Transfer rate: 289.77 [Kbytes/sec] received
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
[root@bogonconf]# ab -n1000 -c100 http://192.168.33.11/index.php
ServerSoftware:nginx/1.11.1
ServerHostname:192.168.33.11
ServerPort:80
DocumentPath:/index.php
DocumentLength:11bytes
ConcurrencyLevel:100
Timetakenfortests:0.583seconds
Completerequests:1000
Failedrequests:0
Writeerrors:0
Totaltransferred:173000bytes
HTMLtransferred:11000bytes
Requestspersecond:1715.17[#/sec] (mean)
Timeperrequest:58.303[ms](mean)
Timeperrequest:0.583[ms](mean,acrossallconcurrentrequests)
Transferrate:289.77[Kbytes/sec]received
swoole:
Shell
[root@vagrant-centos64 nginx]# ab -n1000 -c100 http://192.168.33.10:9930/
Server Software: swoole-http-server
Server Hostname: 192.168.33.10
Server Port: 9930
Document Path: /
Document Length: 28 bytes
Concurrency Level: 100
Time taken for tests: 0.132 seconds
Complete requests: 1000
Failed requests: 0
Write errors: 0
Total transferred: 191000 bytes
HTML transferred: 28000 bytes
Requests per second: 7550.65 [#/sec] (mean)
Time per request: 13.244 [ms] (mean)
Time per request: 0.132 [ms] (mean, across all concurrent requests)
Transfer rate: 1408.37 [Kbytes/sec] received
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
[root@vagrant-centos64nginx]# ab -n1000 -c100 http://192.168.33.10:9930/
ServerSoftware:swoole-http-server
ServerHostname:192.168.33.10
ServerPort:9930
DocumentPath:/
DocumentLength:28bytes
ConcurrencyLevel:100
Timetakenfortests:0.132seconds
Completerequests:1000
Failedrequests:0
Writeerrors:0
Totaltransferred:191000bytes
HTMLtransferred:28000bytes
Requestspersecond:7550.65[#/sec] (mean)
Timeperrequest:13.244[ms](mean)
Timeperrequest:0.132[ms](mean,acrossallconcurrentrequests)
Transferrate:1408.37[Kbytes/sec]received
openresty:
Shell
[root@bogon conf]# ab -n1000 -c100 http://192.168.33.20:3302/lua
Server Software: openresty/1.9.15.1
Server Hostname: 192.168.33.20
Server Port: 3302
Document Path: /lua
Document Length: 135 bytes
Concurrency Level: 100
Time taken for tests: 0.094 seconds
Complete requests: 1000
Failed requests: 0
Write errors: 0
Total transferred: 299598 bytes
HTML transferred: 135270 bytes
Requests per second: 10629.36 [#/sec] (mean)
Time per request: 9.408 [ms] (mean)
Time per request: 0.094 [ms] (mean, across all concurrent requests)
Transfer rate: 3109.90 [Kbytes/sec] received
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
[root@bogonconf]# ab -n1000 -c100 http://192.168.33.20:3302/lua
ServerSoftware:openresty/1.9.15.1
ServerHostname:192.168.33.20
ServerPort:3302
DocumentPath:/lua
DocumentLength:135bytes
ConcurrencyLevel:100
Timetakenfortests:0.094seconds
Completerequests:1000
Failedrequests:0
Writeerrors:0
Totaltransferred:299598bytes
HTMLtransferred:135270bytes
Requestspersecond:10629.36[#/sec] (mean)
Timeperrequest:9.408[ms](mean)
Timeperrequest:0.094[ms](mean,acrossallconcurrentrequests)
Transferrate:3109.90[Kbytes/sec]received
结果分析:
1) php7.x比php5.x性能提升接近一倍,据第三方测评,php7.x比 HHVM还高,且更为显著的减少内存使用。这边仅启用了opcache,还没按照让PHP7达到最高性能的几个Tips来做到性能最大化。
2)Nginx和Swoole都是使用epoll/kqueue作为事件轮询机制的,且都是多线程Reactor的,但Swoole中的PHP代码需要编译为opcode来执行,每条opcode都是一次函数调用。语言的执行效率效率比C语言(Nginx)差。
浅谈web缓存技术 下一篇: 安装OpenResty(nginx+lua)开发环境并正常运行