nginx设置问题

发布于 2024-07-06 04:40:01 字数 664 浏览 5 评论 0 原文

我知道这不是一个直接的编程问题,但是 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

2024-07-13 04:40:01

建议:
- 每个处理器使用 1 个工作人员。
- 检查各种 nginx 缓冲区设置

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

十秒萌定你 2024-07-13 04:40:01

也许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.

梨涡 2024-07-13 04:40:01

当您重新加载 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

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文