nginx/backend keepalive question

Maxim Dounin mdounin at
Thu May 8 23:52:44 UTC 2014


On Wed, Apr 30, 2014 at 02:08:57PM -0700, Yu Zhao wrote:

> Greetings!
> I couldn't find my answer of following questions in the manual or somewhere
> else. Your help is much appreciated!

See src/http/modules/ngx_http_upstream_keepalive_module.c.

> 1) does nginx manage frontend/nginx and nginx/backend connections
> separately? In another word, will a nginx/backend connection be bond to a
> certain frontend/nginx connection for the lifetime of the frontend/nginx
> connection that is also kept-alive? My guess is it's not, nginx uses M:N
> model which M is the number of frontend/nginx connections that may or may
> not be kept-alive and N is the number of nginx/backend kept-alive
> connections, and M connections share N connections.

Cache of connections to upstream servers is completely unrelated 
to client connections.

> 2) If my guess is correct, how does nginx make sure the request/response
> pair is not broken/mismatched? Nginx wil NOT send new request to a backend
> until the response of the last one is received, right?


Moreover, even documentation specifically talks about "idle 
keepalive connections to upstream servers that are preserved in 
the cache", see

> 3) If I'm still on the right track: because nginx has to wait the response
> from a backend connection, it cannot reuse it for next request. That's why
> nginx still needs to open new connections to backend even there are
> existing connections. But It will only do so when all the existing
> connection are non-idle (i.e. responses from them haven't been fully
> received).

Yes, see above.

Maxim Dounin

More information about the nginx-devel mailing list