开发者

Fast single thread comet server, possible?

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开发者_Go百科

Does something like this exist? Would it work? Is it possible to do?

Disclaimer: I'm not a server expert.


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


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?


You are talking about "asynchronous web requests" applied to Comet, some like "asynchronous Comet".

In my opinion this approach, so popular these days, is deeply flawed.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜