Welcome! Log In Create A New Profile

Advanced

Re: [PATCH] skip apply "ngx_http_upstream_process_accel_expires" when a request responeded by cache

Sokichi Takada
June 24, 2020 07:34AM
Hello!

In my case, the backend returns x-accel-expires with 304 responses every
time.

nginx calculates valid_sec by "ngx_http_upstream_process_accel_expires" for
any revalidate or HIT responses, thus to get the wrong valid_sec value in
header_filter/log hook handler.
This patch has no impact to every response results, and to be able to get
TRUE valid_sec value in the hook handlers.

---
TAKADA Sokichi


On Mon, Jun 22, 2020 at 7:37 PM Maxim Dounin <mdounin@mdounin.ru> wrote:

> Hello!
>
> On Mon, Jun 22, 2020 at 05:09:16PM +0900, Sokichi Takada wrote:
>
> > > The cache validity time as obtained from cached responses is used
> > > while processing 304 responses during cache revalidation, so the
> > > suggested change looks wrong to me.
> >
> > When processing 304 responses during cache revalidation,
> > ngx_http_upstream_process_accel_expires is called twice.
> >
> > 1st time, in "ngx_http_upstream_process_header" function.
> > src/http/ngx_http_upstream.c: 2387 rc = u->process_header(r);
> > # process_header = ngx_http_upstream_process_accel_expires
> >
> > 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.
> > Also, the r->cached is 0 at this time.
> >
> > 2nd time, in "ngx_http_upstream_process_header" ->
> > "ngx_http_upstream_test_next" -> "ngx_http_upstream_cache_send" function.
> > src/http/ngx_http_upstream.c: 2423 if
> > (ngx_http_upstream_test_next(r, u) == NGX_OK) ->
> > src/http/ngx_http_upstream.c: 2535 rc =
> > ngx_http_upstream_cache_send(r, u); ->
> > src/http/ngx_http_upstream.c: 1073 rc = u->process_header(r);
> >
> > This calculates unnecessary valid_sec value by x-accel-expires of the
> cache
> > data.
> > Also, this calculation can skip by this patch since the r->cached is 1 at
> > this time.
> >
> > Please look into ngx_http_upstream_test_next.
> > It keeps the valid_sec value of 1st time into "valid" variable at "2523
> > valid = r->cache->valid_sec;".
> > After that, it "calls ngx_http_upstream_cache_send", then updates cache
> > data with the "valid" variable at "2560 r->cache->valid_sec =
> > valid;".
>
> Backend is not required to return cache control headers along with
> the 304 response. If it doesn't - nginx uses the headers returned
> in the cached response.
>
> --
> Maxim Dounin
> http://mdounin.ru/
> _______________________________________________
> nginx-devel mailing list
> nginx-devel@nginx.org
> http://mailman.nginx.org/mailman/listinfo/nginx-devel
>


--
-------------------------------------
Sokichi TAKADA <takada@jocdn.co.jp>
JOCDN Inc.
_______________________________________________
nginx-devel mailing list
nginx-devel@nginx.org
http://mailman.nginx.org/mailman/listinfo/nginx-devel
Subject Author Views Posted

[PATCH] skip apply "ngx_http_upstream_process_accel_expires" when a request responeded by cache

TAKADA Sokichi 375 June 18, 2020 08:42PM

Re: [PATCH] skip apply "ngx_http_upstream_process_accel_expires" when a request responeded by cache

Maxim Dounin 186 June 21, 2020 05:12PM

Re: [PATCH] skip apply "ngx_http_upstream_process_accel_expires" when a request responeded by cache

Sokichi Takada 165 June 22, 2020 04:10AM

Re: [PATCH] skip apply "ngx_http_upstream_process_accel_expires" when a request responeded by cache

Maxim Dounin 165 June 22, 2020 06:38AM

Re: [PATCH] skip apply "ngx_http_upstream_process_accel_expires" when a request responeded by cache

Sokichi Takada 178 June 24, 2020 07:34AM

Re: [PATCH] skip apply "ngx_http_upstream_process_accel_expires" when a request responeded by cache

Maxim Dounin 137 June 25, 2020 04:58AM



Sorry, you do not have permission to post/reply in this forum.

Online Users

Guests: 269
Record Number of Users: 8 on April 13, 2023
Record Number of Guests: 421 on December 02, 2018
Powered by nginx      Powered by FreeBSD      PHP Powered      Powered by MariaDB      ipv6 ready