Testing of the computing performance and stability of Web Server combinations, nginx + php vs Apache + php

Source: Internet
Author: User
Tags builtin zts

Testing of the computing performance and stability of Web Server combinations, nginx + php vs Apache + php

In this test, which combination of nginx + php and apache + php has better computing performance and stability?
Operating System: Centos6.4 x64
Hardware environment:
 
Server IP Address
Hardware configuration
Role
192.168.1.2
4 Core 8 GB
Benchmark Test Server
192.168.1.3
Omitted
Benchmark Test Client
Experiment ideas: This test is intended to be used in combination with the same version, such as (nginx1.4.4 + php5.5.7) vs (httpd2.4.2 + php5.7) and (nginx + php7) vs (apache + php7 ), there are two types of test programs: algorithm program and read/write program connected to the database.
First install the environment
Here we only talk about the simple nginx configuration for installing and configuring Apache (omitted)
I. Compile Apache
Apache Official Website: http://httpd.apache.org/
Other httpd2.4.x series installation configurations are similar here.
1. Install the dependency package
Tar-zxvf apr-1.5.0.tar.gz
Cp-rf apr-1.5.0 httpd-2.4.2/srclib/apr
 
Tar-zxvf apr-util-1.5.3.tar.gz
Cp-rf apr-util-1.5.3 httpd-2.4.2/srclib/apr-util
2. Configure compilation options and install
./Configure -- prefix =/alidata/server/httpd \
-- With-mpm = prefork \
-- Enable-so \
-- Enable-rewrite \
-- Enable-mod-shared = all \
-- Enable-nonportable-atomics = yes \
-- Disable-dav \
-- Enable-deflate \
-- Enable-cache \
-- Enable-disk-cache \
-- Enable-mem-cache \
-- Enable-file-cache \
-- Enable-ssl \
-- With-defined ded-apr \
-- Enable-modules = all \
-- Enable-mpm-shared = all
 
Make-j 4
Make install
# Provide the Startup Script
Cp support/apachectl/etc/init. d/httpd
Chmod u + x/etc/init. d/httpd
Detailed description of some compilation parameters:
Define the default mpm Mode
-- With-mpm = prefork
Install all mpm modules
-- Enable-mpm-shared = all
3. Modify the main configuration file: httpd. conf
ServerRoot "/alidata/server/httpd"
Listen 80
LoadModule authn_file_module modules/mod_authn_file.so
LoadModule authn_core_module modules/mod_authn_core.so
LoadModule authz_host_module modules/mod_authz_host.so
LoadModule authz_groupfile_module modules/mod_authz_groupfile.so
LoadModule authz_user_module modules/mod_authz_user.so
LoadModule authz_core_module modules/mod_authz_core.so
LoadModule access_compat_module modules/mod_access_compat.so
LoadModule auth_basic_module modules/mod_auth_basic.so
LoadModule reqtimeout_module modules/mod_reqtimeout.so
LoadModule filter_module modules/mod_filter.so
LoadModule mime_module modules/mod_mime.so
LoadModule log_config_module modules/mod_log_config.so
LoadModule env_module modules/mod_env.so
LoadModule headers_module modules/mod_headers.so
LoadModule setenvif_module modules/mod_setenvif.so
LoadModule version_module modules/mod_version.so
LoadModule unixd_module modules/mod_unixd.so
LoadModule status_module modules/mod_status.so
LoadModule autoindex_module modules/mod_autoindex.so
LoadModule dir_module modules/mod_dir.so
LoadModule alias_module modules/mod_alias.so
User daemon
Group daemon
/IfModule>
ServerAdmin [email protected]
AllowOverride none
Require all denied
/Directory>
DocumentRoot "/alidata/server/httpd/htdocs"
"/Alidata/server/httpd/htdocs">
Options Indexes FollowSymLinks
AllowOverride None
Require all granted
/Directory>
DirectoryIndex index.html
/IfModule>
". Ht *">
Require all denied
/Files>
ErrorLog "logs/error_log"
LogLevel warn
LogFormat "% h % l % u % t \" % r \ "%> s % B \" % {Referer} I \ "\" % {User-Agent} I \ "" combined
LogFormat "% h % l % u % t \" % r \ "%> s % B" common

LogFormat "% h % l % u % t \" % r \ "%> s % B \" % {Referer} I \ "\" % {User-Agent} I \ "% I % O" combinedio
/IfModule>
CustomLog "logs/access_log" common
/IfModule>
ScriptAlias/cgi-bin/"/alidata/server/httpd/cgi-bin /"
/IfModule>
/IfModule>
"/Alidata/server/httpd/cgi-bin">
AllowOverride None
Options None
Require all granted
/Directory>
TypesConfig conf/mime. types
AddType application/x-compress. Z
AddType application/x-gzip. gz. tgz
/IfModule>
Include conf/extra/proxy-html.conf
/IfModule>
SSLRandomSeed startup builtin
SSLRandomSeed connect builtin
/IfModule>
4. Configure the VM
Include/alidata/server/httpd/conf/vhosts/*. conf
". Php">
Order allow, deny
Deny from all
/Files>
/DirectoryMatch>
 
DocumentRoot/alidata/www/phpwind

ServerName localhost
ServerAlias localhost
"/Alidata/www/phpwind">
Options Indexes FollowSymLinks
Require all granted
/Directory>

RewriteEngine On
RewriteRule ^ (. *)-htm-(. *) $. php?
RewriteRule ^ (. *)/simple/([a-z0-9 \ _] + \. html) $/simple/index. php?
/IfModule>
ErrorLog "/alidata/log/httpd/phpwind-error.log"
CustomLog "/alidata/log/httpd/phpwind. log" common
/VirtualHost>
Apache installation and configuration complete
2. Compile PHP5.5.7
./Configure -- prefix =/alidata/server/php-Apache \
-- Enable-opcache \
-- With-config-file-path =/alidata/server/php-Apache/etc \
-- With-apxs2 =/alidata/server/httpd/bin/apxs \
-- With-mysql = mysqlnd \
-- With-mysqli = mysqlnd \
-- With-pdo-mysql = mysqlnd \
-- Enable-static \
-- Enable-maintainer-zts \
-- Enable-zend-multibyte \
-- Enable-inline-optimization \
-- Enable-sockets \
-- Enable-wddx \
-- Enable-zip \
-- Enable-calendar \
-- Enable-bcmath \
-- Enable-soap \
-- With-zlib \
-- With-iconv \
-- With-gd \
-- With-xmlrpc \
-- Enable-mbstring \
-- Without-sqlite \
-- With-curl \
-- Enable-ftp \
-- With-mcrypt \
-- With-freetype-dir =/usr/local/freetype.2.1.10 \
-- With-jpeg-dir =/usr/local/2.16.6 \
-- With-png-dir =/usr/local/libpng.1.2.50 \
Disable-ipv6 \
-- Disable-debug \
-- With-openssl \
-- Disable-maintainer-zts \
-- Disable-safe-mode \
-- Disable-fileinfo
If the compiling mode is work or event, add -- enable-maintainer-zts when compiling PHP, because these two modes work based on threads.
Make ZEND_EXTRA_LIBS = '-liconv'-j 4
Make install
Provide php. ini files
Cp./php-5.5.7/php. ini-production/alidata/server/php-Apache/etc/php. ini
Php installation and configuration complete
Prepare a stress testing tool
Here, we use three stress testing tools: AB, WebBench, and Siege.
 
Siege detailed use: http://www.ha97.com/4663.html
Detailed use of other pressure testing tools: http://www.cnblogs.com/EthanCai/archive/2014/05/11/3721656.html
The following is the script code for installing the relevant stress testing tool:
#! /Bin/bash
 
# Install siege
Wget http://download.joedog.org/siege/siege-3.1.4.tar.gz
Tar-xzvf siege-3.1.4.tar.gz
Cd siege-3.1.4
./Configure
Make & make install
 
# Install WebBench
Wget http://www.ha97.com/code/webbench-1.5.tar.gz
Tar zxvf webbench-1.5.tar.gz
Cd webbench-1.5
Make
Make install
The installation of AB is special, because the AB installed with the rpm package has concurrency restrictions by default, so re-compile AB here.
Find the support/AB. c file in the Apache source code directory and modify the file to line 1 as follows:
/* Catch legitimate fatal apr_socket_recv errors */
Else if (status! = APR_SUCCESS ){
Err_recv ++;
If (recverrok ){
Bad ++;
Close_connection (c );
If (verbosity> = 1 ){
Char buf [120];
Fprintf (stderr, "% s: % s (% d) \ n", "apr_socket_recv", apr_strerror (status, buf, sizeof buf), status );
}
Return;
} Else {
// Apr_err ("apr_socket_recv", status); // start from this
Bad ++;
Close_connection (c );
Return; // here
}
}
After modification, compile as usual.
Iii. Start stress testing
Program environment: Apache2.4.2 + php5.5.7 vs Nginx1.4.4 + php5.5.7
AB Test Database read/write programs
./AB-c 200-n 40000 10.117.64.176/mysql. php
Apache2.4.2 + php5.5.7
The following are the test results of the number of requests processed per second:
1867.58
2185.96
2034.68
1825.54
1842.52
Average: 1951
Average number of failed requests: 0

 


Nginx1.4.4 + php5.5.7
The following are the test results of the number of requests processed per second:
2065.52
2083.04
2026.32
2063.60
1995.74
Average: 2046
Average number of failed requests: 0

./AB-c 500-n 100000 10.117.64.176/mysql. php
Apache2.4.2 + php5.5.7
The following are the test results of the number of requests processed per second:
2104.55
2071.86
2146.81
1984.53
1985.45
Average: 2058
Average number of failed requests: 0

Nginx1.4.4 + php5.5.7
The following are the test results of the number of requests processed per second:
1513.51
1913.67
1719.01
1619.77
2018.31
Average: 1756
Average number of failed requests: 25

./AB-c 1000-n 200000 10.117.64.176/mysql. php
Apache2.4.2 + php5.5.7
The following are the test results of the number of requests processed per second:
1871.87
1609.17
1986.52
1851.46
1877.55
Average: 1839
Average number of failed requests: 849

Nginx1.4.4 + php5.5.7
The following are the test results of the number of requests processed per second:
1816.49
1689.54
1677.48
2033.39
1790.44
Average: 1801
Average number of failed requests: 213

AB Testing Algorithm Program
./AB-c 100-n 20000.117.64.176/arr. php
Apache2.4.2 + php5.5.7
Average: 13.83
Average number of failed requests: 0
Nginx1.4.4 + php5.5.7
Average Value: 14
Average number of failed requests: 30
WebBench Test Database read/write programs
Apache2.4.2 + php5.5.7

Nginx1.4.4 + php5.5.7

WebBench Test Algorithm Program
Apache2.4.2 + php5.5.7

Nginx1.4.4 + php5.5.7

Siege hybrid link test
Apache2.4.2 + php5.5.7
Transactions: 21192 hits
Availability: 95.36%
Elapsed time: 503.23 secs
Data transferred: 473.91 MB
Response time: 2.62 secs
Transaction rate: 42.11 trans/sec
Throughput: 0.94 MB/sec
Concurrency: 110.21
Successful transactions: 21192
Failed transactions: 1031
Longest transaction: 16.24
Shortest transaction: 0.00
Nginx1.4.4 + php5.5.7
Transactions: 18922 hits
Availability: 94.85%
Elapsed time: 453.87 secs
Data transferred: 102.05 MB
Response time: 3.05 secs
Transaction rate: 41.69 trans/sec
Throughput: 0.22 MB/sec
Concurrency: 127.28
Successful transactions: 18922
Failed transactions: 1028
Longest transaction: 18.40

 

Shortest transaction: 0.00
Iv. Apache Event Working Model
The prefork and mpm methods are insufficient in extremely busy server applications. Although the HTTP Keepalive method can reduce the number of TCP connections and network load, the Keepalive must be bound to the service process or thread,
This causes a busy server to consume all threads. Event MPM is a new model to solve this problem. It separates service processes from connections. The processing speed on the server is very fast, and there is a very high click
The number of available threads is the critical resource limit. The Event MPM method is the most effective. A busy server working in the Worker MPM mode can withstand tens of thousands of visits per second (for example, during peak hours of large news service sites), and Event MPM can be used to handle higher loads. It is worth noting that Event MPM cannot work with secure HTTP (HTTPS) access.
The event and work share the same characteristics. They both process requests through threads. A parent process creates multiple child processes, and a child process creates multiple threads.
Stress Testing Apache2.4.2 Event + php5.5.7
./AB-c 500-n 100000 10.117.64.176/mysql. php
The following are the test results of the number of requests processed per second:
2381.76
2413.55
2318.26
2388.66
2461.83
Average: 2392
Average number of failed requests: 237

./AB-c 1000-n 200000 10.117.64.176/mysql. php
The following are the test results of the number of requests processed per second:
1678.28
1931.22
1546.89
1791.62
1720.07
Average: 1733
Average number of failed requests: 776


V. New Features of PHP 7
PHP7 fixes a large number of bugs and adds features and syntactic sugar. These changes involve familiar and unfamiliar core functions and extensions such as core packages, GD libraries, PDO, ZIP, and ZLIB.
PHP7 removed obsolete functions. For example, mysql _ series functions are discarded in PHP5.5 and deleted in PHP7.
Performance improvement:
PHP 5.6 faster
Significantly reduces memory usage
Abstract syntax tree
Consistent 64-bit support
Improved exception hierarchy
Many converted to abnormal fatal errors
Secure random number generator
Delete old and unsupported SAPIs and extensions
Null merge operator (?)
Return and scalar type declaration
Anonymous class
Zero-cost assertions
Compile and install PHP 7
. /Configure -- prefix =/usr/local/php7 -- enable-fpm -- with-zlib -- enable-mbstring -- with-openssl -- with-mysql -- with-mysqli -- with-mysql- sock -- with-gd -- enable-gd-native-ttf -- enable-pdo -- with-pdo-mysql -- with-gettext -- with-curl -- with-pdo-mysql -- enable- sockets -- enable-bcmath -- enable-xml -- with-bz2 -- enable-zip
 
Make & make install
./AB-c 500-n 100000 10.117.64.176: 8081/mysql. php
Stress Testing Apache2.4.2 + php7
The following are the test results of the number of requests processed per second:
2028.29
2336.16
2132.38
1777.49
1151.25
Average: 1885
Average number of failed requests: 37

Nginx1.4.4 + php7 database read performance test
The following are the test results of the number of requests processed per second:
2492.27
2497.95
2646.73
1937.65
1635.76
Average: 2242
Average number of failed requests: 19

./AB-c 1000-n 200000 10.117.64.176: 8081/mysql. php
Apache2.4.2 + php7 database read performance test
The following are the test results of the number of requests processed per second:
2170.86
1584.38
1614.59
1640.35
1641.81
Average: 1730
Average number of failed requests: 723

Stress Testing Nginx1.4.4 + php7
The following are the test results of the number of requests processed per second:
2346.19
1868.92
2134.17
2272.42
1847.33
Average: 2093
Average number of failed requests: 191

Apache2.4.2 + php7 Algorithm Program Performance Test
The following are the test results of the number of requests processed per second:
45.53
45.52
45.54
45.52
45.52
Average Value: 45
Average number of failed requests: 0

Nginx1.4.4 + php7 Algorithm Program Performance Test
The following are the test results of the number of requests processed per second:
53.99
53.98
53.95
53.96
53.97
Average Value: 53
Average number of failed requests: 0

From this we can see that, in fact, Apache + PHP and Nginx + PHP are not very different in performance. You can use them flexibly according to your own business. However, PHP7 is about three times higher than PHP5 in terms of computing performance.
 

 

 

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.