<div dir="ltr"><span class="gmail_msg" style="font-size:13px;color:rgb(34,34,34);font-family:arial,helvetica,sans-serif">Greetings group, </span><div class="gmail_msg" style="color:rgb(33,33,33);font-family:"helvetica neue",helvetica,arial,sans-serif;font-size:13px"><font color="#222222" face="arial, helvetica, sans-serif" class="gmail_msg">I have posted the same questions elsewhere, hope its not against the policy.<br class="gmail_msg"></font><div class="gmail_msg" style="margin:0px;padding:0px;border:0px;color:rgb(34,34,34);font-family:arial,helvetica,sans-serif"><br class="gmail_msg"></div><div class="gmail_msg" style="margin:0px;padding:0px;border:0px;color:rgb(34,34,34);font-family:arial,helvetica,sans-serif">One of the modules that is often employed<span class="inbox-inbox-m_856974760234787411inbox-inbox-Apple-converted-space gmail_msg"> </span><b class="gmail_msg"><i class="gmail_msg">ngx_http_limit_req_module</i></b><br></div><div class="gmail_msg" style="margin:0px;padding:0px;border:0px;color:rgb(34,34,34);font-family:arial,helvetica,sans-serif">has the following precaution in the documentation:</div><div class="gmail_msg" style="margin:0px;padding:0px;border:0px;color:rgb(34,34,34);font-family:arial,helvetica,sans-serif"> </div><blockquote class="gmail_msg" style="margin:0px 0px 0px 40px;border:none;padding:0px;color:rgb(34,34,34);font-family:arial,helvetica,sans-serif"><font size="1" class="gmail_msg" style="margin:0px;padding:0px;border:0px"><b class="gmail_msg">If the </b></font><b class="gmail_msg"><font size="1" class="gmail_msg" style="margin:0px;padding:0px;border:0px">zone storage is exhausted, the server will return the </font><font size="1" class="gmail_msg" style="margin:0px;padding:0px;border:0px">503</font></b> </blockquote><blockquote class="gmail_msg" style="margin:0px 0px 0px 40px;border:none;padding:0px;color:rgb(34,34,34);font-family:arial,helvetica,sans-serif"><b class="gmail_msg"><font size="1" class="gmail_msg" style="margin:0px;padding:0px;border:0px">(Service Temporarily Unavailable) error to all further requests.</font></b></blockquote><div class="gmail_msg" style="color:rgb(33,33,33);font-family:"helvetica neue",helvetica,arial,sans-serif;font-size:13px"><br></div><br class="gmail_msg" style="color:rgb(34,34,34);font-family:arial,helvetica,sans-serif"><span class="gmail_msg" style="color:rgb(34,34,34);font-family:arial,helvetica,sans-serif"><b>Questions:</b></span></div><div class="gmail_msg" style="color:rgb(33,33,33);font-family:"helvetica neue",helvetica,arial,sans-serif;font-size:13px"><span class="gmail_msg" style="color:rgb(34,34,34);font-family:arial,helvetica,sans-serif"><b>----------------------------------------------------------------------</b></span></div><div class="gmail_msg" style="color:rgb(33,33,33);font-family:"helvetica neue",helvetica,arial,sans-serif;font-size:13px"><span class="gmail_msg" style="color:rgb(34,34,34);font-family:arial,helvetica,sans-serif">1. It is interesting for me how is the<span class="inbox-inbox-m_856974760234787411inbox-inbox-Apple-converted-space gmail_msg"> </span></span><b class="gmail_msg" style="color:rgb(34,34,34);font-family:arial,helvetica,sans-serif"><i class="gmail_msg">zone<span class="inbox-inbox-m_856974760234787411inbox-inbox-Apple-converted-space gmail_msg"> </span></i></b><span class="gmail_msg" style="color:rgb(34,34,34);font-family:arial,helvetica,sans-serif">defined?</span></div><div class="gmail_msg"><font color="#222222" face="arial, helvetica, sans-serif">I know that the underlining data structure is a red-black tree.</font></div><div class="gmail_msg" style="font-size:13px"><font color="#222222" face="arial, helvetica, sans-serif">But what comprises the entire zone record?<br></font><div class="gmail_msg" style="color:rgb(34,34,34);font-family:arial,helvetica,sans-serif;margin:0px;padding:0px;border:0px">All the information needed for the rate limit?</div><div class="gmail_msg" style="color:rgb(34,34,34);font-family:arial,helvetica,sans-serif;margin:0px;padding:0px;border:0px"><div class="gmail_msg" style="margin:0px;padding:0px;border:0px"><br class="gmail_msg"></div><div class="gmail_msg" style="margin:0px;padding:0px;border:0px">2. I have multiple users on the website served by nginx.</div><div class="gmail_msg" style="margin:0px;padding:0px;border:0px">And the zone size is 1m. How do I determine the lower </div><div class="gmail_msg" style="margin:0px;padding:0px;border:0px">bound of the zone for a given unique ip count?</div><div class="gmail_msg" style="margin:0px;padding:0px;border:0px"><br class="gmail_msg"></div><div class="gmail_msg" style="margin:0px;padding:0px;border:0px">3. After what time is the zone memory released?</div><div class="gmail_msg" style="margin:0px;padding:0px;border:0px">If I have: rate=1r/m; does that mean that all the records will</div><div class="gmail_msg" style="margin:0px;padding:0px;border:0px">have to be kept for 1 minute to do the accounting, then cleared</div><div class="gmail_msg" style="margin:0px;padding:0px;border:0px">so that memory in zone could be renewed?</div><div class="gmail_msg" style="margin:0px;padding:0px;border:0px"><br></div><div class="gmail_msg" style="margin:0px;padding:0px;border:0px"><br></div><div class="gmail_msg" style="margin:0px;padding:0px;border:0px"><b>Some code considerations:</b></div><div class="gmail_msg" style="margin:0px;padding:0px;border:0px"><div class="gmail_msg" style="color:rgb(33,33,33);font-family:"helvetica neue",helvetica,arial,sans-serif"><span class="gmail_msg" style="color:rgb(34,34,34);font-family:arial,helvetica,sans-serif"><b>----------------------------------------------------------------------</b></span></div></div><div class="gmail_msg" style="margin:0px;padding:0px;border:0px">Trying to look at <i class="gmail_msg" style="font-weight:bold">ngx_http_limit_req_module.c<span class="inbox-inbox-m_856974760234787411inbox-inbox-Apple-converted-space gmail_msg"> </span></i>I saw only configure</div><div class="gmail_msg" style="margin:0px;padding:0px;border:0px">time error being thrown when the zone size is specified incorrectly:</div><div class="gmail_msg" style="margin:0px;padding:0px;border:0px"><br class="gmail_msg"></div><div class="gmail_msg" style="margin:0px;padding:0px;border:0px"><i class="gmail_msg">if (size < (ssize_t) (8 * ngx_pagesize)) { </i></div></div><blockquote class="gmail_msg" style="color:rgb(34,34,34);font-family:arial,helvetica,sans-serif;margin:0px 0px 0px 40px;border:none;padding:0px"><div class="gmail_msg" style="margin:0px;padding:0px;border:0px"><div class="gmail_msg" style="margin:0px;padding:0px;border:0px"><i class="gmail_msg">ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, "zone \"%V\" is too small", &value[i]); </i></div></div></blockquote><blockquote class="gmail_msg" style="color:rgb(34,34,34);font-family:arial,helvetica,sans-serif;margin:0px 0px 0px 40px;border:none;padding:0px"><div class="gmail_msg" style="margin:0px;padding:0px;border:0px"><div class="gmail_msg" style="margin:0px;padding:0px;border:0px"><i class="gmail_msg">return NGX_CONF_ERROR;</i></div></div></blockquote><div class="gmail_msg" style="color:rgb(34,34,34);font-family:arial,helvetica,sans-serif;margin:0px;padding:0px;border:0px"><i class="gmail_msg"> }</i></div><div class="gmail_msg" style="color:rgb(34,34,34);font-family:arial,helvetica,sans-serif;margin:0px;padding:0px;border:0px"><pre class="gmail_msg" style="margin-top:0px;margin-bottom:0px;padding:0px;border:0px;color:rgb(0,0,0)"><br></pre>(8 * ngx_pagesize), if I'm not mistaken is 8 * 4096 = 32768</div><div class="gmail_msg" style="color:rgb(34,34,34);font-family:arial,helvetica,sans-serif;margin:0px;padding:0px;border:0px">I confirmed experimentally that the smallest size is indeed 32768 bytes = 32KB.</div><div class="gmail_msg" style="color:rgb(34,34,34);font-family:arial,helvetica,sans-serif;margin:0px;padding:0px;border:0px"><br class="gmail_msg"></div><div class="gmail_msg" style="color:rgb(34,34,34);font-family:arial,helvetica,sans-serif;margin:0px;padding:0px;border:0px"><b>----------------------------------------------------------------------</b> <br></div><div class="gmail_msg" style="color:rgb(34,34,34);font-family:arial,helvetica,sans-serif;margin:0px;padding:0px;border:0px"><br></div><div class="gmail_msg" style="color:rgb(34,34,34);font-family:arial,helvetica,sans-serif;margin:0px;padding:0px;border:0px">The function contains some interesting data:<span class="inbox-inbox-m_856974760234787411inbox-inbox-Apple-converted-space gmail_msg"> </span><br class="gmail_msg"></div><blockquote class="gmail_msg" style="color:rgb(34,34,34);font-family:arial,helvetica,sans-serif;margin:0px 0px 0px 40px;border:none;padding:0px"><div class="gmail_msg" style="margin:0px;padding:0px;border:0px"><i class="gmail_msg">static ngx_int_t ngx_http_limit_req_lookup(ngx_http_limit_req_limit_t *limit, </i></div></blockquote><blockquote class="gmail_msg" style="color:rgb(34,34,34);font-family:arial,helvetica,sans-serif;margin:0px 0px 0px 40px;border:none;padding:0px"><blockquote class="gmail_msg" style="margin:0px 0px 0px 40px;border:none;padding:0px"><blockquote class="gmail_msg" style="margin:0px 0px 0px 40px;border:none;padding:0px"><blockquote class="gmail_msg" style="margin:0px 0px 0px 40px;border:none;padding:0px"><blockquote class="gmail_msg" style="margin:0px 0px 0px 40px;border:none;padding:0px"><blockquote class="gmail_msg" style="margin:0px 0px 0px 40px;border:none;padding:0px"><blockquote class="gmail_msg" style="margin:0px 0px 0px 40px;border:none;padding:0px"><blockquote class="gmail_msg" style="margin:0px 0px 0px 40px;border:none;padding:0px"><blockquote class="gmail_msg" style="margin:0px 0px 0px 40px;border:none;padding:0px"><div class="gmail_msg" style="margin:0px;padding:0px;border:0px"><i class="gmail_msg">ngx_uint_t hash, </i></div></blockquote></blockquote></blockquote></blockquote></blockquote></blockquote></blockquote></blockquote></blockquote><blockquote class="gmail_msg" style="color:rgb(34,34,34);font-family:arial,helvetica,sans-serif;margin:0px 0px 0px 40px;border:none;padding:0px"><blockquote class="gmail_msg" style="margin:0px 0px 0px 40px;border:none;padding:0px"><blockquote class="gmail_msg" style="margin:0px 0px 0px 40px;border:none;padding:0px"><blockquote class="gmail_msg" style="margin:0px 0px 0px 40px;border:none;padding:0px"><blockquote class="gmail_msg" style="margin:0px 0px 0px 40px;border:none;padding:0px"><blockquote class="gmail_msg" style="margin:0px 0px 0px 40px;border:none;padding:0px"><blockquote class="gmail_msg" style="margin:0px 0px 0px 40px;border:none;padding:0px"><blockquote class="gmail_msg" style="margin:0px 0px 0px 40px;border:none;padding:0px"><blockquote class="gmail_msg" style="margin:0px 0px 0px 40px;border:none;padding:0px"><div class="gmail_msg" style="margin:0px;padding:0px;border:0px"><i class="gmail_msg">ngx_str_t *key, </i></div></blockquote></blockquote></blockquote></blockquote></blockquote></blockquote></blockquote></blockquote></blockquote><blockquote class="gmail_msg" style="color:rgb(34,34,34);font-family:arial,helvetica,sans-serif;margin:0px 0px 0px 40px;border:none;padding:0px"><blockquote class="gmail_msg" style="margin:0px 0px 0px 40px;border:none;padding:0px"><blockquote class="gmail_msg" style="margin:0px 0px 0px 40px;border:none;padding:0px"><blockquote class="gmail_msg" style="margin:0px 0px 0px 40px;border:none;padding:0px"><blockquote class="gmail_msg" style="margin:0px 0px 0px 40px;border:none;padding:0px"><blockquote class="gmail_msg" style="margin:0px 0px 0px 40px;border:none;padding:0px"><blockquote class="gmail_msg" style="margin:0px 0px 0px 40px;border:none;padding:0px"><blockquote class="gmail_msg" style="margin:0px 0px 0px 40px;border:none;padding:0px"><blockquote class="gmail_msg" style="margin:0px 0px 0px 40px;border:none;padding:0px"><div class="gmail_msg" style="margin:0px;padding:0px;border:0px"><i class="gmail_msg">ngx_uint_t *ep, </i></div></blockquote></blockquote></blockquote></blockquote></blockquote></blockquote></blockquote></blockquote></blockquote><blockquote class="gmail_msg" style="color:rgb(34,34,34);font-family:arial,helvetica,sans-serif;margin:0px 0px 0px 40px;border:none;padding:0px"><blockquote class="gmail_msg" style="margin:0px 0px 0px 40px;border:none;padding:0px"><blockquote class="gmail_msg" style="margin:0px 0px 0px 40px;border:none;padding:0px"><blockquote class="gmail_msg" style="margin:0px 0px 0px 40px;border:none;padding:0px"><blockquote class="gmail_msg" style="margin:0px 0px 0px 40px;border:none;padding:0px"><blockquote class="gmail_msg" style="margin:0px 0px 0px 40px;border:none;padding:0px"><blockquote class="gmail_msg" style="margin:0px 0px 0px 40px;border:none;padding:0px"><blockquote class="gmail_msg" style="margin:0px 0px 0px 40px;border:none;padding:0px"><blockquote class="gmail_msg" style="margin:0px 0px 0px 40px;border:none;padding:0px"><div class="gmail_msg" style="margin:0px;padding:0px;border:0px"><i class="gmail_msg">ngx_uint_t account)</i></div></blockquote></blockquote></blockquote></blockquote></blockquote></blockquote></blockquote></blockquote></blockquote><div class="gmail_msg" style="color:rgb(34,34,34);font-family:arial,helvetica,sans-serif;margin:0px;padding:0px;border:0px"><br class="gmail_msg"></div><div class="gmail_msg" style="color:rgb(34,34,34);font-family:arial,helvetica,sans-serif;margin:0px;padding:0px;border:0px"><br class="gmail_msg"></div><div class="gmail_msg" style="color:rgb(34,34,34);font-family:arial,helvetica,sans-serif;margin:0px;padding:0px;border:0px"><i class="gmail_msg"> node = ngx_slab_alloc_locked(ctx->shpool, size);</i></div><div class="gmail_msg" style="color:rgb(34,34,34);font-family:arial,helvetica,sans-serif;margin:0px;padding:0px;border:0px"><i class="gmail_msg"> if (node == NULL) {</i></div><div class="gmail_msg" style="color:rgb(34,34,34);font-family:arial,helvetica,sans-serif;margin:0px;padding:0px;border:0px"><i class="gmail_msg"> ngx_log_error(NGX_LOG_ALERT, ngx_cycle->log, 0,</i></div><div class="gmail_msg" style="color:rgb(34,34,34);font-family:arial,helvetica,sans-serif;margin:0px;padding:0px;border:0px"><i class="gmail_msg"> "could not allocate node%s", ctx->shpool->log_ctx);</i></div><div class="gmail_msg" style="color:rgb(34,34,34);font-family:arial,helvetica,sans-serif;margin:0px;padding:0px;border:0px"><i class="gmail_msg"> return NGX_ERROR;</i></div><div class="gmail_msg" style="color:rgb(34,34,34);font-family:arial,helvetica,sans-serif;margin:0px;padding:0px;border:0px"><i class="gmail_msg"> } </i></div><div class="gmail_msg" style="color:rgb(34,34,34);font-family:arial,helvetica,sans-serif;margin:0px;padding:0px;border:0px"><i class="gmail_msg"><br class="gmail_msg"></i></div><div class="gmail_msg" style="color:rgb(34,34,34);font-family:arial,helvetica,sans-serif;margin:0px;padding:0px;border:0px">I suppose this is the error thrown when zone size limit is reached?</div><div class="gmail_msg" style="color:rgb(34,34,34);font-family:arial,helvetica,sans-serif;margin:0px;padding:0px;border:0px">Would really appreciate your help on this issue.</div><div class="gmail_msg" style="color:rgb(34,34,34);font-family:arial,helvetica,sans-serif;margin:0px;padding:0px;border:0px"><br></div><div class="gmail_msg" style="color:rgb(34,34,34);font-family:arial,helvetica,sans-serif;margin:0px;padding:0px;border:0px"><b>----------------------------------------------------------------------</b> <br></div><div class="gmail_msg" style="color:rgb(34,34,34);font-family:arial,helvetica,sans-serif;margin:0px;padding:0px;border:0px"><br></div><div class="gmail_msg" style="color:rgb(34,34,34);font-family:arial,helvetica,sans-serif;margin:0px;padding:0px;border:0px">Also, I calculated the size of each node of the rb tree and </div><div class="gmail_msg" style="color:rgb(34,34,34);font-family:arial,helvetica,sans-serif;margin:0px;padding:0px;border:0px">it seems to only comprise 44 bytes. </div><div class="gmail_msg" style="color:rgb(34,34,34);font-family:arial,helvetica,sans-serif;margin:0px;padding:0px;border:0px"><pre class="inbox-inbox-m_7330198597117354350filecontent gmail_msg" style="color:rgb(0,0,0)"><a class="inbox-inbox-m_7330198597117354350fline gmail_msg" style="background-color:silver">0022</a> <span class="inbox-inbox-m_7330198597117354350reserved gmail_msg" style="color:green;font-weight:bold">struct</span> <a class="inbox-inbox-m_7330198597117354350fid gmail_msg" href="http://lxr.nginx.org/ident?_i=ngx_rbtree_node_s" target="_blank" style="color:rgb(0,122,204)">ngx_rbtree_node_s</a> {
<a class="inbox-inbox-m_7330198597117354350fline gmail_msg" style="background-color:silver">0023</a> <a class="inbox-inbox-m_7330198597117354350fid gmail_msg" href="http://lxr.nginx.org/ident?_i=ngx_rbtree_key_t" target="_blank" style="color:rgb(0,122,204)">ngx_rbtree_key_t</a> <a class="inbox-inbox-m_7330198597117354350fid gmail_msg" href="http://lxr.nginx.org/ident?_i=key" target="_blank" style="color:rgb(0,122,204)">key</a>; ===> 4 bytes
<a class="inbox-inbox-m_7330198597117354350fline gmail_msg" style="background-color:silver">0024</a> <a class="inbox-inbox-m_7330198597117354350fid gmail_msg" href="http://lxr.nginx.org/ident?_i=ngx_rbtree_node_t" target="_blank" style="color:rgb(0,122,204)">ngx_rbtree_node_t</a> *<a class="inbox-inbox-m_7330198597117354350fid gmail_msg" href="http://lxr.nginx.org/ident?_i=left" target="_blank" style="color:rgb(0,122,204)">left</a>; ===> 8 bytes (pointer size on 64bit)
<a class="inbox-inbox-m_7330198597117354350fline gmail_msg" style="background-color:silver">0025</a> <a class="inbox-inbox-m_7330198597117354350fid gmail_msg" href="http://lxr.nginx.org/ident?_i=ngx_rbtree_node_t" target="_blank" style="color:rgb(0,122,204)">ngx_rbtree_node_t</a> *<a class="inbox-inbox-m_7330198597117354350fid gmail_msg" href="http://lxr.nginx.org/ident?_i=right" target="_blank" style="color:rgb(0,122,204)">right</a>; ===> 8
<a class="inbox-inbox-m_7330198597117354350fline gmail_msg" style="background-color:silver">0026</a> <a class="inbox-inbox-m_7330198597117354350fid gmail_msg" href="http://lxr.nginx.org/ident?_i=ngx_rbtree_node_t" target="_blank" style="color:rgb(0,122,204)">ngx_rbtree_node_t</a> *<a class="inbox-inbox-m_7330198597117354350fid gmail_msg" href="http://lxr.nginx.org/ident?_i=parent" target="_blank" style="color:rgb(0,122,204)">parent</a>;===> 8
<a class="inbox-inbox-m_7330198597117354350fline gmail_msg" style="background-color:silver">0027</a> u_char <a class="inbox-inbox-m_7330198597117354350fid gmail_msg" href="http://lxr.nginx.org/ident?_i=color" target="_blank" style="color:rgb(0,122,204)">color</a>; ===> 8
<a class="inbox-inbox-m_7330198597117354350fline gmail_msg" style="background-color:silver">0028</a> u_char <a class="inbox-inbox-m_7330198597117354350fid gmail_msg" href="http://lxr.nginx.org/ident?_i=data" target="_blank" style="color:rgb(0,122,204)">data</a>; ===> 8
<a class="inbox-inbox-m_7330198597117354350fline gmail_msg" style="background-color:silver">0029</a> };</pre></div></div></div>