Mercurial > hg > nginx
comparison src/core/ngx_connection.c @ 7698:5440ff4ac6fc
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.
author | Maxim Dounin <mdounin@mdounin.ru> |
---|---|
date | Mon, 10 Aug 2020 18:53:07 +0300 |
parents | b9071b875194 |
children | 6d98f29867e8 532fe796b0e2 |
comparison
equal
deleted
inserted
replaced
7697:b9071b875194 | 7698:5440ff4ac6fc |
---|---|
1105 "but only %ui files are available", | 1105 "but only %ui files are available", |
1106 s, ngx_cycle->files_n); | 1106 s, ngx_cycle->files_n); |
1107 return NULL; | 1107 return NULL; |
1108 } | 1108 } |
1109 | 1109 |
1110 ngx_drain_connections((ngx_cycle_t *) ngx_cycle); | |
1111 | |
1110 c = ngx_cycle->free_connections; | 1112 c = ngx_cycle->free_connections; |
1111 | |
1112 if (c == NULL) { | |
1113 ngx_drain_connections((ngx_cycle_t *) ngx_cycle); | |
1114 c = ngx_cycle->free_connections; | |
1115 } | |
1116 | 1113 |
1117 if (c == NULL) { | 1114 if (c == NULL) { |
1118 ngx_log_error(NGX_LOG_ALERT, log, 0, | 1115 ngx_log_error(NGX_LOG_ALERT, log, 0, |
1119 "%ui worker_connections are not enough", | 1116 "%ui worker_connections are not enough", |
1120 ngx_cycle->connection_n); | 1117 ngx_cycle->connection_n); |
1296 { | 1293 { |
1297 ngx_uint_t i, n; | 1294 ngx_uint_t i, n; |
1298 ngx_queue_t *q; | 1295 ngx_queue_t *q; |
1299 ngx_connection_t *c; | 1296 ngx_connection_t *c; |
1300 | 1297 |
1301 if (cycle->reusable_connections_n == 0) { | 1298 if (cycle->free_connection_n > cycle->connection_n / 16 |
1299 || cycle->reusable_connections_n == 0) | |
1300 { | |
1302 return; | 1301 return; |
1303 } | 1302 } |
1304 | 1303 |
1305 if (cycle->connections_reuse_time != ngx_time()) { | 1304 if (cycle->connections_reuse_time != ngx_time()) { |
1306 cycle->connections_reuse_time = ngx_time(); | 1305 cycle->connections_reuse_time = ngx_time(); |