Hacker News new | ask | show | jobs
by deadbabe 914 days ago
I find that node js based multiplayer backends will eventually slow to a crawl as the number of connections goes up. How have you solved this problem? Wouldn’t something like Go be a better alternative here?
4 comments

I don’t see why. Connection-wise, the node event would loop make I/o blocking from the http request / response side a non issue. I doubt the backend is doing physics heavy stuff for the front end.
You must perform physics calculations on the backend if they are significant features that influence player positions.

Node also only works off a single core.

Node of course can work on multiple cores, using worker threads [1]. You can even share large data efficiently using a SharedArrayBuffer.

[1]: https://nodejs.org/api/worker_threads.html

It isn’t trivial to just split up a game into múltiple worker threads and keep everything in sync. With Go, it’s much easier.
Can you expand on the low hanging fruit of splitting a game into multiple goroutines?

What lends itself well to this?

goroutines
There is still considerable overhead turning things into buffers and back. Was there ever a good reason given as to why passing an object to a worker normally has to convert everything to string and back? It is just so completely idiotic.
I see. That makes sense.
They use uWebSockets (https://github.com/uNetworking/uWebSockets), which was written in C, but has an interface to use in NodeJS. It's been really performant for me in my simple tests compared to other popular websocket libs that slow down fairly quickly.
I get the feeling that the bottleneck in most IO games is the IO (no pun intended, the genre name comes from the TLD), which makes Node a good choice.
Scaling can indeed become a consideration, especially with a large number of connections. In our case, we've optimized our backend to handle a substantial number of concurrent connections efficiently. Also, each game is limited to 64 players max, although we tested up to 100+ connections and didn't notice any performance issues. Each game runs in isolated containers.