实施实时网络仪表板

发布于 2024-10-16 00:34:08 字数 177 浏览 3 评论 0原文

我想实现一个仪表板,它基于网络并且具有各种指标,其中一个指标每分钟更改一次,其他指标每天更改两次。如果发生更改,应尽快通过 AJAX 更新指标。这意味着同一页面将运行至少几个小时。

在 Java 世界中处理这个问题最有效的方法(技术/实现方面)是什么?

I'd like to implement a dashboard that is web-based and has a variety of metrics where one changes every minute and others change like twice a day. Via AJAX the metrics should be updated as quick as possible if a change occured. This means the same page would be running for at least several hours.

What would be the most efficient way (technology-/implementation-wise) of dealing with this in the Java world?

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

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

发布评论

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

评论(2

沙沙粒小 2024-10-23 00:34:08

好吧,这里有两个明显的选择:

  • Comet,又名长轮询:AJAX请求由服务器保持打开状态,直到几分钟后超时或发生更改(以先发生者为准)。这样做的缺点是处理许多连接可能会很棘手。除此之外,您不会想要常见的典型“每个请求一个线程,同步处理它”模型。
  • 来自 AJAX 页面的频繁轮询,每个请求都快速返回。这可能更容易实现,但在网络方面效率较低(请求更多)并且不太直接;例如,您可以每 5 秒发送一次请求,但如果您有很多用户,最终会产生大量流量。

最佳解决方案取决于您拥有多少用户。如果只有几个客户端,您可能很想采用“每 5 秒轮询一次”的方法 - 甚至可能每个请求一个线程进行长轮询(尽管这可能是实施起来稍微困难一些)。如果您有很多客户端,我肯定会选择长轮询,但是您需要了解如何在特定服务器环境中将线程与连接分离。

Well, there are two obvious options here:

  • Comet, aka long polling: the AJAX request is held open by the server until it times out after a few minutes or until a change occurs, whichever happens first. The downside of this is that handling many connections can be tricky; aside from anything else, you won't want the typical "one thread per request, handling it synchronously" model which is common.
  • Frequent polling from the AJAX page, where each request returns quickly. This would probably be simpler to implement, but is less efficient in network terms (far more requests) and will be less immediate; you could send a request every 5 seconds for example, but if you have a lot of users you're going to end up with a lot of traffic.

The best solution will depend on how many users you've got. If there are only going to be a few clients, you may well want to go for the "poll every 5 seconds" approach - or even possibly long polling with a thread per request (although that will probably be slightly harder to implement). If you've got a lot of clients I'd definitely go with long polling, but you'll need to look at how to detach the thread from the connection in your particular server environment.

勿忘初心 2024-10-23 00:34:08

我想彗星时代已经过去了。全新的 Socket.IO 协议越来越受欢迎。我建议使用 netty-socketio,它支持长轮询和 websocket 协议。 javascriptiosandroid 客户端库也可用。

I think time of Comet has gone. The brand new Socket.IO protocol gaining popularity. And i suggest to use netty-socketio, it supports both long-polling and websocket protocols. javascript, ios, android client libs also available.

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