Requests per second slower when using nginx for load balancing

Posted by Ed Eliot on Server Fault See other posts from Server Fault or by Ed Eliot
Published on 2011-02-14T00:05:35Z Indexed on 2011/02/19 23:26 UTC
Read the original article Hit count: 285

I've set up nginx as a load balancer that reverse proxies requests to 2 Apache servers. I've benchmarked the setup with ab and am getting approx 35 requests per second with requests distributed between the 2 backend servers (not using ip_hash). What is confusing me is that if I query either of the backend servers directly via ab I get around 50 requests per second.

I've experimented with a number of different values in ab the most common being 1000 requests with 100 concurrent connections.

Any idea why traffic distributed across 2 servers would result in fewer requests per second than hitting either directly?

Additional info:

I've experimented with worker_processes values of between 1 and 8, worker_connections between 1024 and 8092 and have also tried keepalive 0 and 65.

My main conf currently looks like this:

user www-data;
worker_processes 1;

error_log  /var/log/nginx/error.log;
pid        /var/run/nginx.pid;

worker_rlimit_nofile 8192;

events {
    worker_connections  2048;
    use epoll;
}

http {
    include       /etc/nginx/mime.types;

    sendfile        on;

    keepalive_timeout  0;
    tcp_nodelay        on;

    gzip  on;
    gzip_disable "MSIE [1-6]\.(?!.*SV1)";

    include /etc/nginx/conf.d/*.conf;
    include /etc/nginx/sites-enabled/*;
}

I've got one virtual host (in sites available) that redirects everything under / to 2 backends across a local network.

© Server Fault or respective owner

Related posts about apache

Related posts about nginx