3 ms·
The broadcasting loop shouldn't take too long... I'm pretty sure that the socket.send() calls are non-blocking. I could be wrong, I haven't tested my (toy) chat
by dhotson 17y ago
The broadcasting loop shouldn't take too long... I'm pretty sure that the socket.send() calls are non-blocking.
I could be wrong, I haven't tested my (toy) chat server that thoroughly. :-P
In general, the single threaded evented model tends to scale better than the process/thread per connection model for large numbers of connections.
Having to context switch between 10,000 threads/processes typically means the OS spends a lot of time doing context switching instead of IO.
I'm not sure how Clojure implements agents, it may already handle having 10,000 concurrent agents efficiently. I'd be curious to know.
Also, there's a great article about network programming, which you may have read. It's called "The C10K Problem", which talks about scaling to 10,000 concurrent connections.
http://www.kegel.com/c10k.html http://www.kegel.com/c10k.html
.. really good article, well worth a read if you haven't already.
- KirinDave 17y ago> In general, the single threaded evented model tends to scale better than the process/thread per connection model for large numbers of connections. Having to context switch between 10,000 threads/processes typically means the OS spends a lot of time doing context switching instead of IO. Right, the evented model works, and you get that for free with Node.js. I dunno if that specific codebase would handle "thousands of users" though. Test it, it'd make a cool blogpost. :) > I'm not sure how Clojure implements agents, it may already handle having 10,000 concurrent agents efficiently. I'd be curious to know. Well right now it's 1 thread per connection, which I will have to change. As for agents, they dispatch on a threadpool with a number of threads corresponding to the number of cors in the physical hardware. So that part of the code should scale of fairly arbitrarily (although a specific room with many, many people may experience some latency, and many such rooms might bog down the thread pool).