如何提高使用System.Threading.Task的应用程序的性能 [英] How do I improve performance of an application that uses System.Threading.Task
本文介绍了如何提高使用System.Threading.Task的应用程序的性能的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
对于在主(应用程序)线程中分配所有任务的基于任务的应用程序(处理n个客户端),我计划为每个客户分配一个线程并为每个线程分配任务。性能如何?任何建议都会很棒..提前谢谢。
For a task based application (handles n number of clients) that assigns all the tasks in main (application) thread, I plan to assign each customer a thread and assign task to each thread. How will be the performance? Any suggestion would be great..thanks in advance.
推荐答案
线程
s资源非常昂贵所以分配一个每个客户都不具有可扩展性,但拥有一个线程池(通常远低于客户数量)并根据请求将工作分配给这些线程。
任务
s是重量较轻的处理单元,可以在后台运行线程并且扩展得更好。
一般答案您的性能问题是:它取决于您的处理性质,因此您必须对其进行测试。
Thread
s are resource expensive so assigning one to each customer is not scalable but having a pool of threads (usually much lower than the number of customers) and assigning work to those threads is per request is.
Task
s are lighter weight processing units which work on threads in the background and scale much better.
The general answer to your question of performance is : it depends on the nature of your processing, so you must test it.
这篇关于如何提高使用System.Threading.Task的应用程序的性能的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文