Web 套接字使用大量资源,如彗星长轮询?

发布于 2024-09-13 14:01:36 字数 150 浏览 2 评论 0原文

我知道 Comet 长轮询对 Web 服务器不利,因为它们每个连接占用一个线程。因此,您不能让大量用户保持持续连接,否则您的 Web 服务器将崩溃。

这与 HTML 5 中的 Web 套接字相同吗?

如果每个持久连接也占用一个线程,这怎么解决资源问题呢?

I know that Comet long polling are bad for Web servers because they occupy one thread per connection. So you cannot have a lot of users with persistent connections or your web server will crash.

Is this the same with web sockets in HTML 5?

How could this solve the resource problem if it occupies one thread too per persistent connection?

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

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

发布评论

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

评论(2

自控 2024-09-20 14:01:36

...因为它们每个连接占用一个线程

这种假设完全不正确。请参阅我在此处给出的答案 了解更多信息。 (例如)完全可以在 IIS 中使用 IAsyncHttpHandler 来执行长轮询,而不为每个客户端使用线程。

...because they occupy one thread per connection

This assumption is totally untrue. See the answer I gave here for more info. It is (for instance) entirely possible to use IAsyncHttpHandler in IIS to perform long-polling, without using a thread per client.

青瓷清茶倾城歌 2024-09-20 14:01:36

Spender 是正确的,只有糟糕的 Web 服务器(例如带有 mpm_worker 或 mpm_prefork 的 Apache)每个连接使用一个线程/进程。

智能 Comet 或 Websockets 网关(我不久前写过这样一个)将具有事件驱动的架构 - 要么基于 Proactor(具有固定的线程池),要么基于 Reactor(单线程)模式。长轮询应该通过保持活动的 HTTP 连接来完成(对于支持该连接的浏览器 - 大约 99%),在这种情况下,它将具有与 Websockets 类似的性能/可扩展性特征。

Spender is correct, only shitty web servers (e.g. Apache with mpm_worker or mpm_prefork) use a thread/process per connection.

A smart Comet or Websockets gateway (I wrote such one not long ago) will have an event-driven architecture - either based on the Proactor (with a fixed pool of threads) or Reactor (single-threaded) patterns. Long-polling should be done over keep-alive HTTP connections (for the browsers which support that - about 99% of them), in which case it will have similar performance/scalability characteristics as Websockets.

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