diff options
author | Maxim Dounin <mdounin@mdounin.ru> | 2017-01-20 14:03:20 +0300 |
---|---|---|
committer | Maxim Dounin <mdounin@mdounin.ru> | 2017-01-20 14:03:20 +0300 |
commit | c3ad24da01c062eaa4eb096f85f9be2312316821 (patch) | |
tree | 20c15be390173fe2638da269b29bc9c7bc449d04 /src/core/ngx_connection.c | |
parent | 660e1a5340f15bdfcedfd298ccf96ca8a9604af2 (diff) | |
download | nginx-c3ad24da01c062eaa4eb096f85f9be2312316821.tar.gz nginx-c3ad24da01c062eaa4eb096f85f9be2312316821.zip |
Improved connection draining with small number of connections.
Closing up to 32 connections might be too aggressive if worker_connections
is set to a comparable number (and/or there are only a small number of
reusable connections). If an occasional connection shorage happens in
such a configuration, it leads to closing all reusable connections instead
of gradually reducing keepalive timeout to a smaller value. To improve
granularity in such configurations we now close no more than 1/8 of all
reusable connections at once.
Suggested by Joel Cunningham.
Diffstat (limited to 'src/core/ngx_connection.c')
-rw-r--r-- | src/core/ngx_connection.c | 8 |
1 files changed, 6 insertions, 2 deletions
diff --git a/src/core/ngx_connection.c b/src/core/ngx_connection.c index c43163f18..2af287614 100644 --- a/src/core/ngx_connection.c +++ b/src/core/ngx_connection.c @@ -1204,6 +1204,7 @@ ngx_reusable_connection(ngx_connection_t *c, ngx_uint_t reusable) if (c->reusable) { ngx_queue_remove(&c->queue); + ngx_cycle->reusable_connections_n--; #if (NGX_STAT_STUB) (void) ngx_atomic_fetch_add(ngx_stat_waiting, -1); @@ -1217,6 +1218,7 @@ ngx_reusable_connection(ngx_connection_t *c, ngx_uint_t reusable) ngx_queue_insert_head( (ngx_queue_t *) &ngx_cycle->reusable_connections_queue, &c->queue); + ngx_cycle->reusable_connections_n++; #if (NGX_STAT_STUB) (void) ngx_atomic_fetch_add(ngx_stat_waiting, 1); @@ -1228,11 +1230,13 @@ ngx_reusable_connection(ngx_connection_t *c, ngx_uint_t reusable) static void ngx_drain_connections(ngx_cycle_t *cycle) { - ngx_int_t i; + ngx_uint_t i, n; ngx_queue_t *q; ngx_connection_t *c; - for (i = 0; i < 32; i++) { + n = ngx_max(ngx_min(32, cycle->reusable_connections_n / 8), 1); + + for (i = 0; i < n; i++) { if (ngx_queue_empty(&cycle->reusable_connections_queue)) { break; } |