2 ms·
> Cluster your app How is this possible in my multiplayer game where the whole world lives in the program? E.g. var map = [...] and then map[x][y] when I wan
by Kiro 11y ago
> Cluster your app
How is this possible in my multiplayer game where the whole world lives in the program? E.g. var map = [...] and then map[x][y] when I want to use it, var players = [], players.push(newPlayer) etc. How can I share this state in a cluster?
- jw989 11y agoWell, you're main app should obviously not be clustered but think about the api you use to manage data. I don't know your architecture but I'm sure that you can separate your api from your user state and cluster those apis as well as use various reverse proxies and load balancing services.
- jonesetc 11y agoYou need some form of IPC. Easiest thing that comes to my mind is just to use a redis hash.
- chowes 11y agoIn your current state, clustering is probably not be the best advice for your use case. That being said, if you are planning on scaling, you'll likely be moving your map object into it's own process, or a more traditional database, etc. Then whatever node application you have that facilitates the communication between that db/process and your users (via websockets or http) will be the place where clustering will come in handy.
- angersock 11y agoClustering is useful mainly when your app gets large or when you are handling redundancy. If you aren't doing that, your app is small enough not to need it. :) If you want a fun exercise, try monkeypatching your global objects (map, players, etc.) to have getters/setters/etc. that transparently handle the syncing stuff.
- habitue 11y agoYour app should be clustered, and your db (where your state should live) can be clustered too. Ultimately you want as little state in your app servers as possible, since this makes it harder to scale them out, reboot them etc. That's the ideal case anyway, its hard to avoid session state with websockets etc, but you can still push a lot down to the database layer
- seivan 11y agoWould Redis solve your problem?