Welcome! Log In Create A New Profile

Advanced

[PATCH] Fix drain logic for small number of connections

Joel Cunningham
December 07, 2016 04:52PM
Hi,

I run NGINX in an embedded environment with limited resources. We have NGINX configured with a small number of maximum connections (worker_connections is 16). I’ve found the ngx_drain_connection() logic uses a hard-coded value to limit the number of reaped reusable connections. This works fine with the default 512, but is too aggressive for small number of connections and ends up reaping all reusable connections. These include new connections just accepted on the previous event loop cycle (which had not yet had a chance to receive a request) at the head of the list.

The below patch switches to the minimum of 32 or 1/4 of the number of connections. This should be less aggressive, even when the number of connections is slightly larger than 32, e.g. 48 or 64.

Joel

# HG changeset patch
# User Joel Cunningham <joel.cunningham@me.com>
# Date 1481145862 21600
# Wed Dec 07 15:24:22 2016 -0600
# Node ID b103dddcee7322522651f9aca764d499d5822ac1
# Parent 75dbab4ea930bc73cca98d183c2f556eb5125462
Fix drain logic for small number of connections

This commit fixes the ngx_drain_connections logic when maximum number of
connections are small (16/32/64). Using a hardcoded value of 32 when
the number of connections is small is overlly aggressive and will result
in repeaing the entire (or large portion of) the reusable_connections_queue,
which includes at the tail newly accepted connections that have not received
a request yet

The logic is updated to use the minimum of 1/4 the number of connections
or 32, which ever is smaller

diff -r 75dbab4ea930 -r b103dddcee73 src/core/ngx_connection.c
--- a/src/core/ngx_connection.c Mon Nov 21 16:03:42 2016 +0300
+++ b/src/core/ngx_connection.c Wed Dec 07 15:24:22 2016 -0600
@@ -1232,7 +1232,7 @@
ngx_queue_t *q;
ngx_connection_t *c;

- for (i = 0; i < 32; i++) {
+ for (i = 0; i < ngx_min(32, ngx_cycle->connection_n / 4); i++) {
if (ngx_queue_empty(&ngx_cycle->reusable_connections_queue)) {
break;
}
_______________________________________________
nginx-devel mailing list
nginx-devel@nginx.org
http://mailman.nginx.org/mailman/listinfo/nginx-devel
Subject Author Views Posted

[PATCH] Fix drain logic for small number of connections

Joel Cunningham 718 December 07, 2016 04:52PM

Re: [PATCH] Fix drain logic for small number of connections

Joel Cunningham 306 December 27, 2016 05:38PM

Re: [PATCH] Fix drain logic for small number of connections

Joel Cunningham 269 December 30, 2016 01:14PM

Re: [PATCH] Fix drain logic for small number of connections

Maxim Dounin 270 December 30, 2016 09:06PM

Re: [PATCH] Fix drain logic for small number of connections

Joel Cunningham 218 January 17, 2017 10:40AM

Re: [PATCH] Fix drain logic for small number of connections

Maxim Dounin 396 January 19, 2017 08:04AM



Sorry, you do not have permission to post/reply in this forum.

Online Users

Guests: 101
Record Number of Users: 8 on April 13, 2023
Record Number of Guests: 421 on December 02, 2018
Powered by nginx      Powered by FreeBSD      PHP Powered      Powered by MariaDB      ipv6 ready