views:

44

answers:

2

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.

+1  A: 

Check out node.js - single threaded, event driven server. Uses JavaScript as a bonus.

unomi
Looks nice :) Would Twisted do the same? They mention it there somewhere.
Pepijn
+1  A: 

If you are using ASP.NET, the following post should be useful

http://beta.codeproject.com/KB/aspnet/CometAsync.aspx

By the way, it is possible to implement Comet to serve more than one client per thread, but only one thread for all client seems not enough?

ZEAXIF
I'm more into Python and Clojure
Pepijn