Rate-limiting across connections

Hello,

The limit_rate
http://nginx.org/en/docs/http/ngx_http_core_module.html#limit_rate
directive documentation clearly states that it is applied on a
per-request
basis.
How would one rate-limit a client over N connections?

  1. Count all N simultaneous connections from a single client
  2. Set a rate capped to maxRate/N for each n (connection)

The second part would be a simple recipe, applied through the use of
$limit_rate
http://nginx.org/en/docs/http/ngx_http_core_module.html#var_limit_rate
to
dynamically set it, provided the information of the first part was
available.

I see variables such as $connection
http://nginx.org/en/docs/http/ngx_http_core_module.html#var_connection
or
$connection_requests
http://nginx.org/en/docs/http/ngx_http_core_module.html#var_connection_requests,
but everything available is connection-based.
Would it be possible to have cross-connection information/states about
clients or is it a limitation due to how nginx operates?

B. R.

Hello!

On Fri, Nov 14, 2014 at 11:31 AM, B.R. [email protected] wrote:

The limit_rate directive documentation clearly states that it is applied on
a per-request basis.
How would one rate-limit a client over N connections?

It’s easy to do if you use ngx_lua module [1] together with the
$limit_rate builtin variable. You can not only limit on a per-server
basis (across worker processes) but also limit on a cluster-level
(across machines). It’s all up to you. Thanks to the flexibility of
Lua.

Regards,
-agentzh

[1] https://github.com/openresty/lua-nginx-module