comparison src/http/modules/ngx_http_upstream_keepalive_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 3939483cd1b5
children 82e174e47663
comparison
equal deleted inserted replaced
7819:3674d5b7174e 7820:fdc3d40979b0
11 11
12 12
13 typedef struct { 13 typedef struct {
14 ngx_uint_t max_cached; 14 ngx_uint_t max_cached;
15 ngx_uint_t requests; 15 ngx_uint_t requests;
16 ngx_msec_t time;
16 ngx_msec_t timeout; 17 ngx_msec_t timeout;
17 18
18 ngx_queue_t cache; 19 ngx_queue_t cache;
19 ngx_queue_t free; 20 ngx_queue_t free;
20 21
82 { ngx_string("keepalive"), 83 { ngx_string("keepalive"),
83 NGX_HTTP_UPS_CONF|NGX_CONF_TAKE1, 84 NGX_HTTP_UPS_CONF|NGX_CONF_TAKE1,
84 ngx_http_upstream_keepalive, 85 ngx_http_upstream_keepalive,
85 NGX_HTTP_SRV_CONF_OFFSET, 86 NGX_HTTP_SRV_CONF_OFFSET,
86 0, 87 0,
88 NULL },
89
90 { ngx_string("keepalive_time"),
91 NGX_HTTP_UPS_CONF|NGX_CONF_TAKE1,
92 ngx_conf_set_msec_slot,
93 NGX_HTTP_SRV_CONF_OFFSET,
94 offsetof(ngx_http_upstream_keepalive_srv_conf_t, time),
87 NULL }, 95 NULL },
88 96
89 { ngx_string("keepalive_timeout"), 97 { ngx_string("keepalive_timeout"),
90 NGX_HTTP_UPS_CONF|NGX_CONF_TAKE1, 98 NGX_HTTP_UPS_CONF|NGX_CONF_TAKE1,
91 ngx_conf_set_msec_slot, 99 ngx_conf_set_msec_slot,
147 "init keepalive"); 155 "init keepalive");
148 156
149 kcf = ngx_http_conf_upstream_srv_conf(us, 157 kcf = ngx_http_conf_upstream_srv_conf(us,
150 ngx_http_upstream_keepalive_module); 158 ngx_http_upstream_keepalive_module);
151 159
160 ngx_conf_init_msec_value(kcf->time, 3600000);
152 ngx_conf_init_msec_value(kcf->timeout, 60000); 161 ngx_conf_init_msec_value(kcf->timeout, 60000);
153 ngx_conf_init_uint_value(kcf->requests, 100); 162 ngx_conf_init_uint_value(kcf->requests, 100);
154 163
155 if (kcf->original_init_upstream(cf, us) != NGX_OK) { 164 if (kcf->original_init_upstream(cf, us) != NGX_OK) {
156 return NGX_ERROR; 165 return NGX_ERROR;
324 333
325 if (c->requests >= kp->conf->requests) { 334 if (c->requests >= kp->conf->requests) {
326 goto invalid; 335 goto invalid;
327 } 336 }
328 337
338 if (ngx_current_msec - c->start_time > kp->conf->time) {
339 goto invalid;
340 }
341
329 if (!u->keepalive) { 342 if (!u->keepalive) {
330 goto invalid; 343 goto invalid;
331 } 344 }
332 345
333 if (!u->request_body_sent) { 346 if (!u->request_body_sent) {
511 * conf->original_init_upstream = NULL; 524 * conf->original_init_upstream = NULL;
512 * conf->original_init_peer = NULL; 525 * conf->original_init_peer = NULL;
513 * conf->max_cached = 0; 526 * conf->max_cached = 0;
514 */ 527 */
515 528
529 conf->time = NGX_CONF_UNSET_MSEC;
516 conf->timeout = NGX_CONF_UNSET_MSEC; 530 conf->timeout = NGX_CONF_UNSET_MSEC;
517 conf->requests = NGX_CONF_UNSET_UINT; 531 conf->requests = NGX_CONF_UNSET_UINT;
518 532
519 return conf; 533 return conf;
520 } 534 }