comparison src/http/ngx_http_core_module.c @ 7820:fdc3d40979b0

Introduced the "keepalive_time" directive. Similar to lingering_time, it limits total connection lifetime before keepalive is switched off. The default is 1 hour, which is close to the total maximum connection lifetime possible with default keepalive_requests and keepalive_timeout.
author Maxim Dounin <mdounin@mdounin.ru>
date Thu, 08 Apr 2021 00:15:48 +0300
parents 1ebd78df4ce7
children 82e174e47663
comparison
equal deleted inserted replaced
7819:3674d5b7174e 7820:fdc3d40979b0
493 ngx_http_set_complex_value_size_slot, 493 ngx_http_set_complex_value_size_slot,
494 NGX_HTTP_LOC_CONF_OFFSET, 494 NGX_HTTP_LOC_CONF_OFFSET,
495 offsetof(ngx_http_core_loc_conf_t, limit_rate_after), 495 offsetof(ngx_http_core_loc_conf_t, limit_rate_after),
496 NULL }, 496 NULL },
497 497
498 { ngx_string("keepalive_time"),
499 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1,
500 ngx_conf_set_msec_slot,
501 NGX_HTTP_LOC_CONF_OFFSET,
502 offsetof(ngx_http_core_loc_conf_t, keepalive_time),
503 NULL },
504
498 { ngx_string("keepalive_timeout"), 505 { ngx_string("keepalive_timeout"),
499 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE12, 506 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE12,
500 ngx_http_core_keepalive, 507 ngx_http_core_keepalive,
501 NGX_HTTP_LOC_CONF_OFFSET, 508 NGX_HTTP_LOC_CONF_OFFSET,
502 0, 509 0,
1331 if (r->keepalive) { 1338 if (r->keepalive) {
1332 if (clcf->keepalive_timeout == 0) { 1339 if (clcf->keepalive_timeout == 0) {
1333 r->keepalive = 0; 1340 r->keepalive = 0;
1334 1341
1335 } else if (r->connection->requests >= clcf->keepalive_requests) { 1342 } else if (r->connection->requests >= clcf->keepalive_requests) {
1343 r->keepalive = 0;
1344
1345 } else if (ngx_current_msec - r->connection->start_time
1346 > clcf->keepalive_time)
1347 {
1336 r->keepalive = 0; 1348 r->keepalive = 0;
1337 1349
1338 } else if (r->headers_in.msie6 1350 } else if (r->headers_in.msie6
1339 && r->method == NGX_HTTP_POST 1351 && r->method == NGX_HTTP_POST
1340 && (clcf->keepalive_disable 1352 && (clcf->keepalive_disable
3498 clcf->tcp_nopush = NGX_CONF_UNSET; 3510 clcf->tcp_nopush = NGX_CONF_UNSET;
3499 clcf->tcp_nodelay = NGX_CONF_UNSET; 3511 clcf->tcp_nodelay = NGX_CONF_UNSET;
3500 clcf->send_timeout = NGX_CONF_UNSET_MSEC; 3512 clcf->send_timeout = NGX_CONF_UNSET_MSEC;
3501 clcf->send_lowat = NGX_CONF_UNSET_SIZE; 3513 clcf->send_lowat = NGX_CONF_UNSET_SIZE;
3502 clcf->postpone_output = NGX_CONF_UNSET_SIZE; 3514 clcf->postpone_output = NGX_CONF_UNSET_SIZE;
3515 clcf->keepalive_time = NGX_CONF_UNSET_MSEC;
3503 clcf->keepalive_timeout = NGX_CONF_UNSET_MSEC; 3516 clcf->keepalive_timeout = NGX_CONF_UNSET_MSEC;
3504 clcf->keepalive_header = NGX_CONF_UNSET; 3517 clcf->keepalive_header = NGX_CONF_UNSET;
3505 clcf->keepalive_requests = NGX_CONF_UNSET_UINT; 3518 clcf->keepalive_requests = NGX_CONF_UNSET_UINT;
3506 clcf->lingering_close = NGX_CONF_UNSET_UINT; 3519 clcf->lingering_close = NGX_CONF_UNSET_UINT;
3507 clcf->lingering_time = NGX_CONF_UNSET_MSEC; 3520 clcf->lingering_time = NGX_CONF_UNSET_MSEC;
3736 3749
3737 if (conf->limit_rate_after == NULL) { 3750 if (conf->limit_rate_after == NULL) {
3738 conf->limit_rate_after = prev->limit_rate_after; 3751 conf->limit_rate_after = prev->limit_rate_after;
3739 } 3752 }
3740 3753
3754 ngx_conf_merge_msec_value(conf->keepalive_time,
3755 prev->keepalive_time, 3600000);
3741 ngx_conf_merge_msec_value(conf->keepalive_timeout, 3756 ngx_conf_merge_msec_value(conf->keepalive_timeout,
3742 prev->keepalive_timeout, 75000); 3757 prev->keepalive_timeout, 75000);
3743 ngx_conf_merge_sec_value(conf->keepalive_header, 3758 ngx_conf_merge_sec_value(conf->keepalive_header,
3744 prev->keepalive_header, 0); 3759 prev->keepalive_header, 0);
3745 ngx_conf_merge_uint_value(conf->keepalive_requests, 3760 ngx_conf_merge_uint_value(conf->keepalive_requests,