Nginx Serving Static Files Way Too Slowly

nginx

I asked this on Stack Overflow, but maybe it's more of a question for the SF crew.

So there have been lots of articles like this one recently, extolling the virtues of Django Static Generator when used in combination with a light front-end Web server. It makes a whole lot of sense to me.

However, I get nothing like the results that other people are reporting — thousands of requests per second — and I don't know why that is.

I'm getting ready to launch a redesign of my newspaper's Web site. I've got it using Static Generator on a test server right now. And when I run Apache Bench on a particular static page, I get pretty miserable results:

ab -c 10 -n 1000 http://journal.streamlister.com/news/

Concurrency Level:      10
Time taken for tests:   53.011 seconds
Complete requests:      1000
Failed requests:        0
Write errors:           0
Total transferred:      21281212 bytes
HTML transferred:       21067360 bytes
Requests per second:    18.86 [#/sec] (mean)
Time per request:       530.107 [ms] (mean)
Time per request:       53.011 [ms] (mean, across all concurrent requests)
Transfer rate:          392.04 [Kbytes/sec] received

I'm watching top on the server while the siege is on, and I can see that it's not hitting Apache or the database server at all. So it is, in fact, serving the cached page. Nginx is running, but it never gets above 2% memory usage. CPU remains about 95 percent idle.

What am I doing wrong? Could I have misconfigured nginx somehow? My main config file is pasted below; the include specific to this site is pretty much a carbon copy of the sample config on the Static Generator home page. I'm running Ubuntu 9.10 on a Slicehost 256k slice.

user not_my_real_username;
worker_processes  4;
error_log  /var/log/nginx/error.log;
pid        /var/run/nginx.pid;
events {
    worker_connections  8192;
}
http {
    include       /etc/nginx/mime.types;
    default_type  application/octet-stream;
    access_log  /var/log/nginx/access.log;
    sendfile        on;
    #tcp_nopush     on;
    keepalive_timeout  0;
    #keepalive_timeout  65;
    tcp_nodelay        on;
    gzip  on;
    include /etc/nginx/conf.d/*.conf;
    include /etc/nginx/sites-enabled/*;
}

Best Answer

You can increase nginx performance, just adding next options to config:

   http {

      open_file_cache max=1000 inactive=300s;
      open_file_cache_valid 360s;
      open_file_cache_min_uses 2;
      open_file_cache_errors off;

    }