设计一个长期运行的,资源密集型的Web服务的建议 [英] Recommendations for designing a long-running, resource-intensive web service

查看:221
本文介绍了设计一个长期运行的,资源密集型的Web服务的建议的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个.NET函数做一些复杂的计算。根据所传入的参数,函数:

I have a .NET function that does some complex calculation. Depending on the parameters that are passed in, the function:

  • 注意到任何地方从几分钟到几个小时来运行
  • 计算
  • 中采用的是单核心100%
  • 需要从MB的100秒到几个GB的内存
  • 在写入数据的任何地方从几MB到几个GB到磁盘
  • 在可能会抛出一个异常,其中包括一个OutOfMemoryException
  • Takes anywhere from several minutes to several hours to run
  • Uses 100% of a single core during the computation
  • Requires anywhere from 100s of MB to several GB of memory
  • Writes anywhere from several MB to several GB of data to disk
  • May throw an exception, including an OutOfMemoryException

的量,以将数据写入到磁盘可准确$从该函数的参数化pdicted p $。有没有简单的方法来predict其他资源需求从功能参数设置。

The amount to data to be written to disk can be accurately predicted from the function parameterisation. There is no easy way to predict the other resource requirements from the function parameterisation.

我需要通过Web服务来公开此功能。这种服务必须是:

I need to expose this function via a web service. This service needs to be:

  • Resiliant和优雅计算
  • 在报告任何问题
  • 能够处理并发请求,只要有足够的资源来处理不显著性能下降的请求,并平稳地拒绝该请求,否则。

我打算通过让初始请求返回一个可轮询进度的状态的资源来处理长期运行的本质。一旦计算完成该资源将会提供输出数据,该客户机可以下载(可能通过FTP)的位置。

I'm intending to handle the long-running nature by having the initial request return a status resource that can be polled for progress. Once the calculation is complete this resource will provide the location of the output data, which the client can download (probably via FTP).

我对如何最好地处理其他要求不太清楚。我正在考虑某种形式的计算池维持计算器的实例,并跟踪其当前使用的是的,但我还没有想出的细节。

I'm less clear on how best to handle the other requirements. I'm considering some sort of "calculation pool" that maintains instances of the calculator and keeps track of which ones are currently being used, but I haven't figured out the details.

有没有人有类似情况的经验有什么建议?只要该解决方案可以在Windows中运行,所有的技术方案可以考虑。

Does anyone with experience of similar situations have any suggestions? As long as the solution can run on a Windows box, all technology options can be considered.

推荐答案

我建议拆分应用程序两部分。

I'd suggest splitting your application in two parts.

  1. Web服务本身。它的功能:
    • 获取来自客户端的工作项目;
    • 在这项工作转移到后端服务执行实际工作;
    • 报告进度和结果;
  1. The web service itself. It's functionality:
    • Get a work item from a client;
    • Transfer this work to a backend service that performs the actual work;
    • Report progress and the result;
  • 在处理请求friom Web服务;
  • 执行实际的计算。

这种情况的原因是设计
1)它是比较难以处理的托管应用(ASP.NET),因为服务器(IIS工作量)将管理资源,同时在一个单独的应用程序,你有更直接的控制;
2)两层设计更具可扩展性 - 例如,以后你可以很容易地将后端移动到另一台物理计算机(或几台机器)

The reasons for this design are
1) it's relatively difficult to handle the workload in the hosted application (ASP.NET) because the server (IIS) will manage the resources, while in a separate app you have more direct control;
2) two-tier design is more scalable - for instance, later you could easily move the backend to another physical machine (or several machines).

该网站的服务应该是无状态 - 例如,后一个请求被接受,用户回来一些ID和使用此ID来轮询结果的服务

The web service should be stateless - for instance, after a request is accepted, the user gets back some ID and uses this ID to poll the service for the result.

后端服务器,可能是,具有维持对这些请求进行排队来处理和一组处理它们的工作线程。工人应监控可用资源并注意不要超载机(和,当然,妥善处理所有可能的错误情况)。

The backend server, probably, has to maintain a queue of the requests to process and a set of worker threads that process them. The workers should monitor the resources available and take care not to overload the machine (and, of course, gracefully handle all possible error conditions).

这篇关于设计一个长期运行的,资源密集型的Web服务的建议的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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