How does Task Parallel Library scale on a terminal server or in a web application?

女生的网名这么多〃 提交于 2019-12-24 01:29:10

问题


I understand that the TPL uses work-stealing queues for its tasks when I execute things like Parallel.For and similar constructs.

If I understand this correctly, the construct will spin up a number of tasks, where each will start processing items. If one of the tasks complete their allotted items, it will start stealing items from the other tasks which hasn't yet completed theirs. This solves the problem where items 1-100 are cheap to process and items 101-200 are costly, and one of the two tasks would just sit idle until the other completed. (I know this is a simplified exaplanation.)

However, how will this scale on a terminal server or in a web application (assuming we use TPL in code that would run in the web app)? Can we risk saturating the CPUs with tasks just because there are N instances of our application running side by side?

Is there any information on this topic that I should read? I've yet to find anything in particular, but that doesn't mean there is none.


回答1:


You might be able to use the TPL to improve I/O bound operations by moving to an asynchronous model. You might also be able to improve request latency by making more use of the available unused processor capacity on a web server in low load situations. You want to think about this pretty carefully as under high loads where the processors are already 100% utilized adding more parallelism will reduce throughput on the server.

This is discussed on the Parallel Extensions Team Blog:

Using Parallel Extensions for .NET 4 in ASP.NET apps

I suspect that the same argument applies to Terminal Server applications also.



来源:https://stackoverflow.com/questions/2753273/how-does-task-parallel-library-scale-on-a-terminal-server-or-in-a-web-applicatio

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!