Mercurial > hg > nginx
comparison src/core/ngx_connection.c @ 7767:6d98f29867e8
Additional connections reuse.
If ngx_drain_connections() fails to immediately reuse any connections
and there are no free connections, it now additionally tries to reuse
a connection again. This helps to provide at least one free connection
in case of HTTP/2 with lingering close, where merely trying to reuse
a connection once does not free it, but makes it reusable again,
waiting for lingering close.
author | Maxim Dounin <mdounin@mdounin.ru> |
---|---|
date | Thu, 11 Feb 2021 21:52:11 +0300 |
parents | 5440ff4ac6fc |
children | 46815874bcc6 13f7085b90d2 |
comparison
equal
deleted
inserted
replaced
7766:3e83336cda5b | 7767:6d98f29867e8 |
---|---|
1308 "%ui worker_connections are not enough, " | 1308 "%ui worker_connections are not enough, " |
1309 "reusing connections", | 1309 "reusing connections", |
1310 cycle->connection_n); | 1310 cycle->connection_n); |
1311 } | 1311 } |
1312 | 1312 |
1313 c = NULL; | |
1313 n = ngx_max(ngx_min(32, cycle->reusable_connections_n / 8), 1); | 1314 n = ngx_max(ngx_min(32, cycle->reusable_connections_n / 8), 1); |
1314 | 1315 |
1315 for (i = 0; i < n; i++) { | 1316 for (i = 0; i < n; i++) { |
1316 if (ngx_queue_empty(&cycle->reusable_connections_queue)) { | 1317 if (ngx_queue_empty(&cycle->reusable_connections_queue)) { |
1317 break; | 1318 break; |
1320 q = ngx_queue_last(&cycle->reusable_connections_queue); | 1321 q = ngx_queue_last(&cycle->reusable_connections_queue); |
1321 c = ngx_queue_data(q, ngx_connection_t, queue); | 1322 c = ngx_queue_data(q, ngx_connection_t, queue); |
1322 | 1323 |
1323 ngx_log_debug0(NGX_LOG_DEBUG_CORE, c->log, 0, | 1324 ngx_log_debug0(NGX_LOG_DEBUG_CORE, c->log, 0, |
1324 "reusing connection"); | 1325 "reusing connection"); |
1326 | |
1327 c->close = 1; | |
1328 c->read->handler(c->read); | |
1329 } | |
1330 | |
1331 if (cycle->free_connection_n == 0 && c && c->reusable) { | |
1332 | |
1333 /* | |
1334 * if no connections were freed, try to reuse the last | |
1335 * connection again: this should free it as long as | |
1336 * previous reuse moved it to lingering close | |
1337 */ | |
1338 | |
1339 ngx_log_debug0(NGX_LOG_DEBUG_CORE, c->log, 0, | |
1340 "reusing connection again"); | |
1325 | 1341 |
1326 c->close = 1; | 1342 c->close = 1; |
1327 c->read->handler(c->read); | 1343 c->read->handler(c->read); |
1328 } | 1344 } |
1329 } | 1345 } |