Upstream Keepalive Questions

Maxim Dounin mdounin at mdounin.ru
Tue Apr 8 09:26:11 UTC 2014


Hello!

On Mon, Apr 07, 2014 at 05:29:15PM -0400, abstein2 wrote:

> I'm somewhat unclear about how the keepalive functionality works within the
> upstream module. My nginx install currently handles several hundred domains
> all of which point to different origin servers. I would imagine I can
> improve performance by enabling keepalive, however the documentation says
> "The connections parameter sets the maximum number of idle keepalive
> connections to upstream servers that are preserved in the cache of each
> worker process. When this number is exceeded, the least recently used
> connections are closed. "
> 
> Does that mean that if I have 10 domains and then set keepalive to 32, that
> there will potentially be up to 320 open connections from my server to the
> backend servers per worker at any given point or would the worker share all
> upstreams and only open a total of 32 regardless of how many upstream blocks
> were on the website? Also, does the number of keepalive connections have
> anything to do with the number of cores on a box?

Each upstream block has it's own connection cache.  There is no 
"generic" connection cache to be used with all upstream blocks.

> Also, is there any downside to having a large number of upstreams in the
> http block? I know for "map" block there's no performance degradation since
> they're only evaluated on demand, but I don't see any kind of documentation
> regarding how upstreams are handled.

Unless you use variables to dynamically select an upstream server, it 
is resolved while parsing configuration and there is no performance 
degradation at runtime regardless of the number of upstream blocks you 
have.

-- 
Maxim Dounin
http://nginx.org/



More information about the nginx mailing list