Preparations for Internet entrepreneurship-web server: Apache, nginx, Lighttpd, PHP module, FastCGI

Source: Internet
Author: User
Tags unix domain socket redmine

Test environment:

VPs of vr.org

CPU: 2-core shared

Memory: MB independent

OS: Ubuntu 12.04 lts x64

Uname-

 
U1 @ www :~ $ CAT/etc/LSB-release distrib_id = ubuntudistrib_release = 12.04distrib _ codename = precisedistrib_description = "ubuntu 12.04 lts" U1 @ www :~ $ Uname-alinux www.shaixuan.org 3.4.0-cloud #1 SMP Thu May 24 04:54:53 EDT 2012 x86_64 x86_64 x86_64 GNU/linuxu1 @ www :~ $ Toptop-23:57:39 up, 2 users, load average: 0.04, 0.03, 0.16 tasks: 55 total, 1 running, 54 sleeping, 0 stopped, 0 zombiecpu (s ): 0.7% us, 0.4% Sy, 0.0% Ni, 97.6% ID, 0.1% wa, 0.0% hi, 0.1% Si, 1.1% STMEM: 506764 k total, 125264 K used, 381500 K free, 7736 K buffersswap: 499708 k total, 0 K used, 499708 K free, 70096 K cached

Software Versions: Apache httpd 2.4.3, nginx 1.2.3, Lighttpd 1.4.31, and PHP 5.4.6

 

Conclusion:

Static Server:

Concurrency: nginx (17000)> Lighttpd (14000)> Apache (5000)

Note: etag cannot be disabled when gzip compression is enabled in Lighttpd ...... It is not recommended. Reference: high-performance website construction Guide

 

Dynamic Server:

Concurrency: nginx + PHP-FPM (1500)> Lighttpd + spawn-fcgi (1000)> Apache + PhP module (400)

Note: When the Web server and FastCGI are on the same machine, Unix domain socket is recommended, which is a little better than TCP socket.

 

Although Apache httpd 2.4 uses epoll like nginx, its performance is much lower than nginx.

The Server OS must use the Linux 2.6 kernel and later, because epoll is supported.

We recommend that the server use Ubuntu server lts x64, because the engineer's PC uses many Ubuntu x64 drivers (easy to install), so that the compilation and deployment are consistent.

Ubuntu, centos, and other Linux distributions are no different for servers. The kernel is the same, just pick a good one.

 

Refer to the Web server of Internet companies:

163. com StaticNginx
T.qq.com Static squid, dynamic nginx
Taobao.com StaticTengine,DynamicTengine (derived from nginx)
Xiaomi Forum StaticTengine,Dynamic tengine
Baidu StaticLighttpd,DynamicLighttpd (with etag)

 

 

 

Test process:

Apache httpd 2.4.3

Compilation parameters:

Apache

. /Configure -- prefix =/usr/local/apache2 -- With-Apr =/usr/local/APR -- With-Apr-util =/usr/local/APR-util/-- -PCRE =/home/u1/pcre-8.30 -- enable-so -- enable-Rewrite -- enable-Deflate -- With-module = metadata: expires

MPM: Default event

Httpd-V

  root @ www:/usr/local/apache2/bin #. /httpd-vserver version: Apache/2.4.3 (UNIX) server built: Aug 26 2012 10: 27: 04server's module magic number: 20120211: 6 server loaded: Apr 1.4.6, APR-UTIL 1.4.1compiled using: Apr 1.4.6, APR-UTIL 1.4.1architecture: 64-bitserver MPM: Event threaded: Yes (fixed thread count) forked: Yes (variable process count) server compiled .... -D apr_has_sendfile-D apr_has_mmap-D apr_have_ipv6 (IPv4-mapped addresses enabled) -d your-D apr_has_other_child-d your-D dynamic_module_limit = 256-D httpd_root = "/usr/local/apache2"-D suexec_bin = "/usr/local/apache2 /bin/suexec "-D default_pidlog =" logs/httpd. PID "-D default_scoreboard =" logs/apache_runtime_status "-D default_errorlog =" logs/error_log "-D ap_types_config_file =" CONF/mime. types "-D server_config_file =" CONF/httpd. conf " 

Default concurrency 400, maxrequestworkers is the previous maxclients, see: http://httpd.apache.org/docs/2.4/mod/mpm_common.html#MaxRequestWorkers

 
<Ifmodule mpm_event_module> startservers 3 minsparethreads 75 maxsparethreads 250 threadsperchild 25 maxrequestworkers 400 maxconnectionsperchild 0 </ifmodule>

Change the concurrency to 40000, and an error is prompted. Add serverlimit:

 
U1 @ www :~ $ Sudo VI/usr/local/apache2/CONF/extra/httpd-mpm.conf U1 @ www :~ $ Sudo VI/usr/local/apache2/CONF/httpd. confu1 @ www :~ $ Sudo/etc/init. d/apache2 restartah00515: Warning: maxrequestworkers of 40000 wowould require 1600 servers and wocould exceed serverlimit of 16, decreasing to 400. to increase, please see the serverlimit directive.

 

Nginx 1.2.3:

Compilation parameters:

View code

 
./Configure -- prefix =/usr/local/nginx -- With-PCRE =/usr/local/PCRE

 

Lighttpd 1.4.31:

The default concurrency is 1024. The maximum value of server. Max-FDS can be changed to 65535, and the maximum value of server. Max-connections can be changed to 32767:

193 #194 # As Lighttpd is a single-threaded server, its main resource limit is195 # The number of file descriptors, which is set to 1024 by default (on196 # most systems ). 197 #198 # If you are running a high-traffic site you might want to increase this199 # limit by setting server. max-fds.200 #201 # changing this setting requires root permissions on startup. see202 # server. username/server. groupname.203 #204 # By default Lighttpd wocould not change the operation system default.205 # But setting it to 2048 is a better default for busy servers.206 #207 server. max-FDS = 2048218 219 #220 # fine tuning for the request handling221 #222 # Max-connections = max-FDS/2 (maybe/3) 223 # means the other file handles are used for FastCGI/files224 #225 server. max-connections = 1024

 

 

1. Static server test

That is, Performance Comparison of Apache, nginx, and Lighttpd.

The same Server Configuration:

Enable gzip and disable etag

TestProgramRun the following command on the same server as the Web server:

 
AB-C1000-N50000HTTP://Localhost/index.htmlSiege-C1000-R20HTTP://Localhost/index.html

 

Apache: HTML file 13 K, Gzip compressed to 4.9 K

Header:

Apache

Test results:

Concurrency Httpd sub-process count Device512 mMemory usage CPU usage Iowait
0 3 19% 0 0
1000 10 30% 38% 0
3000 14 60% 38% 0
5000 10-30 65%-99% 20%-40% 0-30
8000 100 99% 3%-50% 20-100

 

 

Nginx: HTML file 13.2 K, Gzip compressed to 5.34 K

Header:

Nginx

Request URL: http://shaixuan.org/index.htmlRequest method: getstatus code: 200 okrequest headersview sourceaccept: text/html, application/XHTML + XML, application/XML; q = 0.9 ,*/*; Q = 0.8accept-charset: UTF-8, *; q = 0.5accept-encoding: gzip, deflate, sdchaccept-language: ZH-CN, ZH; q = 0.8, en-us; Q = 0.6, en; q = 0.4cache-control: No-cacheconnection: Keep-alivehost: shaixuan. oruplagma: No-cacheuser-AGENT: Mozilla/5.0 (Windows NT 6.1; wow64) applewebkit/537.8 (khtml, like gecko) Chrome/23.0.1251.2 Safari/537.8 response headersview sourceconnection: keep-alivecontent-encoding: gzipcontent-type: text/htmldate: Mon, 03 Sep 2012 13:19:23 gmtlast-modified: Mon, 03 Sep 2012 12:33:45 gmtserver: nginx/1.2.3transfer-encoding: chunked

Test results:

Concurrency Memory usage of MB CPU usage Iowait
0 29% 0 0
1000 35% 40% 0
3000 46% 43% 0
5000 55% 42% 0-1
8000 65% 45% 0
15000 88% 45% 0
17000 97% 47% 0

 

Lighttpd: HTML file 13 K, Gzip compressed to 4.96 K

Header:

Lighttpd

Request URL: http://shaixuan.org/Request method: getstatus code: 200 okrequest headersview sourceaccept: text/html, application/XHTML + XML, application/XML; q = 0.9 ,*/*; Q = 0.8accept-charset: UTF-8, *; q = 0.5accept-encoding: gzip, deflate, sdchaccept-language: ZH-CN, ZH; q = 0.8, en-us; Q = 0.6, en; q = 0.4cache-control: Max-age = 0 connection: Keep-alivehost: shaixuan. oruplagma: No-cacheuser-AGENT: Mozilla/5.0 (Windows NT 6.1; wow64) applewebkit/537.8 (khtml, like gecko) Chrome/23.0.1251.2 Safari/537.8 response headersview sourceaccept-ranges: bytescontent-encoding: gzipcontent-length: 4819content-type: text/htmldate: Tue, 04 Sep 2012 12:51:42 gmtetag: "1028714895" last-modified: Tue, 04 Sep 2012 12:29:10 gmtserver: lighttpd/1.4.31vary: Accept-Encoding

Test results:

Concurrency Memory usage of MB CPU usage Iowait
0 29% 0 0
1000     0
3000 46% 41% 0-6
5000 60% 40% 0-1
8000 75% 45% 0
12000 81% 35% 0
14000 87% 36% 0
16000 99% 40% 0

 

 

2. Dynamic Server Testing

Compare Apache + PhP module, nginx + PHP-FPM, nginx + PHP-CGI, Lighttpd + spawn-fcgi.

Test command:

Siege-C1200-R20HTTP://Localhost/phpinfo. php/Usr/local/apache2/bin/AB-C100-T50HTTP://Localhost/phpinfo. php

 

 

PHP version 5.4.6, testCodePhpinfo ();

 

Apache + PhP module: php file 63.57 K, Gzip compressed to 11.21 K

Test results:

Concurrency Memory usage of MB CPU usage Iowait
0 29% 0 0
100 68% 8% 0
200 72% 10% 0
400 95% 10% 0
600 99% 15% 1-15

 

Nginx + PHP-FPM (multiple PHP-FPM sub-processes): the PHP file is 57.41 kb, And the GZIP file is compressed to 10.84 kb.

Phpinfo Display Server API: FPM/FastCGI

FastCGI socket: TCP socket

PHP compilation parameters:

Php-FPM

. /Configure -- prefix =/usr/local/PHP-FPM -- enable-FPM -- With-FPM-user = www-data -- With-FPM-group = www-data --- curl -- With-mcrypt -- enable-mbstring -- enable-PDO -- With-PDO-mysql = mysqlnd -- With-mysqli = mysqlnd -- enable-zip

Test results:

Concurrency Memory usage of MB CPU usage Iowait Siege success rate
0 33% 0 0  
100 37% 8% 0 100%
200        
400 45% 10% 0 99.96%
800 55% 14 PHP-FPM, 5.9 MB each 12% 0 96.31%
1000 60% 10% 0 90.77%
1200 69% Linux File restrictions, test errors 30%    

 

Nginx + PHP-FPM (multiple PHP-FPM sub-processes): the PHP file is 54.57 kb, And the GZIP file is compressed to 9.16 kb.

Phpinfo Display Server API: FPM/FastCGI

FastCGI socket: Unix domain socket

Test results:

Concurrency Memory usage of MB CPU usage Iowait Siege success rate
0 32% 0 0  
100 35% 7% 0 100%
200 40% 12% 0 100%
400 43% 14% 0 100%
800 55% 14% 0 96.70%
1000 60% 21 PHP-FPM, 5.9 MB each 14% 0 92.02%
1200 50% Linux File restrictions, test errors 50% 0 49%

 

Nginx + a PHP-CGI: php file 64.65 K, Gzip compressed to 11.89 K

Sudo/usr/local/PHP-FPM/bin/PHP-CGI-B 9000-Q

Php-CGI can be resident (long-live) Listening to a port, so it is FastCGI, but because there is no process manager, only one process can be started, low concurrency endurance.

Phpinfo Display Server API: FPM/FastCGI

Test results:

When the concurrency is 100, PHP-CGI crashes and exits after 5 seconds.

 

Spawn-fcgi Process Manager (multiple PHP-CGI sub-processes) of Lighttpd + Lighttpd: php file 58.68 K, Gzip compressed to 9.83 K

Phpinfo Display Server API: CGI/FastCGI

FastCGI socket: Unix domain socket

FastCGI. conf configuration of Lighttpd:

FastCGI. Server

22 FastCGI. server = (". PHP "=> 23 (" PHP-local "=> 24 (25" socket "=> socket_dir +"/php-fastcgi-1.socket ", 26 "bin-path" => "/usr/local/PHP-FPM/bin/PHP-cgi", 27 "Max-procs" => 2, 28 "Broken-scriptfilename" => "enable", 29 "bin-Environment" => (30 "php_fcgi_children" => "16 ", 31 & quot; php_fcgi_max_requests & quot; = & quot; 500 & quot;, 32), 33) 34 ),

Test results:

 

Concurrency Memory usage of MB CPU usage Iowait Siege success rate
0 53% 34 PHP-CGI processes, each 3 m 0 0  
100 65%Each 5.3 MB 10% 0  
200 65%Each 5.7 MB 10% 0 100%
400 72%Each 5.7 MB 11% 0 100%
800 84%Each 5.7 MB 10% 0 99.49%
1000 90%Each 5.7 MB 12% 0 97.41%
1200 Linux File restrictions, test errors      

 

References:

Http://www.cnblogs.com/killkill/archive/2010/04/14/1711810.html

Http://httpd.apache.org/docs/2.4/mod/mpm_common.html#MaxRequestWorkers

Http://www.php.net/manual/zh/install.fpm.php

Http://www.niutian365.com/blog/article.asp? Id = 263

Http://redmine.lighttpd.net/projects/1/wiki/Docs_ModCompress

Http://redmine.lighttpd.net/projects/lighttpd/wiki/Docs_PerformanceFastCGI

Http://php.net/manual/zh/install.unix.lighttpd-14.php

Http://www.361way.com/mpm/1052.html

Http://blog.chinaunix.net/uid-13939710-id-2861331.html

Http://www.yylib.com/blog? P = 70

Http://kb.cnblogs.com/page/95605/

Http://www.dbanotes.net/web/lighttpd_spawn-fcgi.html

Http://www.mike.org.cn/articles/what-is-cgi-fastcgi-php-fpm-spawn-fcgi/

Http://www.php.net/manual/zh/install.unix.apache2.php

Http://ferreousbox.iteye.com/blog/196212

Http://nigelzeng.iteye.com/blog/1197339

Http://blog.csdn.net/tujiyue/article/details/7027134

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.