Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Sticky session load balancer with nginx open source

What the main difference between the sticky session available in nginx plus and hashing cookie in open source version?

According to the docs nginx open source allows session persistence based on hashing different global variables available within nginx, including $cookie_

With the following configuration:

    upstream myserver {
        hash $cookie_sessionID;
        server localhost:8092;
        server localhost:8093;
        server localhost:8094 weight=3;
    }

    location / {
       proxy_pass http://myserver;
    }

Assuming, there will be centralized mechanism across backends for generating unique sessionID cookie for all new requests, so what the main disadvantages of such method compared to the nginx plus sticky session approach?

like image 647
Vasyl Nekohda Avatar asked Dec 18 '17 21:12

Vasyl Nekohda


People also ask

Does Nginx support sticky session?

NGINX Plus supports three session persistence methods. The methods are set with the sticky directive.

Can Nginx be used as load balancer?

It is possible to use nginx as a very efficient HTTP load balancer to distribute traffic to several application servers and to improve performance, scalability and reliability of web applications with nginx.

Which is better HAProxy or Nginx?

HAProxy supports virtual hosts and multiple network segments (layers 4 and 7). It has a more detailed and user friendly status page compared to Nginx. Easy integration with third party monitoring tools and services.


1 Answers

IP Hash load‑balancing can work as "sticky sessions", but you have to keep in mind that this load balancing method is working relative bad itself, because a lot of user/devices shared same external IP-Address in modern world.

We experimented with a rather heavily loaded (thousands of parallel users) application and observed tens of percent imbalance between servers when using IP Hash.

Theoretically, the situation should improve with increasing load and number of servers, but for example we did not see any significant difference when using 3 and 5 servers.

So, I would strongly advise against using IP Hash in productive environment.

As open-source based sticky sessions solution, not bad idea to use HAProxy, because HAProxy support it out-of-the-box. Or HAProxy + Nginx bundle, where HAProxy is responsible for "sticky sessions". (I know about one extremely loaded system that successfully uses such a bundle for this very purpose, so, this is working idea.)

like image 81
Gmugra Avatar answered Oct 23 '22 22:10

Gmugra