快速单线程彗星服务器,可能吗?

发布于 2024-09-05 17:16:50 字数 564 浏览 5 评论 0原文

我最近遇到了一些情况,服务器会分发一个事件流,其中包含所有侦听器完全相同的数据,例如“最近活动”框。

我发现让像 Apache 这样的服务器运行线程处理并查询包含相同数据的每个彗星流的数据库是非常奇怪和低效的。

我对这些全局(不是每个用户)流要做的是运行一个连续发出数据的单个线程,并为每个输出标头的新请求运行一个新的(绿色)线程,然后“合并”到主线程中。

一个线程是否可以服务多个套接字,或者多个客户端监听同一个套接字?

示例

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

存在这样的事情吗?会起作用吗?可以做吗?

免责声明:我不是服务器专家。

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

遇到 2024-09-12 17:16:50

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

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

≈。彩虹 2024-09-12 17:16:50

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

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

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

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?

眼眸印温柔 2024-09-12 17:16:50

您正在谈论应用于 Comet 的“异步 Web 请求”,有些像“异步 Comet”。

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

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文