在TPL最大的任务? [英] Max tasks in TPL?

查看:159
本文介绍了在TPL最大的任务?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在Windows Azure上的工作进程使用TPL。我期待添加一个IJob队列中,这有一个Run方法,因此工人将包括:

I want to use TPL in Worker process on Windows Azure. I'm looking to add an IJob the queue, this has a Run method, so the worker will consist of:

循环
    获得项目关闭队列
    使用TPL调用IJob.Run,​​这是一个异步调用

loop get item off queue Use TPL to call IJob.Run, this is an async call

不过,我很担心,我可以添加到TPL的最大项目一点?我很高兴,如果需要建立一些我自己的TPL游泳池,只是检查它的能力。

But I'm a bit concerned about the maximum items I can add to TPL? I'm happy to build my own TPL Pool of some sort if required, just checking it capabilities.

干杯,
灰。

推荐答案

之一TPL的主要目标是去除不用担心这一点。通过分解你的工作分成任务而不是线程,你允许调度程序能够更妥善处理这一平衡。

One of the main goals of the TPL is to remove the need to worry about this. By decomposing your work into Tasks instead of Threads, you're allowing the scheduler to handle the balancing of this more appropriately.

有没有固定的上限的任务的数量就可以安排。他们是(默认情况下,默认的TaskScheduler)使用线程池,这是.NET 4,秤根据工作计划。我强烈建议不要试图建立自己的游泳池 - 这是极不可能的,你会做比默认的好。话虽这么说,如果你的任务有一个非常不规范的行为,你可能要考虑编写自定义的TaskScheduler。

There is no fixed upper limit to the number of "tasks" you can schedule. They are (by default, with the default TaskScheduler) scheduled using the ThreadPool, which as of .NET 4, scales based on the work. I would strongly suggest not trying to build your own pool - it's highly unlikely that you'll do better than the default. That being said, if you're tasks have a very non-standard behavior, you may want to consider writing a custom TaskScheduler.

此外 - 要知道,你应该,理想情况下,让你的任务是越大越好。还有就是开销单个任务相关的 - 让他们过小(以工作而言)将导致开销会对性能产生较大的影响比如果您有较大的任务的适当数量

Also - realize that you should, ideally, make your tasks as "large as possible". There is overhead associated with an individual task - having them be too small (in terms of work) will cause the overhead to have a larger impact on performance than if you have an appropriate number of larger "tasks".

这篇关于在TPL最大的任务?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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