Welcome! Log In Create A New Profile

Advanced

Random upstream question for persistence and least connection load balancing

Posted by stevek1977 
Random upstream question for persistence and least connection load balancing
June 26, 2012 11:36AM
I'm looking to use nginx as a reverse proxy cache with ssl support. So far everything is awesome. The last piece of the puzzle is that I need to address a somewhat simple problem - least connection based load balancing with session persistence.

Pretty basic, and I've done my research - but have one final question.

The upstream module seems to support both pieces, but possibly not together. What I would like is a way to load balance based on least connections, and then guarantee that once a session is begun they are sent to the same backend server for the remainder of their visit.

It looks like the upstream module supports this with ip_hash and least_conn, but it doesn't say that it supports them TOGETHER.

The other alternative is to utilize technology from third party add-ons:

Upstream Fair Balancer will do the least connection load balancing - http://wiki.nginx.org/HttpUpstreamFairModule
Sticky Upstream will set a cookie and do the routing - http://code.google.com/p/nginx-sticky-module/

If I can get this same functionality with ip_hash and least_conn I am happy to use it, but it doesn't seem that they can be used together. Am I incorrect in that assumption? Can they be used together? Or would it be better to use the third party add-ons? I'm looking for a simple answer here, but more than happy to discuss the benefits of both scenarios and appreciate your response.
Re: Random upstream question for persistence and least connection load balancing
July 20, 2012 04:31AM
Well, we also use HttpUpstreamFairModule and it works like a charme.

You have to define 2 upstream sections, we use the JSESSIONID Cookie for stickiness f.e.:

upstream lan_http {
server server01 srun_id=a;
server server02 srun_id=b;
jvm_route $cookie_JSESSIONID reverse;
}

upstream lan_http_fair {
server server01;
server server02;
fair;
}

After that you could use the following in your location directive:
if ($cookie_JSESSIONID = '') {
proxy_pass http://lan_http_fair;
break;
}
proxy_pass http://lan_http;

So if no Sessioncoockie is set, the fair module is used, otherwise the lan module.

Hth Jens


Edit: In this example we are using the nginx-upstream-jvm-route module.



Edited 1 time(s). Last edit at 07/20/2012 04:33AM by jjk77.
Sorry, only registered users may post in this forum.

Click here to login

Online Users

Guests: 78
Record Number of Users: 8 on April 13, 2023
Record Number of Guests: 421 on December 02, 2018
Powered by nginx      Powered by FreeBSD      PHP Powered      Powered by MariaDB      ipv6 ready