5

We are running NGINX in front of our backend server.

We are attempting to enable the proxy_cache_background_update feature to allow NGINX to async updates to the cache and serve STALE content while it does this.

However, we are noticing that it still delivers STALE content slowly as if it's not serving from the cache. The time it takes after an item expires is very slow and clearly not served from cache - you can tell it's going to the backend server, getting an update and delivering it to the client.

Here is our configuration from NGINX:

proxy_cache_revalidate on; proxy_ignore_headers Expires; proxy_cache_background_update on; 

Our backend server is delivering the following headers:

HTTP/1.1 200 OK Date: Thu, 28 Feb 2019 21:07:09 GMT Server: Apache Cache-Control: max-age=1800, stale-while-revalidate=604800 Content-Type: text/html; charset=UTF-8 

When attempting an expired page fetch we do notice the following header:

X-Cache: STALE 

However, when providing this response it is very slow as if it's contacted the backend server and done it in realtime.

NGINX version:

$ nginx -v nginx version: nginx/1.15.9 

Any suggestions, tips and config changes are greatly appreciated.

UPDATE

It seems that the nginx server is honoring serving stale content (as we have tested) but it also updates the cache from the backend on the same request/thread thus causing the slow response time to the client. I.e. it seems to be totally ignoring the proxy_cache_background_update on; directive and not updating in the background on a separate subrequest (async).

1
  • Did you manage to solve this issue? I'm facing the same issue. Commented Sep 16, 2024 at 12:41

3 Answers 3

1

Please go to ticket:

https://trac.nginx.org/nginx/ticket/1738#comment:6

Seems that this is a reopened bug.

1
1

I was able to fix this by adding. keepalive_timeout 0; to the location block.

1
  • that improves the situation a little but it doesn't completely solve it. nginx still does not actually process those "background" requests in the background. it's definitely not a configuration issue but a limitation of the feature's implementation. they could implement a worker to fetch stale resources, and queries add to a queue of such resources to be updated. that is not the case however. Commented Mar 22, 2024 at 22:54
0

I think you're missing proxy_cache_use_stale updating;

From the docs for that parameter:

the updating parameter permits using a stale cached response if it is currently being updated.

And for proxy_cache_background_update they have this to say:

Note that it is necessary to allow the usage of a stale cached response when it is being updated.

Which is what's proxy_cache_use_stale updating; is doing.

7
  • Thank you for your reply. We have tried with proxy_cache_use_stale updating; however the same behavior happens. As far as I'm aware, there is also no need to use proxy_cache_use_stale updating; when the backend sets a Cache Control: stale-while-revalidate header. The issue seems to be that it honors serving STALE content but it is also updating the cache on the same thread as the request comes in - i.e. it's simply ignoring proxy_cache_background_update on; Commented Mar 1, 2019 at 12:07
  • I have updated the question above with additional details. Commented Mar 1, 2019 at 12:10
  • Hey @TedWilmont. I think I have the same problem, did you solve it? Commented Jun 5, 2019 at 20:57
  • @Lucas Pelegrino, maybe you both just had to upgrade nginx: hg.nginx.org/nginx/rev/9552758a786e Commented Jun 6, 2019 at 8:18
  • Thanks @DanilaVershinin, but I'm on version 1.15.9, and according to source control already has the mentioned changes: hg.nginx.org/nginx/file/9552758a786e/src/http/… Commented Jun 7, 2019 at 18:44

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.