<div dir="ltr">Quite the patch. I recall this behavior being discussed a number of times in the past.<div><br></div><div>Question: why the default of 100? This feels like a significantly breaking change wrt. the previous behavior. Are there any plans for advanced communication regarding this change, outside of a nominal changelog entry (e.g., "introduced 'keepalive_requests' directive")?</div></div><div class="gmail_extra"><br><div class="gmail_quote">On Fri, Aug 10, 2018 at 1:02 PM, Maxim Dounin <span dir="ltr"><<a href="mailto:mdounin@mdounin.ru" target="_blank">mdounin@mdounin.ru</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">details: <a href="http://hg.nginx.org/nginx/rev/70c6b08973a0" rel="noreferrer" target="_blank">http://hg.nginx.org/nginx/rev/<wbr>70c6b08973a0</a><br>
branches: <br>
changeset: 7340:70c6b08973a0<br>
user: Maxim Dounin <<a href="mailto:mdounin@mdounin.ru">mdounin@mdounin.ru</a>><br>
date: Fri Aug 10 21:54:46 2018 +0300<br>
description:<br>
Upstream keepalive: keepalive_requests directive.<br>
<br>
The directive configures maximum number of requests allowed on<br>
a connection kept in the cache. Once a connection reaches the number<br>
of requests configured, it is no longer saved to the cache.<br>
The default is 100.<br>
<br>
Much like keepalive_requests for client connections, this is mostly<br>
a safeguard to make sure connections are closed periodically and the<br>
memory allocated from the connection pool is freed.<br>
<br>
diffstat:<br>
<br>
src/http/modules/ngx_http_<wbr>upstream_keepalive_module.c | 14 ++++++++++++++<br>
src/http/ngx_http_upstream.c | 2 ++<br>
2 files changed, 16 insertions(+), 0 deletions(-)<br>
<br>
diffs (64 lines):<br>
<br>
diff --git a/src/http/modules/ngx_http_<wbr>upstream_keepalive_module.c b/src/http/modules/ngx_http_<wbr>upstream_keepalive_module.c<br>
--- a/src/http/modules/ngx_http_<wbr>upstream_keepalive_module.c<br>
+++ b/src/http/modules/ngx_http_<wbr>upstream_keepalive_module.c<br>
@@ -12,6 +12,7 @@<br>
<br>
typedef struct {<br>
ngx_uint_t max_cached;<br>
+ ngx_uint_t requests;<br>
ngx_msec_t timeout;<br>
<br>
ngx_queue_t cache;<br>
@@ -92,6 +93,13 @@ static ngx_command_t ngx_http_upstream_<br>
offsetof(ngx_http_upstream_<wbr>keepalive_srv_conf_t, timeout),<br>
NULL },<br>
<br>
+ { ngx_string("keepalive_<wbr>requests"),<br>
+ NGX_HTTP_UPS_CONF|NGX_CONF_<wbr>TAKE1,<br>
+ ngx_conf_set_num_slot,<br>
+ NGX_HTTP_SRV_CONF_OFFSET,<br>
+ offsetof(ngx_http_upstream_<wbr>keepalive_srv_conf_t, requests),<br>
+ NULL },<br>
+<br>
ngx_null_command<br>
};<br>
<br>
@@ -142,6 +150,7 @@ ngx_http_upstream_init_<wbr>keepalive(ngx_con<br>
ngx_http_upstream_keepalive_<wbr>module);<br>
<br>
ngx_conf_init_msec_value(kcf-><wbr>timeout, 60000);<br>
+ ngx_conf_init_uint_value(kcf-><wbr>requests, 100);<br>
<br>
if (kcf->original_init_upstream(<wbr>cf, us) != NGX_OK) {<br>
return NGX_ERROR;<br>
@@ -312,6 +321,10 @@ ngx_http_upstream_free_<wbr>keepalive_peer(ng<br>
goto invalid;<br>
}<br>
<br>
+ if (c->requests >= kp->conf->requests) {<br>
+ goto invalid;<br>
+ }<br>
+<br>
if (!u->keepalive) {<br>
goto invalid;<br>
}<br>
@@ -500,6 +513,7 @@ ngx_http_upstream_keepalive_<wbr>create_conf(<br>
*/<br>
<br>
conf->timeout = NGX_CONF_UNSET_MSEC;<br>
+ conf->requests = NGX_CONF_UNSET_UINT;<br>
<br>
return conf;<br>
}<br>
diff --git a/src/http/ngx_http_upstream.c b/src/http/ngx_http_upstream.c<br>
--- a/src/http/ngx_http_upstream.c<br>
+++ b/src/http/ngx_http_upstream.c<br>
@@ -1546,6 +1546,8 @@ ngx_http_upstream_connect(ngx_<wbr>http_reque<br>
<br>
c = u->peer.connection;<br>
<br>
+ c->requests++;<br>
+<br>
c->data = r;<br>
<br>
c->write->handler = ngx_http_upstream_handler;<br>
______________________________<wbr>_________________<br>
nginx-devel mailing list<br>
<a href="mailto:nginx-devel@nginx.org">nginx-devel@nginx.org</a><br>
<a href="http://mailman.nginx.org/mailman/listinfo/nginx-devel" rel="noreferrer" target="_blank">http://mailman.nginx.org/<wbr>mailman/listinfo/nginx-devel</a><br>
</blockquote></div><br></div>