Unicorn + nginx - 上游过早关闭连接,同时从上游-504网关超时读取响应头

时间:2014-08-04 10:14:08

标签: ruby-on-rails nginx export-to-excel

当我尝试以excel格式下载记录时,我在浏览器中收到504 Gateway Timeout错误消息。在我对此进行调查时,查询执行时间过长会出现超时问题。因此,我已将unicorn worker超时值更改为240(即使我测试了1000+)和nginx proxy _ * _ timeout值从300更改为600.但是,再次失败。

我的实现是将用户详细信息导出为ex​​cel格式,但我只是在运行中计算所有内容。应该运行四个查询来导出单个记录。所以,我尝试8000条记录进行测试。

  

8000(记录)* 4(查询)= 32000次查询

如果您有任何其他想法在excel中导出长期查询结果,请告诉我。 THX。

PFB用于配置和错误详情。

unicorn.rb

worker_processes 4    
working_directory "/home/mrblack/myproject" # available in 0.94.0+    
listen "/home/mrblack/myproject/tmp/.unicorn.sock", :backlog => 64    
timeout 240

pid "/home/mrblack/myproject/tmp/unicorn.pid"

stderr_path "/home/mrblack/myproject/log/unicorn.stderr.log"
stdout_path "/home/mrblack/myproject/log/unicorn.stdout.log"

preload_app true
GC.respond_to?(:copy_on_write_friendly=) and
  GC.copy_on_write_friendly = true 

check_client_connection false

before_fork do |server, worker|    
  defined?(ActiveRecord::Base) and
    ActiveRecord::Base.connection.disconnect!
end

after_fork do |server, worker|

  defined?(ActiveRecord::Base) and
    ActiveRecord::Base.establish_connection
end

nginx的-conf的

user              ngnix;
worker_processes  1;    
error_log  /var/log/nginx/error.log;    
pid        /var/run/nginx.pid;    
timer_resolution  500ms;

worker_rlimit_nofile 10240;
events {
    use epoll;
    worker_connections 10240;
}

http {
    add_header X-Frame-Options SAMEORIGIN;
    include       /etc/nginx/mime.types;
    default_type  application/octet-stream;

    server_name_in_redirect off;
    server_tokens           off;

    log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
                      '$status $body_bytes_sent "$http_referer" '
                      '"$http_user_agent" "$http_x_forwarded_for"';

    access_log  /var/log/nginx/access.log  main;

    sendfile       on;
    tcp_nopush     on;

    keepalive_timeout  70s;
    tcp_nodelay        off;

    client_body_timeout   60s;
    client_header_timeout 60s;

    client_header_buffer_size 128;
    client_max_body_size      8m;

    open_file_cache           max=1000 inactive=20s;
    open_file_cache_valid     30s;
    open_file_cache_min_uses  2;
    open_file_cache_errors    on;

    proxy_cache_path  /var/cache/nginx/  levels=1:2   keys_zone=cache:80m inactive=1d  max_size=2500m;
    proxy_cache_key   "$scheme$request_method$host$request_uri";
    proxy_cache       cache;

#    proxy_temp_path   /var/lib/nginx/proxy;

    proxy_cache_valid  200 302  1d;
    proxy_cache_valid  301      1d;
    proxy_cache_valid  any      1m;

    #proxy_ignore_headers  "X-Accel-Redirect" "X-Accel-Expires" "Expires" "Cache-Control" "Set-Cookie";

    proxy_connect_timeout 600s;
    proxy_send_timeout    600s;
    proxy_read_timeout    600s;
    send_timeout          600s;

    proxy_buffer_size           32k;
    proxy_buffers               4 32k;
    proxy_busy_buffers_size     32k;
    proxy_temp_file_write_size  32k;

    gzip              on;
    gzip_http_version 1.0;
    gzip_disable      "MSIE [1-6]\.(?!.*SV1)";

    gzip_buffers    4 16k;
    gzip_comp_level 2;
    gzip_min_length 0;

    gzip_types    text/plain text/css application/x-javascript text/xml application/xml application/xml+rss text/javascript;
    gzip_proxied  expired no-cache no-store private auth;

    # Load config files from the /etc/nginx/conf.d directory
    # The default server is in conf.d/default.conf
    include /etc/nginx/conf.d/*.conf;

    upstream app_server {
      server unix: /home/mrblack/myproject/tmp/.unicorn.sock;
    }

    server {
        listen 80;
        add_header X-Frame-Options "DENY";
        client_max_body_size 4G;
        server_name localhost;
        keepalive_timeout 5;
        root /home/mrblack/myproject/public;
        try_files $uri/index.html $uri.html $uri @app;
        location @app {
            proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
            proxy_set_header Host $http_host;
            proxy_redirect off;
            proxy_pass http://app_server;
        }

        error_page 500 502 503 504 /500.html;
        location = /500.html {
            root /home/mrblack/myproject/public;
        }
    }

}

麒麟-stderr的

I, [2014-08-04T15:11:47.966332 #30951]  INFO -- : listening on addr=/home/mrblack/myproject/tmp/.unicorn.sock fd=10
I, [2014-08-04T15:11:47.992843 #30970]  INFO -- : worker=0 ready
I, [2014-08-04T15:11:47.998725 #30951]  INFO -- : master process ready
I, [2014-08-04T15:11:48.002149 #30973]  INFO -- : worker=1 ready
I, [2014-08-04T15:11:48.013117 #30976]  INFO -- : worker=2 ready
I, [2014-08-04T15:11:48.015180 #30979]  INFO -- : worker=3 ready
E, [2014-08-04T15:17:16.262433 #30951] ERROR -- : worker=0 PID:30970 timeout (61s > 60s), killing
E, [2014-08-04T15:17:16.363226 #30951] ERROR -- : reaped #<Process::Status: pid 30970 SIGKILL (signal 9)> worker=0
I, [2014-08-04T15:17:16.384091 #31476]  INFO -- : worker=0 ready

ngnix误差

  

上游过早关闭连接,同时从上游读取响应头,客户端:127.0.0.1,服务器:localhost,请求:&#34; GET /users/download_excel.xls?sEcho=1&iColumns=7&sColumns=c0% 2CC1%2C%2C%2C%2C%2C&安培; iDisplayStart = 0&安培; iDisplayLength = 10安培; mDataProp_0 = 0&安培; mDataProp_1 = 1&安培; mDataProp_2 = 2及mDataProp_3 = 3及mDataProp_4 = 4和; mDataProp_5 = 5&安培; mDataProp_6 = 6&安培; SSEARCH = &安培; bRegex =假安培; sSearch_0 =安培; bRegex_0 =假安培; bSearchable_0 =真安培; sSearch_1 =安培; bRegex_1 =假安培; bSearchable_1 =真安培; sSearch_2 =安培; bRegex_2 =假安培; bSearchable_2 =真安培; sSearch_3 =安培; bRegex_3 =假安培; bSearchable_3 =真安培; sSearch_4 =安培; bRegex_4 =假安培; bSearchable_4 =真安培; sSearch_5 =安培; bRegex_5 =假安培; bSearchable_5 =真安培; sSearch_6 =安培; bRegex_6 =假安培; bSearchable_6 =真安培; iSortCol_0 = 1&安培; sSortDir_0 = ASC&安培; iSortingCols = 1安培; bSortable_0 =真安培; bSortable_1 =真安培; bSortable_2 =真安培; bSortable_3 =假安培; bSortable_4 =假安培; bSortable _5 = true&amp; bSortable_6 = false HTTP / 1.1&#34 ;, upstream:&#34; /home/mrblack/myproject/tmp/.unicorn.sock:/users/download_excel.xls?sEcho = 1&amp; iColumns = 7&amp; sColumns = C0%2CC1%2C%2C%2C%2C%2C&安培; iDisplayStart = 0&安培; iDisplayLength = 10安培; mDataProp_0 = 0&安培; mDataProp_1 = 1&安培; mDataProp_2 = 2及mDataProp_3 = 3及mDataProp_4 = 4和; mDataProp_5 = 5&安培; mDataProp_6 = 6安培; SSEARCH =安培; bRegex =假安培; sSearch_0 =安培; bRegex_0 =假安培; bSearchable_0 =真安培; sSearch_1 =安培; bRegex_1 =假安培; bSearchable_1 =真安培; sSearch_2 =安培; bRegex_2 =假安培; bSearchable_2 =真安培; sSearch_3 =安培; bRegex_3 =假安培; bSearchable_3 =真安培; sSearch_4 =安培; bRegex_4 =假安培; bSearchable_4 =真安培; sSearch_5 =安培; bRegex_5 =假安培; bSearchable_5 =真安培; sSearch_6 =安培; bRegex_6 =假安培; bSearchable_6 =真安培; iSortCol_0 = 1&安培; sSortDir_0 = asc&amp; iSortingCols = 1&amp; bSortable_0 = true&amp; bSortable_1 = true&amp; bSortable_2 = true&amp; bSortable_3 = false&amp; bSortable_4 = false&amp; bSortable_5 = true&amp; bSortable_6 = false&#34;,host: &#34; localhost&#34;,推荐人:&#34; localhost / users / members&#34;

0 个答案:

没有答案