[PATCH] Proxy: altered limit_rate to support variables
Sergey Kandaurov
pluknet at nginx.com
Tue Dec 26 15:07:37 UTC 2023
> On 26 Nov 2023, at 03:37, J Carter <jordanc.carter at outlook.com> wrote:
>
> # HG changeset patch
> # User J Carter <jordan.carter at outlook.com>
> # Date 1700949429 0
> # Sat Nov 25 21:57:09 2023 +0000
> # Node ID 98306e705015758eab0a05103d90e6bdb1da2819
> # Parent f366007dd23a6ce8e8427c1b3042781b618a2ade
> Proxy: altered limit_rate to support variables
Since it changes the upstream interface, I'd rather say:
Upstream: variables support in proxy_limit_rate and friends.
The change looks good to me, also it compliments variables support
in the stream proxy module's directives.
Any particular use-cases you'd like to share for this functionality?
>
> diff -r f366007dd23a -r 98306e705015 src/http/modules/ngx_http_fastcgi_module.c
> --- a/src/http/modules/ngx_http_fastcgi_module.c Tue Nov 14 15:26:02 2023 +0400
> +++ b/src/http/modules/ngx_http_fastcgi_module.c Sat Nov 25 21:57:09 2023 +0000
> @@ -375,7 +375,7 @@
>
> { ngx_string("fastcgi_limit_rate"),
> NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1,
> - ngx_conf_set_size_slot,
> + ngx_http_set_complex_value_size_slot,
> NGX_HTTP_LOC_CONF_OFFSET,
> offsetof(ngx_http_fastcgi_loc_conf_t, upstream.limit_rate),
> NULL },
> @@ -2898,7 +2898,7 @@
>
> conf->upstream.send_lowat = NGX_CONF_UNSET_SIZE;
> conf->upstream.buffer_size = NGX_CONF_UNSET_SIZE;
> - conf->upstream.limit_rate = NGX_CONF_UNSET_SIZE;
> + conf->upstream.limit_rate = NGX_CONF_UNSET_PTR;
>
> conf->upstream.busy_buffers_size_conf = NGX_CONF_UNSET_SIZE;
> conf->upstream.max_temp_file_size_conf = NGX_CONF_UNSET_SIZE;
> @@ -3015,8 +3015,8 @@
> prev->upstream.buffer_size,
> (size_t) ngx_pagesize);
>
> - ngx_conf_merge_size_value(conf->upstream.limit_rate,
> - prev->upstream.limit_rate, 0);
> + ngx_conf_merge_ptr_value(conf->upstream.limit_rate,
> + prev->upstream.limit_rate, NULL);
>
>
> ngx_conf_merge_bufs_value(conf->upstream.bufs, prev->upstream.bufs,
> diff -r f366007dd23a -r 98306e705015 src/http/modules/ngx_http_proxy_module.c
> --- a/src/http/modules/ngx_http_proxy_module.c Tue Nov 14 15:26:02 2023 +0400
> +++ b/src/http/modules/ngx_http_proxy_module.c Sat Nov 25 21:57:09 2023 +0000
> @@ -494,7 +494,7 @@
>
> { ngx_string("proxy_limit_rate"),
> NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1,
> - ngx_conf_set_size_slot,
> + ngx_http_set_complex_value_size_slot,
> NGX_HTTP_LOC_CONF_OFFSET,
> offsetof(ngx_http_proxy_loc_conf_t, upstream.limit_rate),
> NULL },
> @@ -3371,7 +3371,7 @@
>
> conf->upstream.send_lowat = NGX_CONF_UNSET_SIZE;
> conf->upstream.buffer_size = NGX_CONF_UNSET_SIZE;
> - conf->upstream.limit_rate = NGX_CONF_UNSET_SIZE;
> + conf->upstream.limit_rate = NGX_CONF_UNSET_PTR;
>
> conf->upstream.busy_buffers_size_conf = NGX_CONF_UNSET_SIZE;
> conf->upstream.max_temp_file_size_conf = NGX_CONF_UNSET_SIZE;
> @@ -3515,8 +3515,8 @@
> prev->upstream.buffer_size,
> (size_t) ngx_pagesize);
>
> - ngx_conf_merge_size_value(conf->upstream.limit_rate,
> - prev->upstream.limit_rate, 0);
> + ngx_conf_merge_ptr_value(conf->upstream.limit_rate,
> + prev->upstream.limit_rate, NULL);
>
> ngx_conf_merge_bufs_value(conf->upstream.bufs, prev->upstream.bufs,
> 8, ngx_pagesize);
> diff -r f366007dd23a -r 98306e705015 src/http/modules/ngx_http_scgi_module.c
> --- a/src/http/modules/ngx_http_scgi_module.c Tue Nov 14 15:26:02 2023 +0400
> +++ b/src/http/modules/ngx_http_scgi_module.c Sat Nov 25 21:57:09 2023 +0000
> @@ -223,7 +223,7 @@
>
> { ngx_string("scgi_limit_rate"),
> NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1,
> - ngx_conf_set_size_slot,
> + ngx_http_set_complex_value_size_slot,
> NGX_HTTP_LOC_CONF_OFFSET,
> offsetof(ngx_http_scgi_loc_conf_t, upstream.limit_rate),
> NULL },
> @@ -1301,7 +1301,7 @@
>
> conf->upstream.send_lowat = NGX_CONF_UNSET_SIZE;
> conf->upstream.buffer_size = NGX_CONF_UNSET_SIZE;
> - conf->upstream.limit_rate = NGX_CONF_UNSET_SIZE;
> + conf->upstream.limit_rate = NGX_CONF_UNSET_PTR;
>
> conf->upstream.busy_buffers_size_conf = NGX_CONF_UNSET_SIZE;
> conf->upstream.max_temp_file_size_conf = NGX_CONF_UNSET_SIZE;
> @@ -1413,8 +1413,8 @@
> prev->upstream.buffer_size,
> (size_t) ngx_pagesize);
>
> - ngx_conf_merge_size_value(conf->upstream.limit_rate,
> - prev->upstream.limit_rate, 0);
> + ngx_conf_merge_ptr_value(conf->upstream.limit_rate,
> + prev->upstream.limit_rate, NULL);
>
>
> ngx_conf_merge_bufs_value(conf->upstream.bufs, prev->upstream.bufs,
> diff -r f366007dd23a -r 98306e705015 src/http/modules/ngx_http_uwsgi_module.c
> --- a/src/http/modules/ngx_http_uwsgi_module.c Tue Nov 14 15:26:02 2023 +0400
> +++ b/src/http/modules/ngx_http_uwsgi_module.c Sat Nov 25 21:57:09 2023 +0000
> @@ -289,7 +289,7 @@
>
> { ngx_string("uwsgi_limit_rate"),
> NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1,
> - ngx_conf_set_size_slot,
> + ngx_http_set_complex_value_size_slot,
> NGX_HTTP_LOC_CONF_OFFSET,
> offsetof(ngx_http_uwsgi_loc_conf_t, upstream.limit_rate),
> NULL },
> @@ -1532,7 +1532,7 @@
>
> conf->upstream.send_lowat = NGX_CONF_UNSET_SIZE;
> conf->upstream.buffer_size = NGX_CONF_UNSET_SIZE;
> - conf->upstream.limit_rate = NGX_CONF_UNSET_SIZE;
> + conf->upstream.limit_rate = NGX_CONF_UNSET_PTR;
>
> conf->upstream.busy_buffers_size_conf = NGX_CONF_UNSET_SIZE;
> conf->upstream.max_temp_file_size_conf = NGX_CONF_UNSET_SIZE;
> @@ -1656,8 +1656,8 @@
> prev->upstream.buffer_size,
> (size_t) ngx_pagesize);
>
> - ngx_conf_merge_size_value(conf->upstream.limit_rate,
> - prev->upstream.limit_rate, 0);
> + ngx_conf_merge_ptr_value(conf->upstream.limit_rate,
> + prev->upstream.limit_rate, NULL);
>
>
> ngx_conf_merge_bufs_value(conf->upstream.bufs, prev->upstream.bufs,
> diff -r f366007dd23a -r 98306e705015 src/http/ngx_http_upstream.c
> --- a/src/http/ngx_http_upstream.c Tue Nov 14 15:26:02 2023 +0400
> +++ b/src/http/ngx_http_upstream.c Sat Nov 25 21:57:09 2023 +0000
> @@ -3236,7 +3236,7 @@
> p->downstream = c;
> p->pool = r->pool;
> p->log = c->log;
> - p->limit_rate = u->conf->limit_rate;
> + p->limit_rate = ngx_http_complex_value_size(r, u->conf->limit_rate, 0);
> p->start_sec = ngx_time();
>
> p->cacheable = u->cacheable || u->store;
> diff -r f366007dd23a -r 98306e705015 src/http/ngx_http_upstream.h
> --- a/src/http/ngx_http_upstream.h Tue Nov 14 15:26:02 2023 +0400
> +++ b/src/http/ngx_http_upstream.h Sat Nov 25 21:57:09 2023 +0000
> @@ -156,7 +156,7 @@
>
> size_t send_lowat;
> size_t buffer_size;
> - size_t limit_rate;
> + ngx_http_complex_value_t *limit_rate;
>
> size_t busy_buffers_size;
> size_t max_temp_file_size;
--
Sergey Kandaurov
More information about the nginx-devel
mailing list