[PATCH] HTTP: keepalive_graceful_close support

Maxim Dounin mdounin at mdounin.ru
Tue Jan 11 01:12:15 UTC 2022


Hello!

On Fri, Dec 31, 2021 at 02:24:13PM +0000, 幼麟 封 wrote:

> You are right, we can’t completely avoid this kind of problem, 
> but we can reduce some. Maybe "keepalive_graceful_close" is not 
> exact, it should be "wait_keepalive_on_exit". I mean, with this 
> patch, I want to optimize the connection closure problem caused 
> by the exit of the work process, is an optimization for a 
> specific scene. By setting a shorter expiration time for the 
> keepalived connection on the client side than the 
> "keepalive_timeout" on the nginx side, we can really reduce the 
> number of client retries.

Sure enough, by waiting longer before closing the keepalive 
connection we can reduce retries.  But this delays worker shutdown 
and therefore comes at cost, and this cost might be bigger than 
saved client retries.  Further, this won't completely eliminate 
retries anyway, even if clients are configured to use shorter 
timeouts than nginx: there are cases when nginx closes keepalive 
connections before keepalive_timeout expires, notably when there 
are no free worker connections.

I've committed the patch to disable keepalive as long as we know 
it cannot be used when sending response headers.  This should 
significantly reduce retries in practical cases, and comes at 
(almost) no cost.  Thanks for prodding this.

-- 
Maxim Dounin
http://mdounin.ru/



More information about the nginx-devel mailing list