Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/nginx/nginx.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/src/http
diff options
context:
space:
mode:
authorMaxim Dounin <mdounin@mdounin.ru>2018-08-10 21:54:46 +0300
committerMaxim Dounin <mdounin@mdounin.ru>2018-08-10 21:54:46 +0300
commitd817ceae729914e7423c4c206165fc244513f021 (patch)
tree556b398cd41a7ad290cf92fac7ab7f1346159248 /src/http
parent7de808990b8e49e2e18c2a013e4cca82a092fdbc (diff)
Upstream keepalive: keepalive_requests directive.
The directive configures maximum number of requests allowed on a connection kept in the cache. Once a connection reaches the number of requests configured, it is no longer saved to the cache. The default is 100. Much like keepalive_requests for client connections, this is mostly a safeguard to make sure connections are closed periodically and the memory allocated from the connection pool is freed.
Diffstat (limited to 'src/http')
-rw-r--r--src/http/modules/ngx_http_upstream_keepalive_module.c14
-rw-r--r--src/http/ngx_http_upstream.c2
2 files changed, 16 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 ffb2bcf2b..bdc4ae5c7 100644
--- a/src/http/modules/ngx_http_upstream_keepalive_module.c
+++ b/src/http/modules/ngx_http_upstream_keepalive_module.c
@@ -12,6 +12,7 @@
typedef struct {
ngx_uint_t max_cached;
+ ngx_uint_t requests;
ngx_msec_t timeout;
ngx_queue_t cache;
@@ -92,6 +93,13 @@ static ngx_command_t ngx_http_upstream_keepalive_commands[] = {
offsetof(ngx_http_upstream_keepalive_srv_conf_t, timeout),
NULL },
+ { ngx_string("keepalive_requests"),
+ NGX_HTTP_UPS_CONF|NGX_CONF_TAKE1,
+ ngx_conf_set_num_slot,
+ NGX_HTTP_SRV_CONF_OFFSET,
+ offsetof(ngx_http_upstream_keepalive_srv_conf_t, requests),
+ NULL },
+
ngx_null_command
};
@@ -142,6 +150,7 @@ ngx_http_upstream_init_keepalive(ngx_conf_t *cf,
ngx_http_upstream_keepalive_module);
ngx_conf_init_msec_value(kcf->timeout, 60000);
+ ngx_conf_init_uint_value(kcf->requests, 100);
if (kcf->original_init_upstream(cf, us) != NGX_OK) {
return NGX_ERROR;
@@ -312,6 +321,10 @@ ngx_http_upstream_free_keepalive_peer(ngx_peer_connection_t *pc, void *data,
goto invalid;
}
+ if (c->requests >= kp->conf->requests) {
+ goto invalid;
+ }
+
if (!u->keepalive) {
goto invalid;
}
@@ -500,6 +513,7 @@ ngx_http_upstream_keepalive_create_conf(ngx_conf_t *cf)
*/
conf->timeout = NGX_CONF_UNSET_MSEC;
+ conf->requests = NGX_CONF_UNSET_UINT;
return conf;
}
diff --git a/src/http/ngx_http_upstream.c b/src/http/ngx_http_upstream.c
index 63fa5d998..605ae3486 100644
--- a/src/http/ngx_http_upstream.c
+++ b/src/http/ngx_http_upstream.c
@@ -1546,6 +1546,8 @@ ngx_http_upstream_connect(ngx_http_request_t *r, ngx_http_upstream_t *u)
c = u->peer.connection;
+ c->requests++;
+
c->data = r;
c->write->handler = ngx_http_upstream_handler;