Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ELB Keep-Alive Timeout: Varnish Configuration Assistance

I am looking to configure Varnish to optimize keep-alive timeout settings to work with my ELB. The ELB is using Varnish as the backend (providing caching for Tomcat).

The keep-alive timeout value has been set within Tomcat for 120s. Testing this it works fine via that port.

# time telnet XXX.XX.XX.XX 8080
Trying XXX.XX.XX.XX...
Connected to XXX.XX.XX.XX
Escape character is '^]'.
Connection closed by foreign host.

real    2m0.038s
user    0m0.002s
sys     0m0.004s

When we try and establish a connection via the Varnish port 9000, this timeouts within 6seconds

[root@dev-server ~]# time telnet XXX.XX.XX.XX 9000
Trying XXX.XX.XX.XX...
Connected to XXX.XX.XX.XX.
Escape character is '^]'.
Connection closed by foreign host.

real    0m6.093s
user    0m0.001s
sys     0m0.005s

Have checked several options for Varnish but nothing seems to work.

My default.vcl config for backend is as below

backend Example {
    .host = "localhost";
    .port = "8080";
    .connect_timeout = 600s;
    .first_byte_timeout = 600s;
    .between_bytes_timeout = 600s;
    .probe = {
        .url = "/service/search/test";
        .timeout = 500ms;
        .interval = 5s;
        .window = 10;
        .threshold = 8;
    }
}

Several forums suggests using idle_timeout or sess_timout but none of these are accepted variables. I am running Varnish 3.0.7 and no plans of upgrade now.

As per AWS support, they recommend ELB idle timeout + 1 second for keepalive timeout and double for the request timeout in general.

For example;

ELB idle timeout = 60 s
Request timeout = 120 s
KeepAlive timeout = 61 s

We have the ELB timeout set correctly but just need to figure out how we can set this within Varnish, as the connection closes within 6 secs. Ideally we want this to close in 120s (same value set in Tomcat)

Your help will be appreciated. Thanks

like image 206
Juzer Avatar asked Feb 02 '26 18:02

Juzer


1 Answers

The suggestions from several forums are correct, timeout_idle (previously known as sess_timeout in Varnish 3) is the setting you're looking for:

  • Units: seconds
  • Default: 5

Idle timeout for persistent sessions. If a HTTP request has not been received in this many seconds, the session is closed.

However, note that this is a varnishd parameter and not a VCL setting, so it doesn't go in your VCL but is passed as a command-line argument to varnishd.

To apply, add -p sess_timeout=61 to the list of command-line arguments passed to varnishd. (Typically this argument would be added to your distribution's configuration file that starts varnish, e.g., /etc/default/varnish on older Debian/Ubuntu).

You'll need to remember to restart the varnishd process (e.g., sudo service varnish restart on Debian/Ubuntu) for the setting to take effect.

like image 60
wjordan Avatar answered Feb 04 '26 12:02

wjordan



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!