Greetings openresty-en group,
I wanted to ask a question related more to nginx, than openresty per se.
One of the modules that is often employed ngx_http_limit_req_module
has the following precaution in the documentation:
If the zone storage is exhausted, the server will return the 503
(Service Temporarily Unavailable) error to all further requests.
It is interesting for me how is the
zone defined?
All the information needed for the rate limit?
If so, what does it contain - the data structure.
I have multiple users on the website served by openresty.
Would the zone size be exhausted if the unique IP count
would reach 8K unique IP's in some time frame?
How do I determine the lower bound of the zone?
For example do I need 5m or 20m?
Trying to look at ngx_http_limit_req_module.c I saw only configure
time error being thrown when the zone size is specified incorrectly:
if (size < (ssize_t) (8 * ngx_pagesize)) {
ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, "zone \"%V\" is too small", &value[i]);
}
(8 * ngx_pagesize), if I'm not mistaken is 8 * 4096 = 32768
I confirmed experimentally that the smallest size is indeed 32768 bytes = 32KB.
The function contains some interesting data:
static ngx_int_t ngx_http_limit_req_lookup(ngx_http_limit_req_limit_t *limit,
ngx_uint_t hash,
ngx_str_t *key,
ngx_uint_t *ep,
ngx_uint_t account)
node = ngx_slab_alloc_locked(ctx->shpool, size);
if (node == NULL) {
ngx_log_error(NGX_LOG_ALERT, ngx_cycle->log, 0,
"could not allocate node%s", ctx->shpool->log_ctx);
return NGX_ERROR;
}
I suppose this is the error thrown when zone size limit is reached?
Would really appreciate your help on this issue.