有多少任务太多? [英] How many tasks are too many?

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

问题描述

我目前正在对依赖于许多不同的Web服务来获取数据的应用程序。因为我想每一个模块化服务,有一点依赖在那里,我跑在了自己的任务,每个服务(服务1必须服务2和3等之前运行)。

I'm currently working on an application that relies on many different web services to get data. Since I want to modularize each service and have a bit of dependency in there (service1 must run before service 2 and 3 etc), I'm running each service in its own task.

任务本身或者是


  1. 主动运行,这意味着他们将自己的请求发送到Web服务,并正在等待回应或处理响应

  1. running actively, meaning they're sending their request to the web service and are waiting for a response or processing the response

等待(通过监控器和超时) - 一旦任务完成所有等待任务唤醒,并检查它们的依赖已完成

waiting (via monitor and timeout) - once a task finishes all waiting tasks wake up and check if their dependencies have finished

现在,该系统是与我所说的良好的性能(特别是因为性能而忽略不计)运行 - 然而, ,应用程序产生相当多的任务

Now, the system is running with what I would call good performance (especially since the performance is rather negligible) - however, the application generates quite a number of tasks.

所以,我的问题:是〜在这种情况下200的任务太多了?难道他们产生太多的开销,这样一个基本的非线程的方式会更好?

So, to my question: are ~200 tasks in this scenario too many? Do they generate that much overhead so that a basically non-threaded approach would be better?

推荐答案

一般的答案是措施,测量,测量:)如果你没有遇到性能的任何问题,你不应该开始优化。

The general answer is "Measure, Measure, Measure" :) if you're not experiencing any problems with performance, you shouldn't start optimizing.

我说200的任务都很好,虽然。相比于线程任务的优点是其低开销相比,真实的主题,甚至线程池。所述的TaskScheduler是确保所有的硬件线程被利用尽可能与线程切换最少。它通过各种招数吸作为运行的子任务,连续,窃取工作从其他线程等队列。

I'd say 200 tasks are fine though. The beauty of tasks compared to threads is their low overhead compared to "real" threads and even the thread pool. The TaskScheduler is making sure all the hardware threads are utilized as much as possible with the least amount of thread switching. it does this by various tricks suck as running child tasks serially, stealing work from queues on other threads and so on.

您也可以给的TaskScheduler关于什么是一些提示具体任务是要通过 TaskCreationOptions

You can also give the TaskScheduler some hints about what a specific task is going to do via the TaskCreationOptions

如果你想要一些数字,看看这篇文章,你可以看到,太平人寿也便宜架空结果$ b条款$ b HTTP://www.palmmedia。德/博客/ 2010/1/19 /净-40-性能的任务并行库-TPL

If you want some numbers, check out this post, as you can see, Tpl is pretty cheap in terms of overhead
http://www.palmmedia.de/Blog/2010/1/19/net-40-performance-of-task-parallel-library-tpl

这是另一个有趣的文章标的结果
http://msdn.microsoft.com/en-us/magazine /cc163552.aspx

This is another interesting article on the subject
http://msdn.microsoft.com/en-us/magazine/cc163552.aspx

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

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