Welcome! Log In Create A New Profile

Advanced

[nginx] Core: reusing connections in advance.

Maxim Dounin
August 10, 2020 11:58AM
details: https://hg.nginx.org/nginx/rev/5440ff4ac6fc
branches:
changeset: 7698:5440ff4ac6fc
user: Maxim Dounin <mdounin@mdounin.ru>
date: Mon Aug 10 18:53:07 2020 +0300
description:
Core: reusing connections in advance.

Reworked connections reuse, so closing connections is attempted in
advance, as long as number of free connections is less than 1/16 of
worker connections configured. This ensures that new connections can
be handled even if closing a reusable connection requires some time,
for example, for a lingering close (ticket #2017).

The 1/16 ratio is selected to be smaller than 1/8 used for disabling
accept when working with accept mutex, so nginx will try to balance
new connections to different workers first, and will start reusing
connections only if this won't help.

diffstat:

src/core/ngx_connection.c | 11 +++++------
1 files changed, 5 insertions(+), 6 deletions(-)

diffs (29 lines):

diff -r b9071b875194 -r 5440ff4ac6fc src/core/ngx_connection.c
--- a/src/core/ngx_connection.c Mon Aug 10 18:52:59 2020 +0300
+++ b/src/core/ngx_connection.c Mon Aug 10 18:53:07 2020 +0300
@@ -1107,12 +1107,9 @@ ngx_get_connection(ngx_socket_t s, ngx_l
return NULL;
}

- c = ngx_cycle->free_connections;
+ ngx_drain_connections((ngx_cycle_t *) ngx_cycle);

- if (c == NULL) {
- ngx_drain_connections((ngx_cycle_t *) ngx_cycle);
- c = ngx_cycle->free_connections;
- }
+ c = ngx_cycle->free_connections;

if (c == NULL) {
ngx_log_error(NGX_LOG_ALERT, log, 0,
@@ -1298,7 +1295,9 @@ ngx_drain_connections(ngx_cycle_t *cycle
ngx_queue_t *q;
ngx_connection_t *c;

- if (cycle->reusable_connections_n == 0) {
+ if (cycle->free_connection_n > cycle->connection_n / 16
+ || cycle->reusable_connections_n == 0)
+ {
return;
}

_______________________________________________
nginx-devel mailing list
nginx-devel@nginx.org
http://mailman.nginx.org/mailman/listinfo/nginx-devel
Subject Author Views Posted

[nginx] Core: reusing connections in advance.

Maxim Dounin 304 August 10, 2020 11:58AM



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

Online Users

Guests: 291
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