在时间密集型应用程序中正确使用 node.js 和 Socket.IO 的其他技术?
作为一个假设的例子,假设我想制作一个显示人们的 Twitter 网络的应用程序。我将提供一个 API,允许客户端查询单个用户名。该用户的前 x 条推文将被发送到客户端。然后,最初提到的每个人都会被扫描。他们的前 x 条推文将发送给客户。这个过程将递归地继续,广度优先,直到达到预定义的深度。客户端将实时接收数据,显示统计数据,例如扫描的用户数量、剩余扫描的已知用户数量以及不断增长的推文数据列表。所有处理都不复杂(少量文本的正则表达式),但许多网络请求将从单个初始请求中产生。
我真的很想要 Node.js 与 socket.io 的出色实时功能,但我觉得这是对这些技术的滥用 - 它们并不适合繁重的服务器端提升。是否有更合适的工具集来完成我想要完成的任务,或者使用这些工具来实现该目的的特定方法? Milewise 正在做类似的事情,但我认为我的应用程序会比他们的应用程序消耗更多的网络资源。
谢谢。
As a hypothetical example, let's say that I wanted to make an application that displays peoples twitter networks. I would provide an API that would allow a client to query on a single username. That user's top x tweets would be sent to the client. Then, each person that had been mentioned by the initial person would be scanned. Their top x tweets would be sent to the client. This process would recursively continue, breadth-first, until a pre-defined depth was reached. The client would be receiving the data in real time, displaying statistics such as number of users scanned, number of known users remaining to scan, and a growing list of the tweet data. None of the processing is complicated (regex of small amounts of text), but many, many network requests would be spawned from a single initial request.
I really want the fantastic realtime capabilities of node.js with socket.io, but I feel like this is an abuse of those technologies - they're not meant for heavy server-side lifting. Is there a more appropriate toolset for what I am trying to accomplish, or a particular way to use these tools to that end? Milewise is doing something similar-ish, but I think that my application would consume significantly more network resources than theirs.
Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
现在您可以在网络上获得的最佳网络传输是 WebSockets,它提供持久的双向实时传输- 服务器和客户端之间的时间连接。尽管并非每个浏览器都支持它们,但 socket.io 为您提供了一些后备解决方案,但它们可能会降低与 WebSocket 相比的网络性能,如 这篇文章:
除了网络传输之外,其他事情也可能很重要,例如如何在服务器端获取、格式化和处理数据。在 Node.js 中,大量 CPU 密集计算可能会阻塞其他异步操作的处理,因此应将此类操作分派到单独的线程或进程以防止阻塞。
The best network transport which you can get on the web now are WebSockets which offers persistent bi-directional real-time connection between server and client. Although not every browser supports them, socket.io gives you a couple of fallback solutions which may however decrease the network performance when compared to WebSockets as stated in this article:
Apart from network transport, other things may also be important, for example how are you fetching, formating and processing the data on the server side. In node.js heavy CPU bound computations may block processing of other asynchronous operations, therefore these kind of operations should be dispatched to separate threads or processes in order to prevent blocking.