自动摘要
正在生成中……
配置
这是lua block的nginx/openresty
配置,openresty的版本1.19.3.1
:
worker_processes 1;
error_log logs/error.log;
events {
worker_connections 1024;
}
http{
server {
listen 6699;
location / {
default_type text/html;
content_by_lua_block {
ngx.say("<h1>HelloWorld</h1>");
}
}
}
}
这是php的部分nginx/openresty
配置, php版本是7.4.14
:
location ~ \.php$ {
try_files $uri =404;
include fastcgi.conf;
fastcgi_pass unix:/dev/shm/php7-fpm.sock;
}
...
PHP 脚本:hello.php
<?php
echo '<h1>Hello hkhost</h1>';
测试结果:
lua block
ab -w -c10 -n50000 http://hkhost:6699/
This is ApacheBench, Version 2.3 <$Revision: 1430300 $>
Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
Licensed to The Apache Software Foundation, http://www.apache.org/
Completed 5000 requests Completed 10000 requests Completed 15000 requests Completed 20000 requests Completed 25000 requests Completed 30000 requests Completed 35000 requests Completed 40000 requests Completed 45000 requests Completed 50000 requests Finished 50000 requests
Server Software: |
openresty/1.19.3.1 |
Server Hostname: |
hkhost |
Server Port: |
6699 |
Document Path: |
/ |
Document Length: |
20 bytes |
Concurrency Level: |
10 |
Time taken for tests: |
4.153 seconds |
Complete requests: |
50000 |
Failed requests: |
0 |
Total transferred: |
8400000 bytes |
HTML transferred: |
1000000 bytes |
Requests per second: |
12039.22 |
Transfer rate: |
2022589.43 kb/s received |
Connnection Times (ms) |
|
min |
avg |
max |
Connect: |
0 |
0 |
9 |
Processing: |
0 |
0 |
1 |
Total: |
0 |
0 |
10 |
=============
PHP脚本
ab -w -c10 -n50000 http://hkhost/hello.php
This is ApacheBench, Version 2.3 <$Revision: 1430300 $>
Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
Licensed to The Apache Software Foundation, http://www.apache.org/
Completed 5000 requests Completed 10000 requests Completed 15000 requests Completed 20000 requests Completed 25000 requests Completed 30000 requests Completed 35000 requests Completed 40000 requests Completed 45000 requests Completed 50000 requests Finished 50000 requests
Server Software: |
openresty/1.19.3.1 |
Server Hostname: |
hkhost |
Server Port: |
80 |
Document Path: |
/hello.php |
Document Length: |
21 bytes |
Concurrency Level: |
10 |
Time taken for tests: |
8.795 seconds |
Complete requests: |
50000 |
Failed requests: |
0 |
Total transferred: |
8200000 bytes |
HTML transferred: |
1050000 bytes |
Requests per second: |
5685.19 |
Transfer rate: |
932370.51 kb/s received |
Connnection Times (ms) |
|
min |
avg |
max |
Connect: |
0 |
0 |
1 |
Processing: |
1 |
1 |
9 |
Total: |
1 |
1 |
10 |
并发差距非常明显,每秒处理的请求数 12000
对 5600
,差距几乎达到2倍之大!
在openresty的官网对比页中,差距更高达4倍之多,当然他对比的是 5.2时代的 PHP,性能肯定更弱一些。
So on my laptop, for a single nginx worker, we've got 20k+ r/s. For comparison, HelloWorld servers using nginx + php-fpm 5.2.8 gives 4k r/s, Erlang R14B2 raw gen_tcp server gives 8k r/s, and [[node.js|http://nodejs.org/] v0.4.8 yields 5.7k r/s.