no performance improvement on nginx reverse-proxy

yung innobak at gmail.com
Wed Oct 13 08:33:17 MSD 2010


Hello,

This day I did a simpe test with nginx's reverse-proxy.
The environment is on a vmware virtual host.

OS: slackware Linux, kernel 2.6.24.5-smp
CPU: Intel(R) Celeron(R) CPU          723  @ 1.20GHz
MEM: 350M


The application environment:

nginx version: nginx/0.8.52
apache version: Apache/2.2.15 (Unix)
mysql version: 5.1.51


The performance/capability arguments for nginx/apache are:

[nginx]

worker_processes  8;
events {
    worker_connections  1024;
}

[apache]

<IfModule mpm_prefork_module>
    StartServers          5
    MinSpareServers       5
    MaxSpareServers      10
    MaxClients          150
    MaxRequestsPerChild   0
</IfModule>


Apache run with two vhosts, one is listening on 8080 port, another is
listening on 8081 port.

The vhost config shown as below:

<VirtualHost *:8080>
    DocumentRoot "/usr/local/apache2.2/vhost/vh1"
    ScriptAlias /cgi/ "/usr/local/apache2.2/vhost/vh1/cgi/"
</VirtualHost>

<VirtualHost *:8081>
    DocumentRoot "/usr/local/apache2.2/vhost/vh2"
    ScriptAlias /cgi/ "/usr/local/apache2.2/vhost/vh2/cgi/"
</VirtualHost>


There are two cgi scripts on the cgi dirs above.
one is /usr/local/apache2.2/vhost/vh1/cgi/test.cgi
another is /usr/local/apache2.2/vhost/vh2/cgi/test.cgi

Their content is do the same.
It's a simple perl script which fetches a record by random from a
table which has 150,000 records totally.
[the script content is pasted on the last of this message.]


Nginx is setup for the reverse-proxy to the two vhosts of apache.
The config piece shown as:

    upstream MyTestServ {
      server 127.0.0.1:8081;
      server 127.0.0.1:8080;
    }

    server {
        server_name my.test.com;
        listen 80;

        location / {
          proxy_set_header Host  $host;
          proxy_set_header X-Real-IP $remote_addr;
          proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
          proxy_pass http://MyTestServ;
        }
    }



After all  that done, I tested it with http_load (a tool from
http://www.acme.com/software/http_load/).

./http_load -parallel 15 -seconds 30 urls

This test nginx for rever-proxy, the url is like:
http://192.168.0.77/cgi/test.cgi


./http_load -parallel 15 -seconds 30 urls1

This test apache directly, the url is like:
http://192.168.0.77:8080/cgi/test.cgi


After testing for some times (have been changing the arugments for
http_load), I found nginx with reverse-proxy is not better than the
realserver.
Even the result is worse for accessing nginx than access apache directly.


The result with nginx reverse-proxy:

191 fetches, 15 max parallel, 9782 bytes, in 30 seconds
51.2147 mean bytes/connection
6.36667 fetches/sec, 326.067 bytes/sec
msecs/connect: 1.23155 mean, 3.663 max, 0.648 min
msecs/first-response: 2250.49 mean, 5026.69 max, 576.448 min
90 bad byte counts
HTTP response codes:
  code 200 -- 191


The result with NO reverse-proxy:

196 fetches, 15 max parallel, 10030 bytes, in 30.0005 seconds
51.1735 mean bytes/connection
6.53322 fetches/sec, 334.327 bytes/sec
msecs/connect: 1.35084 mean, 6.877 max, 0.797 min
msecs/first-response: 2103.1 mean, 4348.94 max, 535.809 min
84 bad byte counts
HTTP response codes:
  code 200 -- 196


So how do you think about it?
Suggestions are welcome. Thanks.


__END__

This is the CGI script for testing:

#!/usr/bin/perl
use strict;
use CGI;
use DBI;

my $q=CGI->new;
print $q->header("text/plain");

my $dsn = "DBI:mysql:database=pyh;host=127.0.0.1;port=3306";
my $dbh = DBI->connect($dsn, 'root', '');

my $id = 10026 + int(rand(150000));

my $str = "select * from myt2 where id = $id";
my $sth = $dbh->prepare($str);
$sth->execute;

my @array = $sth->fetchrow_array;
$sth->finish;
$dbh->disconnect;

print "@array\n";



More information about the nginx mailing list