I am implementing a distributed chat system, in this system we have the following options :
-
Make the client and server running at each node run as separate threads. The server acting as the receiver will be running as the daemon thread and the client taking the user input as a normal thread.
-
Fork two processes one for the client and one for the server.
I am not able to reason out with which one to proceed. Any insight would be great !
You can do it in a “scalable” way just by creating n workers in threads that receive data and put them into right queues, m workers that push data to clients and k workers that process data from queues.
n workers getting data
m workers pushing data
k workers processing data and tracking state
incoming message que
outcoming message que
this way you can find best (n, m, k) for you. Only problem here is that it will be not trivial to implement it without any bugs. You could potentially reduce amount of worker types to two, incoming message and process + push and use list’s in redis (redis.io) as queues. But still this will require a lot of test coverage 🙂 Good luck
Actually you could use websockets for this. Something like socket.io http://socket.io/ or faye http://faye.jcoglan.com/
And just create front for the chat 🙂 This will solve most of your problems in a really scalable and usable way.