# Subrequest in limit\_rate

**URL:** <https://www.ruby-forum.com/t/subrequest-in-limit-rate/198433>\
**Category:** NGINX\
**Created:** [November 1, 2010, 10:42am UTC](https://www.ruby-forum.com/t/subrequest-in-limit-rate/198433 "2010-11-01T10:42:37Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![okkezSS](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/o/85f322/32.png) [@okkezSS](https://www.ruby-forum.com/u/okkezSS)\
**Post date:** [November 1, 2010, 10:42am UTC](https://www.ruby-forum.com/t/subrequest-in-limit-rate/198433/1 "2010-11-01T10:42:37Z")

</div>

Hi all,

Does limit\_rate, which is in write filter module, work right when many  
subrequests exist?  
I meet a problem with limit\_rate for many subrequests. Here is the  
problem.

1. limit\_rate works like this:  
a) after sending data, it will set wev-\>delayed which disable data  
sending, and sleep for a while(add\_timer);  
b) when timedout, the wev handler will clear wev-\>delayed, to enable  
data sending.  
For example, the handler may like this;

src/http/ngx\_http\_upstream.c:ngx\_http\_upstream\_process\_downstream()

2361 if (wev-\>timedout) {

2363 if (wev-\>delayed) {

2367 wev-\>delayed = 0;

2389 }

2395 }

1. but 1 wev (write event) corresponds to 1 connection; while 1  
(downstream) connection may has many subrequests.  
so when wev timedout, wev gets the active request of the connection,  
like this:

src/http/ngx\_http\_request.c:ngx\_http\_request\_handler()

1724 c = ev-\>data;

1725 r = c-\>data;

1726

1733 if (ev-\>write) {

1734 r-\>write\_event\_handler®;

1737 } else {

1738 r-\>read\_event\_handler®;

1739 }

1. The problem is that: the active request of this connection maybe not  
the one who added the timer. which means that the active request of the  
connection changes before timedout. So its write\_event\_handler maybe not  
the one expected. For example, if the active request’s  
write\_event\_handler is happened to be ngx\_http\_request\_empty\_handler(),  
which is set in ngx\_http\_core\_content\_phase(), then the handler doesn’t  
clear the wev-\>delayed.So the data sending in write filter module will  
never be enabled again.

Is my analysis right? Does limit\_rate work right for many subrequests?

I hope I made myself understood.

Thanks,

Wu
