如何最快速地从服务器获取小而频繁的更新?
我正在设计一个 Web 应用程序,该应用程序将使用 AJAX 与嵌入式设备上的服务器进行通信。但对于一项功能,客户端需要在较长时间内获得非常频繁的更新(每秒 >10 次),并尽可能接近实时。同时,需要不时处理典型的 AJAX 请求。
该项目特有的一些考虑因素:
该数据将非常小,可能不超过一个数值。
一次只有 1 个客户端连接到服务器,因此扩展不是问题。
客户端和服务器将驻留在同一本地网络上,因此连接将快速可靠。
该应用程序将专为 Android 设备设计,因此我们可以利用任何特定于平台的浏览器功能。
后端很可能使用 Apache 或 lighttpd 上的 WSGI 在 Python 中实现,但这仍然有待讨论。
我正在研究 Comet 技术,包括 XHL 长轮询 和 隐藏 iframe,但我对 Web 开发还很陌生,我不知道我们可以期待什么样的表现。服务器准备数据不应该有任何问题,只需尽快将其推送到客户端即可。对于任何 Comet 技术,甚至常规 AJAX 轮询,每秒 10 次更新是否是不合理的期望?或者您有其他建议的方法吗?
我意识到这最终需要一些原型设计,但如果有人能给我一个大致的估计或更好的特定技术(客户端和服务器端),在这种情况下可以提供最佳性能,那将是一个很大的帮助。
I'm working on the design of a web app which will be using AJAX to communicate with a server on an embedded device. But for one feature, the client will need to get very frequent updates (>10 per second), as close to real time as possible, for an extended period of time. Meanwhile typical AJAX requests will need to be handled from time to time.
Some considerations unique to this project:
This data will be very small, probably no more than a single numeric value.
There will only be 1 client connected to the server at a time, so scaling is not an issue.
The client and server will reside on the same local network, so the connection will be fast and reliable.
The app will be designed for Android devices, so we can take advantage of any platform-specific browser features.
The backend will most likely be implemented in Python using WSGI on Apache or lighttpd, but that is still open for discussion.
I'm looking into Comet techniques including XHL long polling and hidden iframe but I'm pretty new to web development and I don't know what kind of performance we can expect. The server shouldn't have any problem preparing the data, it's just a matter of pushing it out to the client as quickly as possible. Is 10 updates per second an unreasonable expectation for any of the Comet techniques, or even regular AJAX polling? Or is there another method you would suggest?
I realize this is ultimately going to take some prototyping, but if someone can give me a ball-park estimate or better yet specific technologies (client and server side) that would provide the best performance in this case, that would be a great help.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您可能需要考虑 WebSocket。这样您就不必轮询,您可以直接从服务器接收数据。我不确定目前有哪些服务器实现可用,因为它仍然是一项相当新技术,但我找到了一篇关于 Android 上的 WebSockets 库的博客文章:
http://anismiles.wordpress.com/2011/02/03/websocket-support-in-android%E2%80%99s-phonegap-apps/
You may want to consider WebSockets. That way you wouldn't have to poll, you would receive data directly from your server. I'm not sure what server implementations are available at this point since it's still a pretty new technology, but I found a blog post about a library for WebSockets on Android:
http://anismiles.wordpress.com/2011/02/03/websocket-support-in-android%E2%80%99s-phonegap-apps/
对于 Python 后端,您可能需要查看 Twisted。我还推荐 WebSocket 方法,但如果做不到这一点,并且由于您似乎专注于浏览器客户端,我将默认使用 HTTP 流而不是轮询或长轮询。这个 jQuery 插件 实现了一个 http 流 Ajax 客户端,并专门声明支持 Twisted。
For a Python back end, you might want to look into Twisted. I would also recommend the WebSocket approach, but failing that, and since you seem to be focused on a browser client, I would default to HTTP Streaming rather than polling or long-polls. This jQuery Plugin implements an http streaming Ajax client and claims specifically to support Twisted.
我不确定这是否有帮助,但您可能想尝试 Comet 风格的 ajax
http://ajaxian.com/archives/comet-a-new-approach-to-ajax-applications
I am not sure if this would be helpful at all but you may want to try Comet style ajax
http://ajaxian.com/archives/comet-a-new-approach-to-ajax-applications