来自HTTP / REST服务的进度通知 [英] Progress notifications from HTTP/REST service

查看:152
本文介绍了来自HTTP / REST服务的进度通知的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发一个Web应用程序,它将任务提交给主/工作系统,该系统将任务分配给一系列工作程序实例中的任何一个。工作队列主服务器作为单独的进程运行(在一台单独的机器上),任务通过HTTP / REST请求提交给主服务器。将任务提交到工作队列后,客户端应用程序可以提交另一个HTTP请求以获取有关任务的状态信息。

I'm working on a web application that submits tasks to a master/worker system that farms out the tasks to any of a series of worker instances. The work queue master runs as a separate process (on a separate machine altogether) and tasks are submitted to the master via HTTP/REST requests. Once tasks are submitted to the work queue, client applications can submit another HTTP request to get status information about tasks.

对于我的Web应用程序,我希望它能够提供某种进度条视图,可以向用户显示任务处理的进度。实现这一点的显而易见的方法是使用AJAX进度计小部件,该小部件定期轮询工作队列以获取已提交任务的状态。我的问题是,如果没有频繁的轮询,是否有更好的方法来实现这一目标?

For my web application, I'd like it to provide some sort of progress bar view that gives the user some indication of how far along task processing has come. The obvious way to implement this would be an AJAX progress meter widget that periodically polls the work queue for status on the tasks that have been submitted. My question is, is there a better way to accomplish this without the frequent polling?

我考虑过让客户端Web应用程序打开一个服务器套接字就可以了听取工作大师的通知。我的另一个类似想法是使用XMPP或类似的协议进行状态通知。 (当然,主/工作系统需要更新以提供通知,但我拥有代码,因此可以自行进行任何必要的更新。)

I've considered having the client web application open up a server socket on which it could listen for notifications from the work master. Another similar thought I've had is to use XMPP or a similar protocol for the status notifications. (Of course, the master/worker system would need to be updated to provide notifications either way but I own the code for that so can make any necessary updates myself.)

有关建立这样的通知系统的最佳方法的任何想法?额外的努力是值得的,还是简单的轮询解决方案?

Any thoughts on the best way to set up a notification system like this? Is the extra effort involved worth it, or is the simple polling solution the way to go?

推荐答案

我想它取决于一个几个因素

I guess it depends on a few factors


  • 反馈的准确程度(1%,5%,50%)
    准确的反馈使其值得追求某种进度条和彗星式推。如果你只能说忙......坚持......差不多......完成然后一个简单的ajax我们还在那里民意调查肯定更容易编码。

  • 客户端如何及时看到完成消息

  • 每项任务需要多长时间(1秒,10秒,10分钟)

    1秒使它成为现实有点没有实际意义。 10秒让它值得。 10分钟意味着你最好建议用户去喝咖啡休息时间: - )

  • 会有多少并发请求。
    除非你有一个特殊的服务器,实时推送式系统倾向于吃连接,你很快就会被淘汰出局。不得不为更好的进度条投入更多网络服务器可能会损害预算。

  • How accurate the feedback can be (1 percent, 5 percent, 50 percent)
    Accurate feedback makes it worth pursuing some kind of progress bar and comet style push. If you can only say "Busy... hold on... almost there... done" then a simple ajax "are we there yet" poll is certainly easier to code.
  • How timely the Done message has to be seen by the client
  • How long each task takes (1 second, 10 seconds, 10 minutes)
    1 second makes it a bit moot. 10 seconds makes it worth it. 10 minutes means you're better off suggesting the user goes for a coffee break :-)
  • How many concurrent requests there will be
    Unless you've got a "special" server, live push style systems tend to eat connections and you'll be maxed out pretty quickly. Having to throw more webservers in for a fancy progress bar might hurt the budget.

我在 871184 显示手动滚动永远的框架这似乎运作良好。我开发的项目虽然没有那么严重,但操作需要几秒钟,我们可以提供相当准确的百分比。代码使用asp.net和jquery,但一般技术适用于任何服务器和javascript框架。

I've got some sample code on 871184 that shows a hand rolled "forever frame" which seems to work out well. The project I developed that for isn't hammered all that hard though, the operations take a few seconds and we can give pretty accurate percent. The code uses asp.net and jquery, but the general techniques will work with any server and javascript framework.

编辑 As John 指出,状态报告可能不是RESTful服务的工作。但没有任何内容表明你无法在客户端上打开iframe,该iframe挂钩到轮询服务的服务器上的页面。 Theory说服务器和服务至少会彼此接近: - )

edit As John points out, status reporting probably isn't the job of the RESTful service. But there's nothing that says you can't open an iframe on the client that hooks to a page on the server that polls the service. Theory says the server and the service will at least be closer to one another :-)

这篇关于来自HTTP / REST服务的进度通知的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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