howardchung / watchparty

Watch anything together in-sync with your friends

Home Page:https://www.watchparty.me

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Nodejs cluster

lay3r opened this issue · comments

Why are you using pm2 shards and not nodejs cluster?

Pm2 has nicer logging and management features. But aside from that there's not much reason

Then you have to look at the logs of each cluster

On the other hand, pm2 will automatically restart the cluster, got you

https://socket.io/docs/v4/pm2/

You can pass everything through one port

Right now nginx handles the connections as a gateway and then delegates to the appropriate shard running on separate ports

I can't figure out from your code how a client connects to the same socket session as another client in cluster mode. The roomid is linked to the shard? Because I can't see sticky sessions.

The SHARD parameter is computed from the room name and passed in the URL. Nginx handles directing the traffic to the correct port/instance

What about connecting users to session through redis?

That could probably work too but requires a dependency on Redis