问题描述
我需要在我的Web服务器来执行一些活动/职位,如索引的一些信息,组织一些文件,并计算一些统计数据...
I need to execute some activities/jobs in my Web Server, such as indexing some information, organizing some files, and calculating some statistics...
我想保留我的Web服务器(性能,内存消耗,...)的QoS。所以我想执行外部进程作为这些活动的,而不是调用中创建线程。类似的东西来(它启动的子进程来处理请求)。
I want to preserve the QoS in my Web Server (performance, memory consumption, ...). So I'm thinking of executing an external process for these activities, instead of calling in a thread. Something similar to Apache MPM processer (it launches child processes to process the requests).
- 请知道要做这件事?
- 请您知道任何图书馆的最佳解决方案可以为我做到这一点?
在先进的感谢。
推荐答案
好了,我终于实现了一个系统中的外部进程来执行的任务/作业。
Well, I finally implemented a system to execute tasks/jobs in a external process.
如果有人想知道我是如何实现它,这里有一些细节。也许我会写一篇文章共享解决方案和源代码。
If someone want to know how I implemented it, here are some of the details. Maybe I will write an article to share the solution and the source code.
基本上,我们有两个组成部分,在 Web.dll
(ASP.NET应用程序)和一个名为 TaskExecutor.exe
Basically, we have two components, the Web.dll
(ASP.NET application) and a program called TaskExecutor.exe
在<$ C程序$ C> Web.dll 中,有一个活动调度器,它可以通过名称注册任务:例如:
In the Web.dll
, there is an activity scheduler that can register tasks by name: for example:
ActivityScheduler.Get().RegisterActivity("GenerateSearchIndexes", 4 * 1000 * 60 * 60); //each 2 hours
活动调度执行的线程每一个活动,并且此线程调用外部过程中, ActivityExecutor.exe
该组件有一个参考的 Web.dll
具有静态ActivityFactory得到活动。外部进程的源代码非常简单:
This assembly has a reference to the Web.dll
that has a static ActivityFactory to get the activities. The source code of the external process is quite simple:
public static void Main (string[] args)
{
try
{
if (args.Length == 0)
{
throw new ArgumentException("No activity name given", "ActivityName");
}
//parameter 0 is the activity name
string activityName = args[0];
IScheduledActivity activity = ActivityFactory.GetActivity(activityName);
if (activityName != null)
{
activity.Execute(args);
}
}
catch (Exception ex)
{
Console.WriteLine("Error executing activity: " + ex.Message);
}
}
正如你可以在这里猜测的限制是活动必须静态定义,所以他们不能在其构造函数接收paramenters。该传递在 IScheduledActivity.Schedule(字串[] args)
方法,以同样的方式作为节目会怎么做。
As you can guess the restriction here is that the activities must be statically defined, so they cannot receive paramenters in its constructor. The are passed in the IScheduledActivity.Schedule(string[] args)
method, in the same way as a program would do.
这篇关于实施ASP.NET MVC作业调度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!