1

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.

4

3 回答 3

1

查看 node.js - 单线程、事件驱动的服务器。使用 JavaScript 作为奖励。

于 2010-06-17T13:22:41.027 回答
1

如果您使用的是 ASP.NET,下面的帖子应该很有用

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

顺便说一句,可以实现 Comet 为每个线程服务多个客户端,但所有客户端只有一个线程似乎不够?

于 2010-06-17T13:34:56.210 回答
0

您说的是应用于 Comet 的“异步 Web 请求”,有些类似于“异步 Comet”。

在我看来,这种近来如此流行的方法存在严重缺陷

于 2011-01-10T08:40:12.187 回答