Skip to content
This repository was archived by the owner on Dec 19, 2018. It is now read-only.
This repository was archived by the owner on Dec 19, 2018. It is now read-only.

Asp.NET Core have pure behavior when await #1058

Description

@bnayae

When I compare ASP.NET and ASP.NET Core Web API (over IIS Express).
It's seem that even those I'm awaiting Task.Delay it doesn't handle the next request and behave like
having Thread Pool starvation.

the following code work great on ASP.NET and poor on ASP.NET Core

public async Task<string> Get(int id)
{
    Debug.Write(".");
    await Task.Delay(TimeSpan.FromSeconds(2));
    return $"#{id:00}";
}

I was testing it with the following code (using 50 concurrent request):

        private static async Task CallAsync(int times)
        {
            var sw = Stopwatch.StartNew();
            using (var http = new HttpClient())
            {
                var tasks = from i in Enumerable.Range(0, times)
                            let url = $"{BASE_URL}/{i}"
                            select InvokeAsync(http, url);
                string[] responses = await Task.WhenAll(tasks);
            }
            sw.Stop();
            Console.WriteLine($"\r\n\r\nTOTAL DURATION: {sw.Elapsed.TotalSeconds:N3} seconds");
        }

        private static async Task<string> InvokeAsync(HttpClient http, string url)
        {
            var latency = Stopwatch.StartNew();
            Console.Write("-");
            string response = await http.GetStringAsync(url);
            latency.Stop();
            Console.Write($"{latency.Elapsed.TotalSeconds:0.0}, ");
            return response;
        }

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions