Rate Limit with multiple subrequests

Umesh Sirsiwal usirsiwal at verivue.com
Tue May 3 03:14:46 MSD 2011

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 
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;


More information about the nginx-devel mailing list