Welcome! Log In Create A New Profile

Advanced

Re: [nginx] Upstream keepalive: keepalive_requests directive.

Robert Paprocki
August 10, 2018 04:52PM
Quite the patch. I recall this behavior being discussed a number of times
in the past.

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")?

On Fri, Aug 10, 2018 at 1:02 PM, Maxim Dounin <mdounin@mdounin.ru> wrote:

> details: http://hg.nginx.org/nginx/rev/70c6b08973a0
> branches:
> changeset: 7340:70c6b08973a0
> user: Maxim Dounin <mdounin@mdounin.ru>
> date: Fri Aug 10 21:54:46 2018 +0300
> description:
> 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:
>
> src/http/modules/ngx_http_upstream_keepalive_module.c | 14
> ++++++++++++++
> src/http/ngx_http_upstream.c | 2 ++
> 2 files changed, 16 insertions(+), 0 deletions(-)
>
> diffs (64 lines):
>
> diff --git a/src/http/modules/ngx_http_upstream_keepalive_module.c
> b/src/http/modules/ngx_http_upstream_keepalive_module.c
> --- 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_
> 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_con
> 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(ng
> 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(
> */
>
> 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
> --- a/src/http/ngx_http_upstream.c
> +++ b/src/http/ngx_http_upstream.c
> @@ -1546,6 +1546,8 @@ ngx_http_upstream_connect(ngx_http_reque
>
> c = u->peer.connection;
>
> + c->requests++;
> +
> c->data = r;
>
> c->write->handler = ngx_http_upstream_handler;
> _______________________________________________
> nginx-devel mailing list
> nginx-devel@nginx.org
> http://mailman.nginx.org/mailman/listinfo/nginx-devel
>
_______________________________________________
nginx-devel mailing list
nginx-devel@nginx.org
http://mailman.nginx.org/mailman/listinfo/nginx-devel
Subject Author Views Posted

[nginx] Upstream keepalive: keepalive_requests directive.

Maxim Dounin 138 August 10, 2018 04:04PM

Re: [nginx] Upstream keepalive: keepalive_requests directive.

Robert Paprocki 27 August 10, 2018 04:52PM

Re: [nginx] Upstream keepalive: keepalive_requests directive.

Maxim Dounin 19 August 12, 2018 08:44AM

Re: [nginx] Upstream keepalive: keepalive_requests directive.

Frank Liu 16 August 13, 2018 03:32AM

Re: [nginx] Upstream keepalive: keepalive_requests directive.

Maxim Dounin 40 August 13, 2018 10:36AM

Re: [nginx] Upstream keepalive: keepalive_requests directive.

Frank Liu 18 August 11, 2018 12:34PM

Re: [nginx] Upstream keepalive: keepalive_requests directive.

Maxim Dounin 24 August 12, 2018 09:02AM



Sorry, you do not have permission to post/reply in this forum.

Online Users

Guests: 95
Record Number of Users: 6 on February 13, 2018
Record Number of Guests: 254 on July 05, 2018
Powered by nginx      Powered by FreeBSD      PHP Powered      Powered by MariaDB      ipv6 ready