<DIV>Hi all,</DIV>
<DIV>&nbsp;</DIV>
<DIV><FONT size="3">Does limit_rate, which is in write filter module, work right when many subrequests exist?</FONT></DIV>
<DIV><FONT size="3">I meet a problem with limit_rate for many subrequests. Here is the problem.</FONT></DIV>
<DIV><FONT size="3">&nbsp;</FONT></DIV>
<DIV><FONT size="3">1. limit_rate works like this:</FONT></DIV>
<DIV><FONT size="3">a) after sending data, it will set wev-&gt;delayed which disable data sending,&nbsp;and sleep for a while(add_timer);</FONT></DIV>
<DIV><FONT size="3">b) when timedout, the wev handler will clear wev-&gt;delayed, to enable data sending. </FONT></DIV>
<DIV><FONT size="3">For example, the handler may&nbsp;like this;</FONT></DIV>
<DIV>
<P style="MARGIN: 0cm 0cm 0pt" class="MsoNormal"><SPAN lang="EN-US"><o:p><FONT size="3" face="Calibri"></FONT></o:p></SPAN></P>
<P style="MARGIN: 0cm 0cm 0pt" class="MsoNormal"><SPAN lang="EN-US"><FONT face="Calibri"><STRONG><FONT size="3">src/http/ngx_http_upstream.c:<SPAN lang="EN-US"><FONT face="Calibri">ngx_http_upstream_process_downstream()</FONT></SPAN><o:p></o:p></FONT></STRONG></FONT></SPAN></P>
<P style="MARGIN: 0cm 0cm 0pt" class="MsoNormal"><SPAN lang="EN-US"><FONT face="Calibri"><FONT size="3"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp; </SPAN>2361<SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>if (wev-&gt;timedout) {</FONT></FONT></SPAN></P>
<P style="MARGIN: 0cm 0cm 0pt" class="MsoNormal"><SPAN lang="EN-US"><FONT face="Calibri"><FONT size="3"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp; </SPAN>2363<SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>if (wev-&gt;delayed) {</FONT></FONT></SPAN></P>
<P style="MARGIN: 0cm 0cm 0pt" class="MsoNormal"><SPAN lang="EN-US"><FONT face="Calibri"><FONT size="3"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp; </SPAN>2367<SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>wev-&gt;delayed = 0;</FONT></FONT></SPAN></P>
<P style="MARGIN: 0cm 0cm 0pt" class="MsoNormal"><SPAN lang="EN-US"><FONT face="Calibri"><FONT size="3"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp; </SPAN>2389<SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>}</FONT></FONT></SPAN></P>
<P style="MARGIN: 0cm 0cm 0pt" class="MsoNormal"><SPAN lang="EN-US"><FONT face="Calibri"><FONT size="3"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp; </SPAN>2395<SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>}</FONT></FONT></SPAN></P></DIV>
<DIV><FONT size="3">&nbsp;</FONT></DIV>
<DIV><FONT size="3">2. but 1 wev (write event) corresponds to 1 connection; while 1 (downstream) connection may has&nbsp;many subrequests.</FONT></DIV>
<DIV><FONT size="3">so when wev timedout, wev gets the active request of the connection, like this:</FONT></DIV>
<DIV><FONT size="3">&nbsp;</FONT></DIV>
<DIV>
<P style="MARGIN: 0cm 0cm 0pt" class="MsoNormal"><B style="mso-bidi-font-weight: normal"><SPAN lang="EN-US"><FONT face="Calibri"><FONT size="3">src/http/ngx_http_request.c:ngx_http_request_handler()<o:p></o:p></FONT></FONT></SPAN></B></P>
<P style="MARGIN: 0cm 0cm 0pt" class="MsoNormal"><SPAN lang="EN-US"><FONT face="Calibri"><FONT size="3"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp; </SPAN>1724<SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>c = ev-&gt;data;</FONT></FONT></SPAN></P>
<P style="MARGIN: 0cm 0cm 0pt" class="MsoNormal"><SPAN lang="EN-US"><FONT face="Calibri"><FONT size="3"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp; </SPAN>1725<SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>r = c-&gt;data;</FONT></FONT></SPAN></P>
<P style="MARGIN: 0cm 0cm 0pt" class="MsoNormal"><SPAN lang="EN-US"><FONT face="Calibri"><FONT size="3"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp; </SPAN>1726</FONT></FONT></SPAN></P>
<P style="MARGIN: 0cm 0cm 0pt" class="MsoNormal"><SPAN lang="EN-US"><FONT face="Calibri"><FONT size="3"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp; </SPAN>1733<SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>if (ev-&gt;write) {</FONT></FONT></SPAN></P>
<P style="MARGIN: 0cm 0cm 0pt" class="MsoNormal"><SPAN lang="EN-US"><FONT face="Calibri"><FONT size="3"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp; </SPAN>1734<SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>r-&gt;write_event_handler(r);</FONT></FONT></SPAN></P>
<P style="MARGIN: 0cm 0cm 0pt" class="MsoNormal"><SPAN lang="EN-US"><FONT face="Calibri"><FONT size="3"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp; </SPAN>1737<SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>} else {</FONT></FONT></SPAN></P>
<P style="MARGIN: 0cm 0cm 0pt" class="MsoNormal"><SPAN lang="EN-US"><FONT face="Calibri"><FONT size="3"><SPAN style="mso-spacerun: yes">&nbsp; </SPAN><SPAN style="mso-spacerun: yes">&nbsp;</SPAN>1738<SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>r-&gt;read_event_handler(r);</FONT></FONT></SPAN></P>
<P style="MARGIN: 0cm 0cm 0pt" class="MsoNormal"><SPAN lang="EN-US"><FONT face="Calibri"><FONT size="3"><SPAN style="mso-spacerun: yes">&nbsp;&nbsp; </SPAN>1739<SPAN style="mso-spacerun: yes">&nbsp;&nbsp;&nbsp;&nbsp; </SPAN>}</FONT></FONT></SPAN></P>
<P style="MARGIN: 0cm 0cm 0pt" class="MsoNormal"><SPAN lang="EN-US"><FONT face="Calibri"></FONT></SPAN><FONT size="3">&nbsp;</FONT></P>
<P style="MARGIN: 0cm 0cm 0pt" class="MsoNormal"><FONT size="3"></FONT>&nbsp;</P>
<P style="MARGIN: 0cm 0cm 0pt" class="MsoNormal"><FONT size="3">3. 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-&gt;delayed. <STRONG>So the data sending in write filter module will never be enabled again</STRONG>.</FONT></P>
<P style="MARGIN: 0cm 0cm 0pt" class="MsoNormal"><FONT size="3"></FONT>&nbsp;</P>
<P style="MARGIN: 0cm 0cm 0pt" class="MsoNormal"><FONT size="3">Is my analysis right? Does limit_rate work right for many subrequests?</FONT></P>
<P style="MARGIN: 0cm 0cm 0pt" class="MsoNormal">&nbsp;</P>
<P style="MARGIN: 0cm 0cm 0pt" class="MsoNormal"><FONT size="3">I hope I made myself understood.</FONT></P>
<P style="MARGIN: 0cm 0cm 0pt" class="MsoNormal"><FONT size="3">Thanks,</FONT></P>
<P style="MARGIN: 0cm 0cm 0pt" class="MsoNormal"><FONT size="3">Wu<BR></FONT></P></DIV><br><br><span title="neteasefooter"><span id="netease_mail_footer"></span></span>