notblakeshelton
notblakeshelton

Reputation: 364

Nginx upstream timeout error while running ruby on rails query

In a ruby on rails application, I have a table with ~10,000 entries which can be searched using different parameters. On the dev box, this works fine, but on the production box, I get an error.

2018/10/04 15:46:39 [error] 3418#3418: *6 upstream timed out (110: Connection timed out) while reading response header from upstream, client: 192.168.1.5, server: my.site.com, request: "POST /quotes/quoteTable_js HTTP/1.1", upstream: "http://unix:///path/to/app/shared/tmp/sockets/puma.awi_staging.sock/items/itemTable_js", host: "192.168.1.25", referrer: "http://192.168.1.25/items"

I didn't set up the server so I'm a bit out of depth here. I've looked at the following questions

However, none of those worked or perhaps I didn't implement them correctly.

my nginx.conf file

user nginx;
worker_processes auto;
pid /run/nginx.pid;

events {
    worker_connections 768;
    # multi_accept on;
}

http {

    ##
    # Basic Settings
    ##

    sendfile on;
    tcp_nopush on;
    tcp_nodelay on;
    keepalive_timeout 65;
    types_hash_max_size 2048;
    # server_tokens off;

    # server_names_hash_bucket_size 64;
    # server_name_in_redirect off;

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

    ##
    # SSL Settings
    ##

    ssl_protocols TLSv1 TLSv1.1 TLSv1.2; # Dropping SSLv3, ref: POODLE
    ssl_prefer_server_ciphers on;

    ##
    # Logging Settings
    ##

    access_log /var/log/nginx/access.log;
    error_log /var/log/nginx/error.log;

    ##
    # Gzip Settings
    ##

    gzip on;
    gzip_disable "msie6";

    # gzip_vary on;
    # gzip_proxied any;
    # gzip_comp_level 6;
    # gzip_buffers 16 8k;
    # gzip_http_version 1.1;
    # gzip_types text/plain text/css application/json application/javascript text/xml application/xml application/xml+rss text/javascript;

    ##
    # Virtual Host Configs
    ##

    include /etc/nginx/conf.d/*.conf;
    include /etc/nginx/sites-enabled/*;
}

EDIT

I get the "We're sorry, but something went wrong" rails message after ~7 seconds. I've tried increasing keepalive_timeout, but nothing changed.

Upvotes: 0

Views: 2568

Answers (1)

Vasfed
Vasfed

Reputation: 18504

keepalive_timeout parameter is controlling for how long an idle client connection will be kept open to save on possible reconnect cost, it's not where your problem is.

For upstream timeouts there're proxy_connect_timeout, proxy_send_timeout and proxy_read_timeout (nginx default is 60s, but you seem to have these lower in your config files), you can try increasing the latter two, but usually noone wants server response times that high - because long requests block workers and clients may start getting timeouts for all requests, not only the 'heavy' ones.

Upvotes: 2

Related Questions