8

I know this is not directly a programming question, but people on stackoverflow seems to be able to answer any question.

I have a server running Centos 5.2 64 bit. Pretty powerful dual core 2 server with 4GB memory. It mostly serves static files, flash and pictures. When I use lighttpd it easily serves over 80 MB/sec, but when I test with nginx it drops down to less than 20 MB/sec.

My setup is pretty straight forward, uses the default setup file, and I have added the following

user  lighttpd;
worker_processes  8;
worker_rlimit_nofile 206011;
#worker_rlimit_nofile 110240;

error_log   /var/log/nginx/error.log;
#error_log  /var/log/nginx/error.log  notice;
#error_log  /var/log/nginx/error.log  info;

pid        /var/run/nginx.pid;


events {
    worker_connections  4096;
}

http {
....

keepalive_timeout  2;
....
}

And I thought nginx was supposed to be at least as powerful, so I must be not doing something.

Trausti Thor
  • 3,722
  • 31
  • 41
  • What does your lighttpd config look like? Could be interesting to compare. Also, since lighttpd is single threaded but you are on dual core - do you start two lighttpds or do you handle 80mb/s with a single instance? – Till Sep 24 '08 at 14:42
  • Can you outline your testing method? That might help. – Jauder Ho Jul 06 '09 at 04:48
  • This is an extremely active web server that just does static files. The lighttpd and nginx are installed with yum on centos 5 box. Pretty straight forward from there. All is monitored with munin and active sessions on the load balancer. The box with nginx does 50% of what lighty does – Trausti Thor Jul 06 '09 at 23:33

3 Answers3

7

When you reload your nginx (kiil -HUP) you'll get something like this in your error logs

2008/10/01 03:57:26 [notice] 4563#0: signal 1 (SIGHUP) received, reconfiguring
2008/10/01 03:57:26 [notice] 4563#0: reconfiguring
2008/10/01 03:57:26 [notice] 4563#0: using the "epoll" event method
2008/10/01 03:57:26 [notice] 4563#0: start worker processes
2008/10/01 03:57:26 [notice] 4563#0: start worker process 3870

What event method is your nginx compiled to use?

Are you doing any access_log'ing ? Consider adding buffer=32k, which will reduce the contention on the write lock for the log file.

Consider reducing the number of workers, it sounds counter intuitive, but the workers need to synchronize with each other for sys calls like accept(). Try reducing the number of workers, ideally I would suggest 1.

You might try explicitly setting the read and write socket buffers on the listening socket, see http://wiki.codemongers.com/NginxHttpCoreModule#listen

Dave Cheney
  • 5,575
  • 2
  • 18
  • 24
3

Perhaps lighttpd is using some kind of caching? There's a great article here that describes how to set up memcached with nginx for a reported 400% performance boost.

The nginx doc on the memcached module is here.

Ross
  • 1,415
  • 10
  • 10
1

Suggestions: - Use 1 worker per processor. - Check the various nginx buffer settings

Seun Osewa
  • 4,965
  • 3
  • 29
  • 32