一个不断向服务器请求数据的网页应该使用什么技术
我们需要创建一个基于 Web 的前端来显示一些数据。问题是数据需要大约每秒更新一次。 对于我作为一名 Web 开发人员来说,显而易见的解决方案是 AJAX。 不幸的是,该 Web 前端的目的之一是在嵌入式浏览器窗口内显示,该窗口预计会持续运行数月甚至数年。就这样,几个月的工作,没有重新启动/刷新。 在测试过程中,我们在 Safari 中运行了一个概念验证界面(每 1.5 秒请求一组简单的数据)一个多月。在此期间,Safari 的内存使用量从约 30 MB 上升到超过 100 MB。 因此我们担心这种解决方案的稳定性。
我想知道您是否可以向我们推荐任何其他技术来完成此任务,可能会减少开销(当请求简单的数据集时 - 就像我们的例子一样 - 恐怕 HTTP 标头是数据的非常重要的一部分)
We need to create a web-based frontend for displaying some data. The problem is that the data needs to be updated about once a second.
For me as a web-developer the obvious solution is AJAX.
Unfortunately, one of the purposes of this web frontend is to be displayed inside of embedded browser window which is expected to run constantly for months or even years. That's it, months of work with no restart / refresh.
During testing we ran a proof of concept interface (which requested a simple set of data each 1,5s) in Safari for over a month. During this period of time, the memory usage of Safari raised from ~30 MB to over 100MB.
Thus we're afraid of stability of such a solution.
I'm wondering if you could recommend us any other technique for this task, possibly with less overhead (when requesting simple sets of data - as in our case - I'm afraid the HTTP headers are very significant part of data)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
我建议研究一下 node.js 和 now.js 插件,它允许通过 websockets 进行实时更新。它甚至支持旧版浏览器,因此如果浏览器不支持 websockets,它将转向 Comet 服务器实现、AJAX 或 iframe。
在 Linux 环境中设置起来非常简单,并且有充足的文档可以帮助您入门。
它与 javascript 一起工作,并在 Google V8 javascript 引擎上运行,因此如果您曾经使用过 OOP Javascript,您应该能够相对轻松地掌握它。
链接:
http://nodejs.org/
http://nowjs.com/
I would suggest looking into node.js and the now.js plugging, which allows for realtime updates via websockets. It even has support for older browsers, so if the browser does not support websockets, it will do a fall over to either a comet server implementation, AJAX or an iframe.
It's extremely easy to setup on a linux environment, and there's ample documentation to get you started.
It works with javascript and runs on the Google V8 javascript engine, so if you've ever worked with OOP Javascript, you should be able to pick it up relatively easy.
LINKS:
http://nodejs.org/
http://nowjs.com/
Adobe AIR 作为前端怎么样?你可以使用Flash/FLEX,里面有不错的垃圾收集器,所以长时间运行应该不是问题。 AIR 还允许使用 XHTML 和 JavaScript 进行编写,因此如果您只熟悉这些技术,那么它可能是一个不错的选择
。对于此类请求,PHP 不是一个好的选择。 Comet 似乎是从服务器接收数据的好方法。您可以使用例如优秀的 Tornado (Python) 作为后端。
ActionScript 允许使用 TCP 套接字,因此您可以编写自己的协议以获得更好的性能,并使用 BOOST Asio (C++) 或 Netty (Java) 作为可扩展后端
How about Adobe AIR as front-end? You can use Flash/FLEX inside which have decent garbage collectors so long running shoudn't be a problem. AIR also allows to write in XHTML and JavaScript so it could be a good option if you're only familiar with those technologies
PHP is not a good choice for this kind of requests. Comet seems to be a good way to receive data from server. You can use for example excellent Tornado (Python) as backend.
ActionScript allows to use TCP sockets so you can write your own protocol for even better performance and use BOOST Asio (C++) or Netty (Java) as scalable backend
也许是网络套接字?服务器不是每 X 秒发出一次 AJAX 请求,而是在新数据到来时推送新数据。
Maybe websocket ? Instead of making an AJAX request each X seconds, the server push new data as they comes.
我个人最喜欢的是 php4+、mysql、apache 或 lightpd 网络服务器。
很难我也建议Python。
我专注于你提到的内容,话虽如此,你真的会看屏幕吗?如果没有,您应该使用 http 套接字或通过 Linux 机器上的 wget cronjob 请求该页面。
是的,http 标头非常重要,如果您尝试将其删除,网络服务器将发出“服务器 - 错误请求”错误。
让我知道你的决定,我有很多东西要分享:)
My personal faverite is php4+, mysql, apache or lightpd webserver.
Tough I also suggest Python.
I specialize in what you are mentioning, with that said, will you be actually looking at the screen? If not you should request the page using an http socket or via a wget cronjob on a linux box.
Yes the http header is very important, if you try to strip them out the webserver will issue a "Server - Bad Request" Error.
Let me know what you decide, I have a lot to share :)
我怀疑问题不在于 AJAX 本身,而在于使用浏览器本身:我不认为任何地方都考虑到持续运行,并且我假设所有(重新)加载过程都将成为某种形式的额外记忆最后。
我认为你最好通过自己设计的简单的东西来使用你的数据。显然,您可以在同一地点(服务器,可通过 HTTP 请求或您最喜欢的任何内容)生成它,但如果您的目标首先是“几年的正常运行时间”,则不需要完整的网络浏览器。
I suspect that the problem is not AJAX per se, but using a browser an sich: I don't think any where made with constant running in mind, and I'm assuming that all (re)loading processes will become some form of extra memory in the end.
I think you would be best off to consume your data trough something simple you design yourself. You can obviously produce it on the same spot (server, requestable via HTTP or whatever you like most), but you do not need a complete webbrowser if your goal is first "a couple of years uptime".