Rate Limit with multiple subrequests

Maxim Dounin mdounin at mdounin.ru
Tue May 3 16:35:40 MSD 2011


Hello!

On Mon, May 02, 2011 at 07:14:46PM -0400, Umesh Sirsiwal wrote:

> ngx_http_write_filter module has the following code for rate limit.
>   if (r->limit_rate) {
>         limit = r->limit_rate * (ngx_time() - r->main->start_sec + 1)
>                 - (c->sent - clcf->limit_rate_after);
> 
> Looking at the code, it seems the start_sec is overwritten for each
> subrequest.
> ngx_int_t
> ngx_http_subrequest(ngx_http_request_t *r,
>     ngx_str_t *uri, ngx_str_t *args, ngx_http_request_t **psr,
>     ngx_http_post_subrequest_t *ps, ngx_uint_t flags)
> 
>     tp = ngx_timeofday();
>     r->start_sec = tp->sec;
>     r->start_msec = tp->msec;
> 
> The implication is that the rate limit is off when we have multiple
> subrequests. Shouldn't the above be:
>     sr->start_sec = tp->sec;
>     sr->start_msec = tp->msec;

Yes, thank you for your report.  Incorrect setting of 
r->start_sec/msec was already discussed in russian mailing 
list[1], fix is in 1.0.1.

[1] http://nginx.org/pipermail/nginx-ru/2011-April/040677.html

Maxim Dounin



More information about the nginx-devel mailing list