nginx subrequests / background operations

Maxim Dounin mdounin at
Fri Jun 6 12:16:22 UTC 2014


On Fri, Jun 06, 2014 at 12:57:38AM -0400, Ameir Abdeldayem wrote:

> Hello,
> I am investigating the complexity of allowing for an additional parameter,
> "expired", to proxy_cache_use_stale.
> Instead of a request hitting the backend with an $upstream_cache_status of
> EXPIRED and making the client wait for the request to complete, the client
> would instead be given a stale version of that cached entry, and that entry
> would be updated in the background.

This is what the "proxy_cache_use_stale updating" does for years, 
with the only difference that the update is done by the first 
request instead of background.

So, basically, what you are trying to optimize is a single request 
per a resource expiration.  I would recommend you to reconsider if 
it actually worth the effort.

> I was looking into ngx_http_subrequest() as a potential route to take, but
> it looks like it's blocking (as in the client would have to wait for it to
> complete).  I also looked at post_action, but it's unclear on whether it's
> blocking or not, and whether it'd work for this case.

The post_action functionality will block a connection as well.

If you want something to happen "in the background", you'll have 
to introduce the "in the background" notion in the first place.  
Most simple approach seems to be to create a separate "fake" 
request with emulated properties and a closed connection.

Maxim Dounin

More information about the nginx-devel mailing list