Fast single thread comet server, possible?
- by Pepijn
I recently encountered a few cases where a server would distribute an event stream that contains the exact same data for all listeners, such as a 'recent activity' box.
It occurred to me that it is quite strange and inefficient to have a server like Apache run a thread processing and querying the database for every single comet stream containing the same data.
What I would do for those global(not per user) streams is run a single thread that continuously emits data, and a new (green)thread for every new request that outputs the headers and then 'merges' into the main thread.
Is it possible for one thread to serve multiple sockets, or for multiple clients to listen to the same socket?
An example
o = event
# threads received
| a b # 3
o / / # 3 -
|/_/
| # 1
o c # 2 a, b
| /
o/ # 2 a, b
o # 1 a, b, c
| # connection b closed
o # 1 a, c
Does something like this exist? Would it work? Is it possible to do?
Disclaimer: I'm not a server expert.