IIS中长时间运行任务的最佳实践 [英] best practice with long running task in IIS

查看:66
本文介绍了IIS中长时间运行任务的最佳实践的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我有一个架构问题:

我写了一个企业3层应用程序,DDD方法,它在IIS中运行,我有这个问题,因为:



1)内存限制:我的应用程序使用巨大的图像,IIS是内存有限的。

2)长时间运行的任务:somethime一个任务运行30-40分钟(做大量的查询处理负载数据ecc)这是IIS的一个问题。



我喜欢将应用程序划分为不知何故2个模块:

1)获取用户请求并调用其他模块的Web UI

2)服务器模块,用于从web ui接听电话。



所以,我的问题:我怎么能这样做?并且:这是一个很好的方法?



主要是我的服务器模块有问题:它必须是一个Windows服务?一些其他类型的os应用程序?

Hi,
I have an architecture question:
I wrote an enterprise 3-tier application, DDD approach, it runs in IIS and I have problems with this because:

1) Memory limit: my application work with huge images, and IIS is memory limited.
2) Long running task: somethime a task run for 30-40 minutes (doing tons of query processing loads of data ecc) this is an issue with IIS.

I like to divide the application "somehow" in 2 modules:
1) web UI that get user request and call the other module
2) server module that get the calls from web ui.

So, my questions: how can I do this? and: it is a good approach?

Mainly I have issues with the server module: It have to be a windows service? Some other kind os application?

推荐答案

使用Web服务/ WCF服务。

使用SQL查询优化技术。
Use web service/WCF service.
Use SQL query optimization techniques.


首先在Windows服务中实例化ServiceHost类。然后,在服务接口上,定义一个方法,该方法将启动长时间运行的进程。您可以使用leaders-followers模式来使用多个线程来处理请求。或者,在服务接口上使用单向方法,以便请求者不要等待Windows服务启动线程或其他任何操作。使用单向方法,您必须在服务上对请求进行排队。
Start by instantiating a ServiceHost class in a windows service. Then, on the service interface, define a method that would kick off your long running process. You can use the leaders-followers pattern to service requests using multiple threads. Alternatively, use a One-way method on your service interface so that the requestors don''t wait for the windows service to spin up a thread or whatever it would do. Using a One-way method you must then queue requests on your service.


我想,基本方案如下:

1)用户启动一个过程,给出参数 - 让我们称之为工作

2)你的应用程序开始做这项工作,并创建所需的输出

3)用户对他满意输出:)

我还想,你的服务器没有无限的资源,因此重负载会增加在单个请求期间测量的更多处理时间。



现在,在这种情况下,我建议采用以下方法:

1)将用户界面分为两部分:作业启动和收件箱,用于移交已完成的工作

2)根据该模型创建工作模型和队列。这可以是一个简单的数据库表,但对于复杂的工作来说更复杂。不要忘记将作业链接到发起者用户。

3)创建一个Windows服务,查找队列中的作业,完成作业并将附加到作业的结果存储在队列中。

4)完成的作业被添加到用户的收件箱中。您可以使用ajax调用来刷新客户端的收件箱和/或发送电子邮件以通知用户。

5)您必须根据一般的工作选择在Windows服务中实现的并行度级别,具体的工作参数和服务器上的负载。

6)你甚至可以通过更新工作本身的某种状态或进度信息来告知用户他的工作状态。 UI。



您可以通过生成流程来创建并从asp.net调用单独的应用程序 - 从而逃避您所知道的限制。但是这样您无法安排作业,整体资源限制会影响性能。 WCF可以处理异步调用,但你仍然必须在客户端处理异步性,我认为Windows服务更适合这种情况。
I suppose, the basic scenario is like following:
1) user initiates a the process, gives parameters - let'' call it job
2) your application is starting to do the job, and creates the desired output
3) user is happy with he output :)
I also suppose, that your server does not have unlimited resources, thus a heavy load would inrease even more processing time measured during single request.

Now, in this situation I suggest the following approach:
1) Separate your user interface in two: job initiation and "inbox" for handing over finished jobs
2) Create a job model and a queue based on that model. This can be a simple database table, but something more complicated something for a complex job. Don''t forget to link the job to the initiator user.
3) Create a windows service that looks for jobs in the queue, does the job and stores the result attached to the job in the queue.
4) The finished job is added to the inbox of the user. You can use ajax calls to refresh inbox on client side and/or send out email to notify user.
5) You have to choose the level of parallelism implemented in the windows service based on the job in general, the concrete job parameters and the load on the server.
6) You can even inform the user about the status of his jobs, by updating some sort of status or progress information on the job itself and the UI.

You could create and call a separate application from asp.net, by spawning a process - and thus escaping the limitations you know. But this way you could not schedule the jobs and the overall resource limits would impact performance. WCF can handle async calls, but you still have to handle asynchronicity on client side, and I think a windows service is more appropriate for such scenarios.


这篇关于IIS中长时间运行任务的最佳实践的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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