Elie Steinbock
Elie Steinbock

Reputation: 5088

Nginx: Least connections with sticky sessions

I'm using nginx as a reverse proxy and need sticky sessions, so I'm using ip_hash as the balancing algorithm.

I'd prefer to do use least_conn (least connections) as the balancing algorithm. Is it possible to do least connections with sticky sessions?

Upvotes: 3

Views: 4191

Answers (1)

Baptiste
Baptiste

Reputation: 1759

From a pure load-balancing point of view, it doesn't make any sense to enable persistence and least conn, since persistence is an exeption to load-balancing: once persistence is enabled, then the load-balancer won't use the load balancing algorithm anymore, since it knows where to route the request. When persistence is enabled, then the load-balancing algorithm is only used to route the first request of each user. On Web traffic, the number of connections per server change a LOT every miliseconds... Hence that's why balancing users based on such metric doesn't make much sense when persistence is required.

More information here about persistence and load-balancing: http://blog.haproxy.com/2012/03/29/load-balancing-affinity-persistence-sticky-sessions-what-you-need-to-know/

By the way, unfortunately, you've just relized the difference between a software which can do load-balancing (nginx) and with a real load-balancer...

Simply switch to HAProxy for this purpose:

backend bk_myapp
 cookie MyAPP insert indirect nocache
 balance leastconn
 server srv1 10.0.0.1:80 check cookie srv1
 server srv2 10.0.0.2:80 check cookie srv2

Baptiste

Upvotes: 2

Related Questions