0

In an ASP.NET Web Api project with the SessionState disabled, if I create the following:

public class MyController : ApiController
{
        [Route("doTheThing")]
        public async Task DoTheThing()
        {
            Debug.WriteLine($"Start DoTheThing");
            await Task.Delay(30000);
            Debug.WriteLine($"End DoTheThing");
        }
}

And call this endpoint 100x times at once from another app, I get the output:

Start DoTheThing (x100)
(delay)
End DoTheThing (x100)

So far so good, everything is ran concurrently.


However with the following:

public class MyController : ApiController
{
        [Route("doTheThing")]
        public async Task DoTheThing()
        {
            Debug.WriteLine($"Start DoTheThing");
            await Task.Run(() => Thread.Sleep(30000)); // A busy thread
            Debug.WriteLine($"End DoTheThing");
        }
}

I get the output:

Start DoTheThing
Start DoTheThing
Start DoTheThing
(delay)
Start DoTheThing
(delay)
Start DoTheThing
(delay)
...
End DoTheThing (x100)

We lost (some of) the concurrency, Which is less than ideal. I believe this is due to a limit by client connection (safety limit) but couldn't find the culprit.

How can I configure this thread limit?

Thurfir
  • 65
  • 9

0 Answers0