howardchung / watchparty

Watch anything together in-sync with your friends
https://www.watchparty.me
MIT License
743 stars 137 forks source link

Nodejs cluster #840

Closed lay3r closed 8 months ago

lay3r commented 11 months ago

Why are you using pm2 shards and not nodejs cluster?

howardchung commented 11 months ago

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

lay3r commented 11 months ago

Then you have to look at the logs of each cluster

lay3r commented 11 months ago

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

lay3r commented 11 months ago

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

You can pass everything through one port

howardchung commented 11 months ago

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

lay3r commented 11 months ago

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.

howardchung commented 11 months ago

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

lay3r commented 11 months ago

What about connecting users to session through redis?

howardchung commented 11 months ago

That could probably work too but requires a dependency on Redis