Nginx设置问题
时间:2020-03-06 14:38:54 来源:igfitidea点击:
我知道这不是直接的编程问题,但是stackoverflow上的人们似乎能够回答任何问题。
我有一台运行Centos 5.2 64位的服务器。具有4GB内存的功能强大的双核2服务器。它主要提供静态文件,Flash和图片。当我使用lighttpd时,它可以轻松地以超过80 MB /秒的速度提供服务,但是当我使用nginx进行测试时,它的速度会下降到低于20 MB /秒。
我的设置非常简单,使用了默认的安装文件,并且我添加了以下内容
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; .... }
而且我认为nginx应该至少具有同样的功能,所以我一定不做任何事情。
解决方案
也许lighttpd正在使用某种缓存?这里有一篇很棒的文章,描述了如何使用nginx设置memcached以实现400%的性能提升。
memcached模块上的nginx文档在这里。
重新加载nginx(kiil -HUP)时,错误日志中将得到类似的内容
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
nginx编译使用哪种事件方法?
我们正在执行任何access_log'ing吗?考虑添加buffer = 32k,这将减少日志文件的写锁争用。
考虑减少工作人员的数量,这听起来很直观,但工作人员需要彼此同步以进行诸如accept()之类的系统调用。尝试减少工人数量,理想情况下,我建议1.
我们可以尝试在侦听套接字上显式设置读写套接字缓冲区,请参阅http://wiki.codemongers.com/NginxHttpCoreModule#listen
意见建议:
每个处理器使用1个工作者。
检查各种Nginx缓冲区设置