hello!<br>I have understood it.<br>But why the proxy cache module add the &quot;cache&quot; variable in ngx_http_request_t? It can also be done in the module context.<br><br>thanks.<br><br><div class="gmail_quote">2009/6/23 Maxim Dounin <span dir="ltr">&lt;<a href="mailto:mdounin@mdounin.ru">mdounin@mdounin.ru</a>&gt;</span><br>
<blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">Hello!<br>
<div class="im"><br>
On Tue, Jun 23, 2009 at 08:26:27PM +0800, Chieu wrote:<br>
<br>
&gt; the way of the module context can meet many requitments. But some others<br>
&gt; can&#39;t be implemented by the module way.<br>
&gt; for example,<br>
&gt; In the struct&quot;ngx_http_upstream_rr_peer_t&quot;, I want add a variable to count<br>
&gt; how many times I haved request this upstream.<br>
&gt; If there is a reserved pointer, I can use it point a struct I have defined<br>
&gt; in my module. But now,I must modify the source code and when I want to<br>
&gt; replace with a new version nginx, I have to re-modifiy the code.<br>
<br>
</div>As I said, there is no need to modify nginx code.  Feel free to<br>
wrap balancer module, allocate additional memory in<br>
peer.init_upstream() handler and increment numbers on wrapped<br>
peer.get() handler.<br>
<br>
For simple wrapper around take a look at<br>
ngx_http_upstream_ip_hash_module.  For a bit more complex wrapper<br>
see ngx_http_upstream_keepalive_module here:<br>
<br>
<a href="http://mdounin.ru/hg/ngx_http_upstream_keepalive/file/tip/ngx_http_upstream_keepalive_module.c" target="_blank">http://mdounin.ru/hg/ngx_http_upstream_keepalive/file/tip/ngx_http_upstream_keepalive_module.c</a><br>

<div class="im"><br>
&gt; ngx_http_request_t can expand datas with the module context, but other data<br>
&gt; struct can&#39;t use module conext?<br>
<br>
</div>Basically in nginx you either work with request (and here you have<br>
module contexts to store your data) or with configuration (and<br>
module configs to store your data).  Most things could be easily<br>
done by pure modules without patching nginx itself, and there are<br>
lots of examples in nginx source code how to do it.<br>
<font color="#888888"><br>
Maxim Dounin<br>
</font><div><div></div><div class="h5"><br>
&gt;<br>
&gt; thank you<br>
&gt;<br>
&gt; 2009/6/23 Maxim Dounin &lt;<a href="mailto:mdounin@mdounin.ru">mdounin@mdounin.ru</a>&gt;<br>
&gt;<br>
&gt; &gt; Hello!<br>
&gt; &gt;<br>
&gt; &gt; On Tue, Jun 23, 2009 at 06:05:19PM +0800, Chieu wrote:<br>
&gt; &gt;<br>
&gt; &gt; &gt; hi, developers<br>
&gt; &gt; &gt; Because of the modularity of nginx, I can extend the new function easily.<br>
&gt; &gt; &gt; But there are some requirements which need to modify the original source<br>
&gt; &gt; &gt; code.<br>
&gt; &gt; &gt; For example:<br>
&gt; &gt; &gt; I want to add a variable which records the count of requests sent to each<br>
&gt; &gt; &gt; upstream. And I must add a variable into the struct<br>
&gt; &gt; &gt; &quot;ngx_http_upstream_rr_peer_t&quot;, when round robin get the upstream ,the<br>
&gt; &gt; &gt; variable++ . This way, I shoud modify the source code of the upstream<br>
&gt; &gt; &gt; module.<br>
&gt; &gt;<br>
&gt; &gt; You may easily write transparent upstream balancer module that<br>
&gt; &gt; does this (just counts and passes everything to the real<br>
&gt; &gt; balancer).  Without nginx code modifications.  It&#39;s not really<br>
&gt; &gt; efficient due to extra function calls, but it will work.<br>
&gt; &gt;<br>
&gt; &gt; &gt; I think if the struct &quot;ngx_http_upstream_rr_peer_t&quot; have a reserved<br>
&gt; &gt; &gt; pointer(void *), which reserved for others developing new modules.<br>
&gt; &gt; &gt; Totally, I think the modularity of nginx just resolved the expansibility<br>
&gt; &gt; of<br>
&gt; &gt; &gt; function. But if the I want to expand some import data like the struct<br>
&gt; &gt; &gt; &quot;ngx_http_request_t&quot;, I must modify the original source code. And if<br>
&gt; &gt;  some<br>
&gt; &gt; &gt; important struct adds a reserved pointer, I think the data of nginx will<br>
&gt; &gt; be<br>
&gt; &gt; &gt; easily be extend.<br>
&gt; &gt;<br>
&gt; &gt; I don&#39;t really understand the question, but for any data you may<br>
&gt; &gt; use either your module context (every module has pointer to it&#39;s<br>
&gt; &gt; context stored in ngx_http_request_t) or variables (if you need<br>
&gt; &gt; something that survives internal redirects).<br>
&gt; &gt;<br>
&gt; &gt; Maxim Dounin<br>
&gt; &gt;<br>
&gt; &gt;<br>
<br>
</div></div></blockquote></div><br>