网站地图    收藏   

主页 > 后端 > PHP语言 >

PHP vs Nginx-Lua vs html vs c-cgi_自学php网

来源:自学PHP网    时间:2014-12-04 21:50 作者: 阅读:

[导读] 测试环境: nginx 1.4.2 运行在 xxx.xxx.xxx.xxx(内网IP) Intel(R) Xeon(R) CPU E5620 @ 2.40GHz [root@yw-0-0 ~]# php -v PHP 5.4.16 (cli) (built: Jun 7 2013 14:32:19) Copyright (c) 1997-2013 The PHP Group Zend Engine v2.4.0, Copyrigh...

测试环境:
nginx 1.4.2 运行在 xxx.xxx.xxx.xxx(内网IP)
Intel(R) Xeon(R) CPU E5620 @ 2.40GHz


[root@yw-0-0 ~]# php -v
PHP 5.4.16 (cli) (built: Jun 7 2013 14:32:19)
Copyright (c) 1997-2013 The PHP Group
Zend Engine v2.4.0, Copyright (c) 1998-2013 Zend Technologies
with XCache v3.0.2, Copyright (c) 2005-2013, by mOo
with XCache Optimizer v3.0.2, Copyright (c) 2005-2013, by mOo
with XCache Cacher v3.0.2, Copyright (c) 2005-2013, by mOo
with XCache Coverager v3.0.2, Copyright (c) 2005-2013, by mOo

php-fpm配置:
pm = dynamic
pm.max_children = 200
pm.start_servers = 100
pm.min_spare_servers = 100
pm.max_spare_servers = 150
 

nginx配置文件:


#user nobody;
worker_processes 4;
error_log logs/error.log;
events {
use epoll;
worker_connections 5120;
}
http {
include mime.types;
default_type application/octet-stream;
sendfile on;
#tcp_nopush on;
keepalive_timeout 65;
server {
listen 80;
server_name xxx.xxx.xxx.xxx;
root /var/www/html;
location / {
index index.php index.html index.htm;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
location ~ \.php$ {
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME /var/www/html$fastcgi_script_name;
include fastcgi.conf;
}
location /hello {
default_type 'text/plain';
content_by_lua 'ngx.say("hello")';
}
location ~ \.cgi$ {
fastcgi_pass 127.0.0.1:9001;
fastcgi_index index.cgi;
fastcgi_param SCRIPT_FILENAME fcgi$fastcgi_script_name;
include fastcgi.conf;
}
}
}
 

c语言的fcgi源码:


#include <fcgi_stdio.h>

int main() {
while( FCGI_Accept() >= 0 ) {
printf( "Status: 200 OK\r\n" );
printf( "Content-Type: text/html\r\n\r\n" );
printf( "world\n" );
}
return 0;
}
gcc -lfcgi -Wall world.c -o world.cgi
spawn-fcgi -p 9001 -F 100 -u nobody -f /var/www/world.cgi
 

ab运行在内网另外一台服务器,不使用keepalive。


[root@yw-0-0 zhaokunyao]# ab -n 1000000 -c 100 http://xxx.xxx.xxx.xxx/test.html
Document Path: /test.html
Document Length: 9 bytes

Concurrency Level: 100
Time taken for tests: 53.977 seconds
Complete requests: 1000000
Failed requests: 0
Write errors: 0
Total transferred: 237002844 bytes
HTML transferred: 9000108 bytes
Requests per second: 18526.28 [#/sec] (mean)
Time per request: 5.398 [ms] (mean)
Time per request: 0.054 [ms] (mean, across all concurrent requests)
Transfer rate: 4287.87 [Kbytes/sec] received

[root@yw-0-0 zhaokunyao]# ab -n 1000000 -c 100 http://xxx.xxx.xxx.xxx/hello
Document Path: /hello
Document Length: 6 bytes

Concurrency Level: 100
Time taken for tests: 51.523 seconds
Complete requests: 1000000
Failed requests: 0
Write errors: 0
Total transferred: 147000000 bytes
HTML transferred: 6000000 bytes
Requests per second: 19408.95 [#/sec] (mean)
Time per request: 5.152 [ms] (mean)
Time per request: 0.052 [ms] (mean, across all concurrent requests)
Transfer rate: 2786.25 [Kbytes/sec] received

[root@yw-0-0 zhaokunyao]# ab -n 1000000 -c 100 http://xxx.xxx.xxx.xxx/test.php
Document Path: /test.php
Document Length: 2 bytes

Concurrency Level: 100
Time taken for tests: 71.286 seconds
Complete requests: 1000000
Failed requests: 0
Write errors: 0
Total transferred: 149000000 bytes
HTML transferred: 2000000 bytes
Requests per second: 14028.08 [#/sec] (mean)
Time per request: 7.129 [ms] (mean)
Time per request: 0.071 [ms] (mean, across all concurrent requests)
Transfer rate: 2041.19 [Kbytes/sec] received



[root@yw-0-0 zhaokunyao]# ab -n 1000000 -c 100 http://xxx.xxx.xxx.xxx/aaaa.cgi
Document Path: /aaaa.cgi
Document Length: 6 bytes

Concurrency Level: 100
Time taken for tests: 54.390 seconds
Complete requests: 1000000
Failed requests: 0
Write errors: 0
Total transferred: 127000000 bytes
HTML transferred: 6000000 bytes
Requests per second: 18385.81 [#/sec] (mean)
Time per request: 5.439 [ms] (mean)
Time per request: 0.054 [ms] (mean, across all concurrent requests)
Transfer rate: 2280.27 [Kbytes/sec] received
 

结论:

nginx-lua是相当的快……性能与比静态html还要牛X。

另外,并发100太小了, 完全没有发挥出来html和lua的性能,不过,上面的数据还是有一定的参考价值的。
 

自学PHP网专注网站建设学习,PHP程序学习,平面设计学习,以及操作系统学习

京ICP备14009008号-1@版权所有www.zixuephp.com

网站声明:本站所有视频,教程都由网友上传,站长收集和分享给大家学习使用,如由牵扯版权问题请联系站长邮箱904561283@qq.com

添加评论