HTTP与Websockets在开销方面的关系 [英] HTTP vs Websockets with respect to overhead

查看:89
本文介绍了HTTP与Websockets在开销方面的关系的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在两端使用node.js构建文件同步程序(与Dropbox不同).我需要潜在地有数千个客户端同时请求数据.

I am building a file synchronization program (not unlike Dropbox) using node.js on both ends. I need to have potentially thousands of clients requesting data at the same time.

这是我当前的系统:

  • 服务器通过Websocket将通知推送到客户端(文件已更新)
  • 客户端将下载排队并在空闲时发出HTTP请求

我将以每个50 MB的压缩块形式提供数据,因此HTTP请求开销(标头)可以忽略不计.

I will be serving data in compressed chunks of, say, 50 MB each, so the HTTP request overhead (headers) is negligible.

如果我要使用Websocket来处理请求推送通知,将会出现:

If I were to use websockets for requests and push notifications, would there be:

  • 整体速度显着提高? (减少的延迟,身份验证等)
  • 服务器保持连接打开的额外开销?
  • 是否存在推送二进制数据的问题?

我认为我需要通过专用的websocket发送通知,因为我不希望在进行下载时将它们在服务器上排队(很多开销).

I think I need to have notifications sent over a dedicated websocket because I don't want them to be queued on the server while a download is taking place (lots of overhead).

注意:只要客户的系统处于打开状态,这些websocket就会长期打开.

我将在不同端口上的不同http服务器上使用websocket,以便将它们移至不同的CPU内核.我可能会打开成千上万个(如果不是成百上千个)并发websocket ...

I will be using the websockets on a different http server on different ports in order to move them to different CPU cores. I could potentially have thousands (if not hundreds of thousands) of concurrent websockets open...

推荐答案

如果打算将node.js用于客户端和服务器,则应使用本机

If you intend to use node.js for both client and server then you should use native net module with pure sockets rather than WebSockets. Pure sockets are much better optimized for data transfer, especially binary. As far as I know browser WebSockets do not even support binary transfer yet.

这篇关于HTTP与Websockets在开销方面的关系的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆