<div dir="ltr">Hello!<div><br></div><div>Thanks for the response.</div><div><br></div><div>> The cache validity time as obtained from cached responses is used<br>> while processing 304 responses during cache revalidation, so the<br>> suggested change looks wrong to me.<br></div><div><br></div><div>When processing 304 responses during cache revalidation, ngx_http_upstream_process_accel_expires is called twice.</div><div><br></div><div>1st time, in "ngx_http_upstream_process_header" function.</div><div>src/http/ngx_http_upstream.c: 2387 rc = u->process_header(r);<br></div><div>#
process_header =
ngx_http_upstream_process_accel_expires
</div><div><br></div><div>This calculates the exact valid_sec value by x-accel-expires of upstream's response, It doesn't use a value of the cache data.</div><div>Also, the r->cached is 0 at this time.</div><div><br></div><div>2nd time, in "ngx_http_upstream_process_header" -> "ngx_http_upstream_test_next" -> "ngx_http_upstream_cache_send" function.</div><div>src/http/ngx_http_upstream.c: 2423 if (ngx_http_upstream_test_next(r, u) == NGX_OK) -></div><div>src/http/ngx_http_upstream.c: 2535 rc = ngx_http_upstream_cache_send(r, u); -></div><div>
src/http/ngx_http_upstream.c: 1073 rc = u->process_header(r);<br></div><div><br></div><div>This calculates unnecessary valid_sec value by x-accel-expires of the cache data.<br></div><div>Also, this calculation can skip by this patch since the r->cached is 1 at this time. <br></div><div><br></div><div>Please look into ngx_http_upstream_test_next.</div><div>It keeps the valid_sec value of 1st time into "valid" variable at "2523 valid = r->cache->valid_sec;".</div><div>After that, it "calls ngx_http_upstream_cache_send", then updates cache data with the "valid" variable at "2560 r->cache->valid_sec = valid;".</div><div><br></div><div>--</div><div>TAKADA Sokichi</div><div><br></div><div><br></div><div><br></div><div><br></div><div><br></div><div><br></div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Mon, Jun 22, 2020 at 6:11 AM Maxim Dounin <<a href="mailto:mdounin@mdounin.ru">mdounin@mdounin.ru</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">Hello!<br>
<br>
On Fri, Jun 19, 2020 at 09:41:37AM +0900, TAKADA Sokichi wrote:<br>
<br>
> # HG changeset patch<br>
> # User TAKADA Sokichi <<a href="mailto:takada@jocdn.co.jp" target="_blank">takada@jocdn.co.jp</a>><br>
> # Date 1592383243 -32400<br>
> # Wed Jun 17 17:40:43 2020 +0900<br>
> # Node ID d5bbe3ad1f1491125485786aacc5d219c81801d1<br>
> # Parent 8cf31489b479b689b7ff4a9601ce24c914d0394c<br>
> skip apply "ngx_http_upstream_process_accel_expires" when a request responeded by cache<br>
> <br>
> "ngx_http_upstream_process_accel_expires" is calculate and set valid_date value when a request respond by a cache, even though it will never use in the response.<br>
> This patch to skip unnecessary process.<br>
> <br>
> On the other hands, this has good side effect to can get TRUE valid_date value of the cache file in "header filter" and "log" hook handler.<br>
> i.e. I would like to get the TRUE valid_date of cache in header_filter_by_lua or log_by_lua handlers.<br>
> <br>
> diff -r 8cf31489b479 -r d5bbe3ad1f14 src/http/ngx_http_upstream.c<br>
> --- a/src/http/ngx_http_upstream.c Mon Jun 15 17:35:26 2020 -0400<br>
> +++ b/src/http/ngx_http_upstream.c Wed Jun 17 17:40:43 2020 +0900<br>
> @@ -4776,6 +4776,10 @@<br>
> return NGX_OK;<br>
> }<br>
> <br>
> + if (r->cached == 1) {<br>
> + return NGX_OK;<br>
> + }<br>
> +<br>
> len = h->value.len;<br>
> p = h->value.data;<br>
<br>
Thanks for the patch.<br>
<br>
The cache validity time as obtained from cached responses is used <br>
while processing 304 responses during cache revalidation, so the <br>
suggested change looks wrong to me.<br>
<br>
-- <br>
Maxim Dounin<br>
<a href="http://mdounin.ru/" rel="noreferrer" target="_blank">http://mdounin.ru/</a><br>
_______________________________________________<br>
nginx-devel mailing list<br>
<a href="mailto:nginx-devel@nginx.org" target="_blank">nginx-devel@nginx.org</a><br>
<a href="http://mailman.nginx.org/mailman/listinfo/nginx-devel" rel="noreferrer" target="_blank">http://mailman.nginx.org/mailman/listinfo/nginx-devel</a><br>
</blockquote></div><br clear="all"><div><br></div>-- <br><div dir="ltr" class="gmail_signature"><div dir="ltr"><div>-------------------------------------</div><div>Sokichi TAKADA <<a href="mailto:takada@jocdn.co.jp" target="_blank">takada@jocdn.co.jp</a>></div><div>JOCDN Inc.</div></div></div>