Saturday 16 April 2016

Need help with Redis Pub/Sub load balancing and multiple instances

I really don't like to post on StackOverflow, and you guys have been great here already.Anyways, I'm using Redis with PM2 and have 3 node instances running in the US on 3 ports:My nginx load balancer:upstream websocket { least_conn; server 127.0.0.1:9300; server 127.0.0.1:9301; server 127.0.0.1:9302; } So, I run my app with PM2 and boom, these instances are up and running. Redis is also subcribed on each on each port (9300, 9301, 9302) -- so If a player connects to instance 3 (9302) and sends a message to a player that is on 9300; it will publish to that instance so that user is notified. Yada Yada Yada, basic Pub / Sub system down and working. Obviously this is only good if we get a ton of players...In any event, here are some problems I have:What if I wanted to add another server? I read this, but that doesn't take into account multiple instances, only multiple server's. I'm doing multiple instances here. (this is where I am confused)What if player A is on 9300 and player B is on 9302 and player B joins player A's game. (When I say game I mean my game is similar to Diablo 2 where it's instance based so lets just say "channel") -- is it possible to get both player B and A onto the same node instance without losing their ws connection? This way, I can save some latency without using Redis` Pub/Sub to notify the other instance to send a message. Or is this pre-mature optimization?Thanks for the long read... Now you probably know why I don't post on SO :)

Submitted April 16, 2016 at 08:15AM by BillOReillyYUPokeMe

No comments:

Post a Comment