【问题标题】:nginx configuration that could serve 1000 requests/sec可以服务 1000 个请求/秒的 nginx 配置
【发布时间】:2011-11-09 21:08:38
【问题描述】:

我们的生产服务器有 Ubuntu 9.x, 内存 8GB,HDD 250Gb 使用 nginx 作为网络服务器。 我们目前在高峰时段遇到性能问题(1000 个请求/秒) 我希望服务器可以提供 1000 个请求/秒,有人可以告诉我我应该对 nginx 配置进行哪些更改。谢谢

这里是 nginx 配置文件

#user  nobody;

worker_processes  8;

events {
    worker_connections  8024;
}


http {
    passenger_root /opt/ruby-enterprise-1.8.7-2009.10/lib/ruby/gems/1.8/gems/passenger-3.0.9;
    passenger_ruby /opt/ruby-enterprise-1.8.7-2009.10/bin/ruby;
    passenger_pool_idle_time 0;
    passenger_max_pool_size 15;

    include       mime.types;
    default_type  application/octet-stream;

    sendfile        on;

    ## General options
    #ignore_invalid_headers on;
    keepalive_requests 2000;
    #recursive_error_pages on;
    #server_name_in_redirect off;
    #server_tokens off;

    ## TCP options
    tcp_nodelay on;
    tcp_nopush on;

    ## Timeouts
    client_body_timeout 10;
    client_header_timeout 10;
    keepalive_timeout  65;
    #send_timeout 10;
    #expires 24h;

    gzip  on;

server {
    listen       80;
    server_name  resumecompanion.com;
    passenger_enabled on;
    rails_env production;
    root /var/www/resumecompanion.com/production/current/public;
    #access_log  off;
    #error_log off;
            ## Redirect from www to non-www
            if ($host = 'www.resumecompanion.com' ) {
              rewrite  ^/(.*)$  http://resumecompanion.com/$1  permanent;
            }


            # deny access to .htaccess files, if Apache's document root
            # concurs with nginx's one
            #
            location ~ /\.ht {
                deny  all;
            }
        }


# HTTPS server
#
server {
    listen       443;
    server_name  resumecompanion.com;
    passenger_enabled on;
    rails_env production;

    ssl                  on;
    ssl_certificate      /opt/nginx/ssl/resumecompanion.com.crt;
    ssl_certificate_key  /opt/nginx/ssl/start_resumecompanion_com.key;

    ssl_session_timeout  5m;

#    ssl_protocols  SSLv2 SSLv3 TLSv1;
#    ssl_ciphers  HIGH:!aNULL:!MD5;
#    ssl_prefer_server_ciphers   on;

    root   /var/www/resumecompanion.com/production/current/public;

}

}

【问题讨论】:

  • 对于带有 8 个 worker_processes 的 8024 worker_connections,您还需要修改内核参数:ulimit -n 64192 (8*8024)。最好将进程数设置为与cpu核心数相等。
  • @petermolnar 也可以使用 Nginx 中的 worker_rlimit_nofile 来完成。

标签: ruby-on-rails ruby nginx webserver


【解决方案1】:

如果不分析系统很难说...您必须首先找到大部分时间花费在请求中的位置。它不是常见的 ngingx 或 apache 是问题的原因。

考虑到您使用 ruby​​-on-rails 标签发布了此内容,我想您在 nginx 后面有一个 rails 应用程序......更有可能是 rails 应用程序导致问题。我要检查的第一件事是数据库查询。检查日志中是否有慢查询,并尝试找到一种方法让它们更快……索引总是一个很好的起点……

如果您找不到任何东西,请尝试使用新的工具来找到您的性能问题所在......

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2023-03-18
    • 1970-01-01
    • 2014-07-24
    • 2023-04-02
    • 1970-01-01
    • 1970-01-01
    • 2012-06-23
    • 2016-06-08
    相关资源
    最近更新 更多