nginx setup question

一笑奈何 提交于 2020-01-03 08:57:11

问题


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.


回答1:


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




回答2:


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.




回答3:


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



来源:https://stackoverflow.com/questions/125957/nginx-setup-question

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!