在使用Ubuntu 13.04上完全库存的软件包比较Apache 2.2和Nginx 1.2.6的负载testing中,我发现Nginx PHP请求的性能比Apache PHP的要低。 如果可能的话,我正在寻找指导,让我们的Nginx性能超过Apache的性能 。
Apache的设置相当标准,但是Nginx的设置是相当的定制的; 它们被列在基准结果之下 。
我使用名为Siege v3.0.2的基准testing工具( http://www.joedog.org/siege-home/ )来为单个并发用户(c1),10个并发用户(c10)和100个并发用户( C100); 结果如下:
Apache结果:
Apache和osx-lion上的两个版本的PHP
catalina.out中有很多(Permission denied)
如何在WAMP服务器(v2.5)中启用https(localhost)url?
Homestead + Symfony 2.7安装
Date & Time,Trans,Elap Time,Data Trans,Resp Time,Trans Rate,Throughput,Concurrent,OKAY,Failed **** c1 Apache Static **** 2013-08-01 00:54:12,5982,59.23,338,0.01,101.00,5.71,1.00,0 **** c1 Apache PHP **** 2013-08-01 00:55:12,549,59.98,88,0.11,9.15,1.47,0 **** c1 Apache Combined **** 2013-08-01 00:56:12,1609,139,0.04,26.83,2.32,0 **** c10 Apache Static **** 2013-08-01 00:57:12,35983,59.97,2039,0.02,600.02,34.00,9.99,0 **** c10 Apache PHP **** 2013-08-01 00:58:12,3769,610,0.16,62.84,10.17,0 **** c10 Apache Combined **** 2013-08-01 00:59:12,10928,947,0.05,182.19,15.79,0 **** c100 Apache Static **** 2013-08-01 01:00:12,44581,2523,0.13,743.39,42.07,98.63,0 **** c100 Apache PHP **** 2013-08-01 01:01:12,4427,721,1.32,73.81,12.02,97.34,1 **** c100 Apache Combined **** 2013-08-01 01:02:12,12735,1125,0.47,212.32,18.76,99.68,0
Nginx的结果:
Date & Time,Failed **** c1 Nginx Static **** 2013-08-01 02:36:13,9040,59.10,274,152.96,4.64,0 **** c1 Nginx PHP **** 2013-08-01 02:37:13,581,18,0.10,9.69,0.30,0 **** c1 Nginx Combined **** 2013-08-01 02:38:13,1786,59.59,55,0.03,29.97,0.92,0 **** c10 Nginx Static **** 2013-08-01 02:39:13,44557,1353,742.86,22.56,0 **** c10 Nginx PHP **** 2013-08-01 02:40:13,3766,120,62.79,2.00,9.98,0 **** c10 Nginx Combined **** 2013-08-01 02:41:13,10962,339,182.76,5.65,0 **** c100 Nginx Static **** 2013-08-01 02:42:13,54463,1642,908.02,27.38,99.70,0 **** c100 Nginx PHP **** 2013-08-01 02:43:13,3649,117,1.62,60.84,1.95,98.70,0 **** c100 Nginx Combined **** 2013-08-01 02:44:13,10802,334,0.55,180.09,5.57,0
我所关心的数据来自c100“PHP”和“Combined”结果。 阿帕奇是相当快一点,我想知道如何在网上所有的基准testing显示相反。
这两个服务器是:
运行在四核至强处理器上
8GB内存
连接到同一networking上的MongoDB v2.2数据库
Apache (设置非常接近股票):
在CentOS 5上运行
Apache 2.2
mod_PHP的
Nginx的:
Ubuntu 13.04
Nginx 1.2.6
Nginx.conf
pid /run/Nginx.pid; user www-data; worker_processes 4; events { worker_connections 1024; } http { # APACHE BACKWARDS COMPATIBILITY ENVIRONMENT VARIABLES map $request_uri $my_script_url { default $request_uri; ~^(?<script_filename>.+.(PHP))(.*)?$ $script_filename; #/test.PHP or /test.PHP?hello=world ~^(?<script_filename>.*)(?.*)$ $script_filename; #/tos?hello=world ~^(?<script_filename>.*)(?.*)?$ $script_filename; #/tos or /tos/hello/world or /tos/hello/world?omg=what } # BASE SETTINGS charset utf-8; default_type application/octet-stream; include /etc/Nginx/mime.types; server_tokens off; # CLIENT CACHING SETTINGS add_header Last-Modified ""; expires 7d; # CONNECTION SETTINGS client_body_timeout 15s; client_header_timeout 30s; client_max_body_size 8m; keepalive_requests 10000; keepalive_timeout 30s; reset_timedout_connection on; resolver_timeout 5s; send_timeout 15s; tcp_nopush on; # FASTCGI SETTINGS # fastcgi_cache_path /var/cache/Nginx levels=1:2 keys_zone=microcache:10m max_size=1000m inactive=60m; # FILE CACHING AND PERFORMANCE SETTINGS open_file_cache max=10000 inactive=20s; open_file_cache_errors off; open_file_cache_min_uses 2; open_file_cache_valid 30s; sendfile on; # GZIP SETTINGS gzip on; gzip_comp_level 5; gzip_min_length 1024; gzip_proxied any; gzip_types text/css text/plain text/javascript application/javascript application/json application/x-javascript application/xml application/xml+RSS application/xhtml+xml application/x-font-ttf application/x-font-opentype application/vnd.ms-fontobject image/svg+xml image/x-icon application/RSS+xml application/atom_xml; gzip_vary on; # LOGGING SETTINGS access_log /var/log/Nginx/access.log combined buffer=16k; error_log /var/log/Nginx/error.log crit; open_log_file_cache max=100 inactive=1m min_uses=1 valid=2m; # SSL SETTINGS # ssl_ciphers !aNULL:!eNULL:FIPS@STRENGTH; # ssl_prefer_server_ciphers on; # ssl_protocols TLSv1 TLSv1.1 TLSv1.2; # ssl_session_cache shared:SSL:10m; # ssl_session_timeout 3m; # OTHER GLOBAL CONfigURATION FILES include /etc/Nginx/conf.d/*.conf; # VIRTUAL HOST CONfigS include /etc/Nginx/sites-enabled/*; }
虚拟主机configuration
server { # BASE SETTINGS listen 80; root /var/www/tbi/example/htdocs; # server_name local.example.com; server_name www.example.com; # LOG SETTINGS access_log /var/log/Nginx/www.example.com.access.log combined buffer=64k; error_log /var/log/Nginx/www.example.com.error.log crit; # LOCATIONS location / { index index.PHP index.html; try_files $uri @extensionless-PHP; } location ~ .(ttf|otf|eot|woff)$ { add_header Access-Control-Allow-Origin *; } # location /Nginx_status { # See a brief synopsis of real-time,instantaneous performance # stub_status on; # } location ~ .PHP$ { expires off; # FASTCGI SETTINGS fastcgi_index index.PHP; fastcgi_pass unix:/var/run/PHP5-fpm.sock; fastcgi_split_path_info ^(.+.PHP)(/.+)$; include fastcgi_params; # FASTCGI CACHE SETTINGS # fastcgi_cache microcache; # fastcgi_cache_bypass $http_pragma; # fastcgi_cache_key $scheme$host$request_uri$request_method; # fastcgi_cache_methods GET HEAD; # fastcgi_cache_use_stale updating error timeout invalid_header http_500; # fastcgi_cache_valid any 1m; # fastcgi_ignore_headers "Cache-Control" "Expires" "Set-Cookie"; # TBI ENVIRONMENT VARIABLES fastcgi_param TBI_CONfig /var/www/tbi/configs/; fastcgi_param TBI_DOMAIN example.com; # fastcgi_param TBI_ENV local; fastcgi_param TBI_ENV www; fastcgi_param TBI_RELEASETIME 0; # APACHE BACKWARDS COMPATIBILITY ENVIRONMENT VARIABLES fastcgi_param SCRIPT_URI $scheme://$http_host$my_script_url; fastcgi_param SCRIPT_URL $my_script_url; } location @extensionless-PHP { if (-f $request_filename.PHP) { rewrite ^/(.*)$ /$1.PHP last; } rewrite ^/(.*)$ /index.PHP?$1 last; } }
任何有关使Nginx更快的build议将不胜感激。 如果可能,我想避免内核和TCP / IP调优。
为什么这个PHP apache_request_headers不能在IIS 7上工作
用imagegrabscreen和Wamp捕获图像
如何设置web根目录并隐藏app.PHP和app_dev.PHP在本地主机使用xampp和apache?
HTTP_HOST服务器variables是否始终定义?
Apache和Nginx的80端口
Apache和Nginx之间的PHP性能应该是相当类似的,因为PHP比使用的服务器要高得多。
在你的情况下,当并发性= 1或并发性= 10时,性能看起来相同,只有在并发性为100时,在Nginx / PHP-FPM上才会变慢。
尽管您可能会假设,但并行运行更多的PHP-FPM进程并不会为许多并发查询带来更快的性能。 在某个点之后,PHP不会从并行运行中受益。 在某一点之后,由于额外的上下文切换,I / O访问的更多随机争用,更高的内存使用等,并行中的更多进程可能会降低整体吞吐量。
在我的测试中,PHP-FPM过程的最佳位置是6到10(我使用8)。 即使在使用数百个并发连接进行测试时,这也可以获得最高的性能。 之后添加更多的PHP-FPM流程开始减慢速度。 你的里程可能会有所不同,但100不太可能是任何服务器上的甜蜜点。
请注意,您的PHP-FPM进程数不必等于或大于您支持的并发连接数。 为了更好地解释 – 拥有8个PHP-FPM进程并不意味着你仅限于8个并发连接。 只要您的PHP-FPM中的listen.backlog足够高,您的服务器(Nginx)仍然会维持数百个并发连接,但是PHP-FPM将在内部一次处理它们,而不是一次处理它们。 这意味着,每个单独的查询将花费更少的时间实际上由PHP执行,因为它争夺更少的其他进程。 这些连接仍将保持开放,并且与数百个并发用户进行的测试仍将看到所有请求的快速和成功的服务。
请注意,我还发现另一种方法来加快我的Nginx设置上的PHP,这是增加fastcgi_buffers的数量/大小。 我目前设置为fastcgi_buffers 32 16k; 。
您已经在Nginx中启用gzip快速压缩 – 非常昂贵的操作,所以你期望什么? 更糟糕的是,你已经配置了第5个压缩级别,这使得它更慢,更慢。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。