nginx设置问题
我知道这不是一个直接的编程问题,但是 stackoverflow 上的人似乎能够回答任何问题。
我有一台运行 Centos 5.2 64 位的服务器。 非常强大的双核 2 服务器,具有 4GB 内存。 它主要提供静态文件、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 应该至少同样强大,所以我一定没有做任何事情。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
建议:
- 每个处理器使用 1 个工作人员。
- 检查各种 nginx 缓冲区设置
Suggestions:
- Use 1 worker per processor.
- Check the various nginx buffer settings
也许lighttpd正在使用某种缓存? 这里有一篇很棒的文章描述了如何使用 nginx 设置 memcached,以实现据称 400% 的性能提升。
memcached 模块上的 nginx 文档位于此处。
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.
当您重新加载 nginx (kiil -HUP) 时,您会在错误日志中看到类似的内容
您的 nginx 编译为使用什么事件方法?
你在做任何 access_log'ing 吗? 考虑添加buffer=32k,这将减少日志文件写锁的争用。
考虑减少工作人员的数量,这听起来违反直觉,但是工作人员需要彼此同步以进行像accept()这样的系统调用。 尝试减少工作人员的数量,理想情况下我建议 1。
您可以尝试在侦听套接字上显式设置读写套接字缓冲区,请参阅 http://wiki.codemongers.com/NginxHttpCoreModule#listen
When you reload your nginx (kiil -HUP) you'll get something like this in your error logs
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