Apache 2.4 faster Than Nginx?

 Apache 2.4 Faster Than Nginx?

Here are the benchmark results.

9K

It turned out that it’s a false claim. Apache 2.4 is actually much slower than Nginx!

The benchmark was run on the same Linux box (localhost), to avoid possible network affection. I used ab (ApacheBench) as the benchmark client. Apache listened on port 80 and Nginx listened on port 81. In the whole benchmark process, Apache was stressed first then Nginx. There was a 60 seconds sleep between each test, which was taken by five times per concurrency (from 100 to 1000). I gave up the tests with higher concurrencies because Apache was so unstable with concurrency greater than 1000 that there would be some failures. While Nginx was very stable without problems.

I’ve tried my best to fully “unleash the power of Apache”:
1) configured with apr-1.4.6 and apr-util-1.4.1, using the fastest atomic API:

$ ./configure --prefix=/home/shudu/apache --with-included-apr \
--enable-nonportable-atomics=yes

2) least modules were enabled:

$ apache/bin/httpd -M
Loaded Modules:
 core_module (static)
 so_module (static)
 http_module (static)
 mpm_event_module (static)
 authz_core_module (shared)
 filter_module (shared)
 mime_module (shared)
 unixd_module (shared)

3) MaxRequestWorkers was raised to 800 and ServerLimit to 32.

Nginx was just compiled with its default options:

$ ./configure --prefix=/home/shudu/bench/nginx

The common features of Apache and Nginx:
1) Sendfile on.
2) KeepAlive off.
3) AccessLog off.

The configuration files of Apache and Nginx are as followings:

# Apache 2.4.1
ServerRoot "/home/shudu//bench/apache"

KeepAlive Off

ServerLimit 32
MaxRequestWorkers 800

Listen 80
ServerName localhost

LoadModule authz_core_module modules/mod_authz_core.so
LoadModule filter_module modules/mod_filter.so
LoadModule mime_module modules/mod_mime.so
LoadModule unixd_module modules/mod_unixd.so

<IfModule unixd_module>
User shudu
Group shudu
</IfModule>

ServerAdmin you@example.com

<Directory />
    AllowOverride none
    Require all denied
</Directory>

DocumentRoot "/home/shudu/bench/apache/htdocs"
<Directory "/home/shudu/bench/apache/htdocs">
    Options Indexes FollowSymLinks
    AllowOverride None
    Require all granted
</Directory>

ErrorLog "logs/error_log"
LogLevel warn

<IfModule mime_module>
    TypesConfig conf/mime.types
    AddType application/x-compress .Z
    AddType application/x-gzip .gz .tgz
</IfModule>

EnableSendfile on
# Nginx-1.0.12
user  shudu users;
worker_processes  2;

events {
    worker_connections  10240;
    accept_mutex_delay  100ms;
}

http {
    include             mime.types;
    default_type        application/octet-stream;

    sendfile            on;
    tcp_nopush          on;

    keepalive_timeout   0;

    access_log off;

    server {
        listen          81;
        server_name     localhost;

        location / {
            root        html;
            index       index.html index.htm;
        }
    }
}

My Ubuntu-10.04 box:

$ uname -a
Linux shudu-desktop 2.6.32-38-generic #83-Ubuntu SMP Wed Jan 4 11:13:04 UTC 2012 i686 GNU/Linux
$ grep "model\ name" /proc/cpuinfo 
model name	: Intel(R) Core(TM)2 Duo CPU     E8400  @ 3.00GHz
model name	: Intel(R) Core(TM)2 Duo CPU     E8400  @ 3.00GHz
$ free -m
             total       used       free     shared    buffers     cached
Mem:          1995       1130        864          0         80        341
-/+ buffers/cache:        708       1286
Swap:         2491          0       2491
$ cat /etc/security/limits.conf
root soft nofile 65535
root hard nofile 65535
shudu soft nofile 65535
shudu hard nofile 65535

 

 

This entry was posted in Uncategorized. Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s