Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Default value of nginx keepalive

Tags:

nginx

From nginx.org, the default value of keepalive config is —, however I don't quite understand what does this mean.

Syntax: keepalive connections;
Default:    —
Context:    upstream
This directive appeared in version 1.1.4.
like image 570
ponypaver Avatar asked Sep 26 '17 07:09

ponypaver


People also ask

What is NGINX keepalive?

In Nginx, keepalive is a directive that is utilized for keeping the connection open for a certain number of requests to the server or until the request timeout period has expired.

What is default Keepalive_timeout in NGINX?

Default: keepalive_timeout 75s; Context: http , server , location. The first parameter sets a timeout during which a keep-alive client connection will stay open on the server side.

How many RPS can NGINX handle?

The configuration allows bursts of up to 12 requests, the first 8 of which are processed without delay. A delay is added after 8 excessive requests to enforce the 5 r/s limit. After 12 excessive requests, any further requests are rejected.

How do I disable keep-alive in NGINX?

In order to disable keep-alive do keepalive_timeout 0; .


1 Answers

In order Nginx to keep TCP connection alive both upstream section and origin server should be configured to not finalise the connection. Upstream section keepalive default value means no keepalive, hence connection won't be reused, each time you can see TCP stream number increases per every request to origin server, opposite to what happens with keepalive. You can check it with using tcpdump.

10 Tips for 10x Application Performance blog post describes it very well:

Client keepalives – Keepalive connections reduce overhead, especially when SSL/TLS is in use. For NGINX, you can increase the maximum number of keepalive_requests a client can make over a given connection from the default of 100, and you can increase the keepalive_timeout to allow the keepalive connection to stay open longer, resulting in faster subsequent requests.

Upstream keepalives – Upstream connections – connections to application servers, database servers, and so on – benefit from keepalive connections as well. For upstream connections, you can increase keepalive, the number of idle keepalive connections that remain open for each worker process. This allows for increased connection reuse, cutting down on the need to open brand new connections. For more information, refer to our blog post, HTTP Keepalive Connections and Web Performance.

See also RFC-793 Section 3.5:

A TCP connection may terminate in two ways: (1) the normal TCP close sequence using a FIN handshake, and (2) an "abort" in which one or more RST segments are sent and the connection state is immediately discarded. If a TCP connection is closed by the remote site, the local application MUST be informed whether it closed normally or was aborted.

Two examples, take a look on Application Data below.

Without keepalive: without keepalive

With keepalive: with keepalive

like image 99
Anatoly Avatar answered Oct 23 '22 11:10

Anatoly