News for hackers. Stuff that matters.
Re:Habits of a Happy Node Hacker by Kiro on Wednesday November 11, 2015 @12:11PM (#10547684)
> 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?

Re:Habits of a Happy Node Hacker by chowes on Wednesday November 11, 2015 @12:28PM (#10547789)
In 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.

Re:Habits of a Happy Node Hacker by habitue on Wednesday November 11, 2015 @12:47PM (#10547919)
Your 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

Re:Habits of a Happy Node Hacker by jw989 on Wednesday November 11, 2015 @12:15PM (#10547705)
Well, 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.
Re:Habits of a Happy Node Hacker by jonesetc on Wednesday November 11, 2015 @12:15PM (#10547709)
You need some form of IPC. Easiest thing that comes to my mind is just to use a redis hash.
Re:Habits of a Happy Node Hacker by angersock on Wednesday November 11, 2015 @12:42PM (#10547876)
Clustering 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.

Re:Habits of a Happy Node Hacker by seivan on Wednesday November 11, 2015 @02:04PM (#10548494)
Would Redis solve your problem?