I would like to write a TCP server with node.js can accept 1000s of client connection. Each client would need to publish about 1 timestamp a second to a queue that is unique for the client. That same client would also need to be able to subscribe to one other clients queue, and have that data pushed to it when it get published. The data would not need to persist at all, if there is not a subscriber who wants it discard it.
Any tips on how I should go about doing this? I would like some type of solution that could scale if I put a load balancer in front of it. I have been thinking about using some type of PubSub queue, maybe zeromq, maybe a XMPP server.
If you want to load balance this and you need something custom, you're going to be a lot better off starting with Erlang. In Erlang, a PID reference (process ID) can transparently be a reference to a process on another machine in the cluster, so sending a message to the target queue is some variant on Message ! Pid regardless of which machine the queue is actually living on. MNesia can be used to keep track of what PID is what and that transparently replicates around without you having to write the logic. In Node.js it's going to be less transparent and unless there's a library that does all this for you, you're still going to be putting the solution together when you could have been done in Erlang, even if you're an expert in JS and know nothing about Erlang.
One of the queuing libraries might just work out of the box, though. But at least at the moment I would actually consider Node.js counterindicated for this task, unless you can be rigidly sure that messages never have to cross process boundaries.
Agreed. This sounds like an ideal learning project for Erlang.
Open a few tabs of erlang.org/doc/, grab a book (Joe Armstrong's Pragmatic book is a good one) and get started.
You'll be surprised how easily you made your first Erlang production system. (If this makes you feel guilty and you need to self-flagellate afterwards you can try packaging your app into a release.)
i just built a system like this w/Erlang. we have 'post office boxes' that can receive messages, each is unique, one per connected client, and certain 'PO boxes' can subscribe to others', if they want, or to a random sampling of general message from a group of other boxes. Erlang is perfect for this. We've projected that we will max out at around 1MM connections on a 48GB, 8 core box. We're running 150K connections right now and it's using about 17% of memory and much less CPU. The key though is we already tested with multiple boxes and it works the same way. There's no refactoring when we run out of space on one box. Email me if you want some other ideas about how to set this up in Erlang.
Any tips on how I should go about doing this? I would like some type of solution that could scale if I put a load balancer in front of it. I have been thinking about using some type of PubSub queue, maybe zeromq, maybe a XMPP server.