TPL 中的最大任务数?

发布于 2024-10-13 01:13:59 字数 217 浏览 5 评论 0原文

我想在 Windows Azure 上的工作进程中使用 TPL。我希望在队列中添加一个 IJob,它有一个 Run 方法,因此工作线程将包括

: 将项目从队列中取出 使用 TPL 调用 IJob.Run,​​这是一个异步调用

,但我有点担心可以添加到 TPL 的最大项目数?如果需要的话,我很乐意构建自己的某种 TPL 池,只是检查它的功能。

干杯, 灰。

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:

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

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.

Cheers,
Ash.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

み零 2024-10-20 01:13:59

TPL 的主要目标之一是消除对此的担忧。通过将您的工作分解为任务而不是线程,您可以让调度程序更适当地处理此任务的平衡。

您可以安排的“任务”数量没有固定的上限。它们(默认情况下,使用默认的 TaskScheduler)使用 ThreadPool 进行调度,从 .NET 4 开始,ThreadPool 根据工作进行扩展。我强烈建议不要尝试建立自己的池 - 你不太可能比默认的池做得更好。话虽这么说,如果您的任务有非常不标准的行为,您可能需要考虑编写自定义 TaskScheduler。

另外 - 认识到理想情况下你应该让你的任务“尽可能大”。与单个任务相关的开销 - 让它们太小(就工作而言)将导致开销对性能产生比适当数量的较大“任务”更大的影响。

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.

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 your 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".

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文