Can PLINQ or TPL strangle the .net thread pool and IIS request processing queue?

Here is the script. Gateway hosted by IIS. A request may require the issuance of several independent other requests to another service, each of which may take up to several seconds. Naturally, I thought it was a good candidate for parallelization. However, I have an internal struggle if I do this, and if so, to what extent parallelism, if any, should I use. My concern is that all threads in the application are usually controlled by the .net thread pool, so if I end up allocating too many threads (even waiting), can I strangle other gateway and API functions?

+5
source share
2 answers

PLINQ , . - Async I/O.

- .NET: APM, TPL, , # 5 async/, F # async workflows. - .

Async I/O . /, .

: (IIS) - , , .

:

Task.Factory.StartNew( () => Parallel.ForEach<Item>(items, item => DoSomething(item)));

, , / DoSomething.

, DoSomething - , . 3 , 10 30 . .

I/O , , , .

, TPL , :

var tasks = new Task<System.Net.WebResponse>[2];
var urls = new string[] { "https://stackoverflow.com/", "http://google.com/" };
for (int i = 0; i < tasks.Length; i++)
{
    var wr = (System.Net.HttpWebRequest)System.Net.WebRequest.Create(urls[i]);
    tasks[i] = Task.Factory.FromAsync<System.Net.WebResponse>(
                   wr.BeginGetResponse,
                   wr.EndGetResponse,
                   null);
}

var result = Task.Factory.ContinueWhenAll(
    tasks,
    results => {
        foreach (var result in results)
        {
            var resp = result.Result.GetResponseStream();
            // Process responses and combine them into single result
        }
    });

, 90% - . WebRequest BeginGetResponse, , (TPL, Rx ..).

+8

. , . , -, , . " ". "", .

.

, . , , ( 500-1000 ( = 250)). , , . , , .

, async - , , . 100 . # 5.0, async/await IO.

+3

All Articles