.NET框架来管理单独计算机上的后台运行进程 [英] .Net framework to manage background running processess on seperate machines

查看:77
本文介绍了.NET框架来管理单独计算机上的后台运行进程的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个驻留在服务器上的asp.mvc应用程序.我想从该应用程序启动一个过程,该过程有点长时间运行,并且会占用大量资源.

I am having an asp.mvc application which resides on a server.From this application, I want to start a process which is a bit long-running operation and will be resource intensive operation.

所以我想做的是要有一个像3这样的用户代理,它将在3台计算机上存在,并且该用户代理将仅使用各自计算机的资源.

So what I want to do is I want to have some user agent like 3 which will be there on 3 machines and this user agent will use resources of their respective machines only.

像Hadoop中一样,我们有主节点和集群,其中任务在单个集群上运行,并且有1个主节点跟踪所有这些集群.

Like in Hadoop we have master nodes and cluster in which tasks are run on the individual cluster and there is 1 master node keeping track of all those clusters.

在Azure中,我们有运行任务的虚拟机,如果需要,Azure可以通过扩展新实例来自动水平扩展以加快任务的速度.

In Azure, we have virtual machines on which tasks are run and if require Azure can automatically scale horizontally by spinning up the new instance in order to speed up the task.

因此,我想创建这样的基础结构,在该基础结构中,我可以将任务从mvc应用程序提交给3个用户代理,并且我的应用程序将跟踪该代理,例如哪个代理是免费的,哪个代理被占用,哪个代理无法正常工作.这个.

So I want to create infrastructure like this where I can submit my task to 3 user agents from the mvc application and my application will keep track of this agents like which agent is free, which is occupied, which is not working something like this.

我希望收到每个用户代理的进度,并在我的MVC应用程序中显示.

I would like to receive progress from each of this user agent and show on my MVC application.

.net中是否有任何框架可以用来管理后台运行操作(跟踪,启动,停止等),或者应该采用什么方法?

Is there any framework in .net from which I can manage this background running operations(tracking, start, stop etc..) or what should be the approach for this?

更新:我不想为这种长时间运行的操作增加服务器负载,而且我也想跟踪这种长时间运行的过程,就像它们在做什么,在哪里出错等.

Update : I don't want to put loads of server for this long running operations and moreover I want to keep track of this long running process too like what they are doing, where is error etc.

以下是我正在考虑的方法,我不知道哪种方法更有意义:

Following are the approach which I am thinking and I don't know which will make more sense:

1)在本地以2-3台计算机的代理程序形式安装Windows服务,以利用resp资源并打开与该代理程序的tcp/ip连接,除非并且直到长期运行完成为止.

1) Install Windows Service in the form of agents of 2-3 computer on premises to take advantage of resp resources and open a tcp/ip connection with this agents unless and until the long running process is complete.

2)使用hangfire在IIS线程之外运行此长时间运行的进程,但我想这会给服务器带来负担.

2) Use hangfire to run this long running process outside of IIS thread but I guess this will put load on server.

我想知道上述方法的可能问题以及是否有比此更好的方法.

I would like to know possible problems of above approaches and if there are any better approaches than this.

推荐答案

Hangfire 确实是一个很好的处理解决方案后台任务,我们已经在项目中广泛使用了它.

Hangfire is really a great solution for processing background tasks, and we have used used it extensively in our projects.

我们已经在单独的IIS服务器(也是hangfire客户端)上设置了MVC应用程序,只是排队了需要由hangfire服务器执行的作业.然后,我们有两个hangfire服务器实例,它们是Windows服务应用程序.因此,由于MVC应用服务器正在由单独的hangfire服务器处理,因此实际上没有任何负载可以处理后台作业.

We have setup our MVC application on separate IIS servers which is also a hangfire client and just enqueues the jobs needs to be executed by hangfire server. Then we have two hangfire server instances, which are windows service application. So effectively there is no load on the MVC app server to process the background jobs, as it is being processed by separate hangfire servers.

hangfire的一项非常有用的功能是其开箱即用的仪表板,它使您可以监视和控制后台作业处理的任何方面,包括统计信息,后台作业历史记录等.

One of the extremely helpful feature of hangfire is its out of the box dashboard, that allows you to monitor and control any aspect of background job processing, including statistics, background job history etc.

在应用程序以及hangfire服务器中配置hangfire

Configure the hangfire in application as well as in hangfire servers

public void Configuration(IAppBuilder app)
{
    GlobalConfiguration.Configuration.UseSqlServerStorage("<connection string or its name>");

    app.UseHangfireDashboard();
    app.UseHangfireServer();
}

请注意,您使用相同的连接字符串.仅当您要将实例用作hangfire服务器时才使用app.UseHangfireServer(),因此在您的情况下,您希望从应用程序服务器配置中省略此行,仅在hangfire服务器中使用. 另外,在实例中使用app.UseHangfireDashboard()可以为您的hangfire仪表板提供服务,这很可能是您的MVC应用程序.

Please note that you use the same connection string across. Use app.UseHangfireServer() only if you want to use the instance as hangfire server, so in your case you would like to omit this line from application server configuration and use only in the hangfire servers. Also use app.UseHangfireDashboard() in instance which will serve your hangfire dashboard, which would be probably your MVC application.

那时我们已经使用Windows Service完成了,但是如果现在必须这样做,我想使用

At that time we have done it using Windows Service, but if had to do it now, I would like to go with Azure worker role or even better now Azure Web Jobs to host my hangfire server, and manage things like auto scaling easily.

请参考hangfire 概述

Do refer hangfire overview and documentation for more details.

这篇关于.NET框架来管理单独计算机上的后台运行进程的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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