.Net TPL:具有任务优先级的有限并发级别任务调度程序?
我目前正在使用此处详细介绍的 LimitedConcurrencyLevelTaskScheduler http://msdn.microsoft.com/en -us/library/ee789351.aspx
我想增强这一点,以便可以为个人任务分配优先级。这些优先级不需要映射到线程优先级。它应该只影响任务启动的顺序。
有谁知道这样的任务调度程序的例子? (很多调度的事情超出了我的能力范围,所以如果有一个现有的解决方案那就太好了)
I am currently using the LimitedConcurrencyLevelTaskScheduler detailed here http://msdn.microsoft.com/en-us/library/ee789351.aspx
I want to enhance this so that individuals tasks can be assigned priority. These priorities need not map to thread priority. It should only influence the order in which tasks are started.
Does anyone know of an example of such a task scheduler? (a lot of the scheduling stuff is over my head so it would be great if there was an existing solution)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
Parallel Extensions Extras Samples. 已经提供了这样的调度程序,即 QueuedTaskScheduler。该调度程序提供优先级、并发限制、公平性以及对所使用线程的类型和优先级的细粒度控制。当然,您不必使用或配置不需要的功能。
Stephen Toub 在此处
要使用 QueuedTaskScheduler,请根据需要的优先级调用其 ActivateNewQueue 方法。此方法返回一个新的 TaskScheduler 派生的 Queue 对象,该对象由父 TaskScheduler 管理。所有使用特定队列的任务都由父 TaskScheduler 根据其优先级进行调度。
以下代码创建一个最大并发级别为 4 的调度程序、两个优先级队列,并在第一个队列上调度一个任务:
The Parallel Extensions Extras Samples. already provide such a scheduler, the QueuedTaskScheduler. This scheduler provides priorities, concurrency limits, fairness and fine-grained control over the type and priorities of the threads used. Of course, you don't have to use or configure the features you don't need.
Stephen Toub provides a brief description of the various schedulers in the Parallel Extensions Extras here
To use the QueuedTaskScheduler, you call its ActivateNewQueue method with the priority you need. This method returns a new TaskScheduler-derived Queue object managed by the parent TaskScheduler. All tasks that use a specific queue are scheduled by the parent TaskScheduler according to their priorities.
The following code creates a scheduler with a maximum concurrency level of 4, two priority queues and schedules a task on the first queue:
对任务列表使用某种排序或优先级数据结构。然后创建您自己的包含优先级的添加。这可能不如其他好,但它会优先考虑任务列表。您可以在那里重用 99% 的代码。只需将 LinkedList 替换为 Sorted List 或使用 LINQ 排序并编写一个具有优先级的方法 add 即可。
Use some sorted or priority data structure for the task list. Then create your own add that takes in the Priority. This may not be as good as others but it will prioritize Tasks List. You can reuse 99% of the code there. Simply replace LinkedList with a Sorted list or use LINQ to sort and write a method add that takes the priority.