Fast single thread comet server, possible?
        Posted  
        
            by Pepijn
        on Stack Overflow
        
        See other posts from Stack Overflow
        
            or by Pepijn
        
        
        
        Published on 2010-06-17T13:19:51Z
        Indexed on 
            2010/06/17
            13:23 UTC
        
        
        Read the original article
        Hit count: 424
        
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.
© Stack Overflow or respective owner