Increase buffer timeout size on nginx

Girish BR picture Girish BR · Feb 24, 2014 · Viewed 12k times · Source

I have a nodejs program that connects to cloudstack apis. Creating a Virtual Machine on cloudstack takes almost 20 secs.

The program works fine on my local nodejs installation and also on apigee cloud. However when I deploy the same on customer's OPDK, Nginx returns a 502 - Bad gateway. This link http://www.nginxtips.com/502-bad-gateway-using-nginx/ recommends increasing the buffer and timeout sizes in nginx.conf

http {
...
fastcgi_buffers 8 16k;
fastcgi_buffer_size 32k;
fastcgi_connect_timeout 300;
fastcgi_send_timeout 300;
fastcgi_read_timeout 300;
...
}

What is the recommended ideal value? What is it on Apigee cloud?

Regards, Girish

Answer

Michael Russo picture Michael Russo · Feb 25, 2014

You may need to look at the proxy timeout configs in nginx if using nginx as a proxy:

http://www.nginxtips.com/504-gateway-time-out-using-nginx/
http://wiki.nginx.org/HttpProxyModule

 proxy_connect_timeout       60;
 proxy_read_timeout          120;

Apigee timeout defaults:

Connect timeout - 60s - connect.timeout.millis
Read timeout - 120s - io.timeout.millis

FYI Apigee timeouts are also configurable (in milliseconds) within the TargetEndpoint connection:

<HTTPTargetConnection>
    <Properties>
        <Property name="connect.timeout.millis">5000</Property>
        <Property name="io.timeout.millis">5000</Property>
    </Properties>
    <URL>http://www.google.com</URL>
</HTTPTargetConnection>

Depending on how long the server takes to respond can determine your ideal timeout configurations. In this case, a read timeout of 45-60s might be ideal to provide some buffer in case cloudstack slows down more.