0

I have an Nginx instance which serves requests proxied to it from an haproxy. This instance should balance load between several websocket server. To get better performance the load balancing should be sticky and so i used ip_hash as the load balancing method which not works as all requests are coming from haproxy. so i tried to load balance based on x-forwarded-for header like:

    upstream orderbook {
    hash $http_x_forwarded_for consistent;
    server 127.0.0.1:8001;
    server 127.0.0.1:8002;
}

using this method distributed load between backends but ruins session persistence (i guess so because most of the clients switch from websockets to longpolling)! What can i do to achieve LB based on real client ips?

EDIT: After trying everything most of clients switched to using websocket again by changing client connection configurations and adding:

transports: ['websocket','polling'],

It seems that in the default configuration socket.io first tries to make a long polling connection. But I wonder what was the link between using nginx load balancing and change in transport of choice by clients.

mhk
  • 101
  • 2
  • Please be more specific about "not working". How did you determine that this is the case? – Gerald Schneider Jul 05 '22 at 08:59
  • @GeraldSchneider Edited the post and clarified the problem. Thanks for your comment. – mhk Jul 05 '22 at 10:12
  • You didn't answer the question though. How many client IPs did you use for testing? If you only used a small number chances are high that the calculated hash places them on the same backend server. But that would not be a good test. – Gerald Schneider Jul 05 '22 at 10:49
  • @GeraldSchneider It is a production server and there are 2.2k open websocket connections. – mhk Jul 05 '22 at 15:47

0 Answers0