aboutsummaryrefslogtreecommitdiff
path: root/src/http/modules/ngx_http_upstream_keepalive_module.c
diff options
context:
space:
mode:
authorMaxim Dounin <mdounin@mdounin.ru>2021-04-08 00:15:48 +0300
committerMaxim Dounin <mdounin@mdounin.ru>2021-04-08 00:15:48 +0300
commitd9996d6f27150bfb9c9c00d77fac940712aa1d28 (patch)
tree0dddf15a4e9c9d31cb66677ea7f8746e9402f4c7 /src/http/modules/ngx_http_upstream_keepalive_module.c
parent5599731c00bd152f765c7cea24a7d257bf13320c (diff)
downloadnginx-d9996d6f27150bfb9c9c00d77fac940712aa1d28.tar.gz
nginx-d9996d6f27150bfb9c9c00d77fac940712aa1d28.zip
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.
Diffstat (limited to 'src/http/modules/ngx_http_upstream_keepalive_module.c')
-rw-r--r--src/http/modules/ngx_http_upstream_keepalive_module.c14
1 files changed, 14 insertions, 0 deletions
diff --git a/src/http/modules/ngx_http_upstream_keepalive_module.c b/src/http/modules/ngx_http_upstream_keepalive_module.c
index 1560807c6..bbd650b79 100644
--- a/src/http/modules/ngx_http_upstream_keepalive_module.c
+++ b/src/http/modules/ngx_http_upstream_keepalive_module.c
@@ -13,6 +13,7 @@
typedef struct {
ngx_uint_t max_cached;
ngx_uint_t requests;
+ ngx_msec_t time;
ngx_msec_t timeout;
ngx_queue_t cache;
@@ -86,6 +87,13 @@ static ngx_command_t ngx_http_upstream_keepalive_commands[] = {
0,
NULL },
+ { ngx_string("keepalive_time"),
+ NGX_HTTP_UPS_CONF|NGX_CONF_TAKE1,
+ ngx_conf_set_msec_slot,
+ NGX_HTTP_SRV_CONF_OFFSET,
+ offsetof(ngx_http_upstream_keepalive_srv_conf_t, time),
+ NULL },
+
{ ngx_string("keepalive_timeout"),
NGX_HTTP_UPS_CONF|NGX_CONF_TAKE1,
ngx_conf_set_msec_slot,
@@ -149,6 +157,7 @@ ngx_http_upstream_init_keepalive(ngx_conf_t *cf,
kcf = ngx_http_conf_upstream_srv_conf(us,
ngx_http_upstream_keepalive_module);
+ ngx_conf_init_msec_value(kcf->time, 3600000);
ngx_conf_init_msec_value(kcf->timeout, 60000);
ngx_conf_init_uint_value(kcf->requests, 100);
@@ -326,6 +335,10 @@ ngx_http_upstream_free_keepalive_peer(ngx_peer_connection_t *pc, void *data,
goto invalid;
}
+ if (ngx_current_msec - c->start_time > kp->conf->time) {
+ goto invalid;
+ }
+
if (!u->keepalive) {
goto invalid;
}
@@ -513,6 +526,7 @@ ngx_http_upstream_keepalive_create_conf(ngx_conf_t *cf)
* conf->max_cached = 0;
*/
+ conf->time = NGX_CONF_UNSET_MSEC;
conf->timeout = NGX_CONF_UNSET_MSEC;
conf->requests = NGX_CONF_UNSET_UINT;