'First time creating HttpRequestMessage instance takes time

Hello I have a problem I have an application which are hosted in OpenShift and I noticed that after deploying or restarting pods application first call is very slow. It takes more than 1 second just to create Request Message. After some debugging with Stopwatch I see that first time creating HttpRequestMessage

    var watch1 = System.Diagnostics.Stopwatch.StartNew();

    var request = new HttpRequestMessage()
    {
        RequestUri = new Uri(OriginalEndpoint),
        Method = HttpMethod.Post,
        Content = new StringContent(requestBody, Encoding.UTF8, "application/json")
    };

    watch1.Stop();
    Console.WriteLine("Create request HttpRequestMessage: " + elapsedMs1);

always takes more than 1 second. enter image description here I tried to do separate warmup service for creating HttpRequestMessage and doing actual call.

    var request = new HttpRequestMessage()
    {
        RequestUri = new Uri("http://Example"),
        Method = HttpMethod.Get,
        Content = new StringContent(requestBody, Encoding.UTF8, "application/json")
    };

    var response = _igcApiClient.HttpClient.SendAsync(request).Result;

But after my warmup service creates RequestMessage it still takes more than one second to create original request message in other class for the first time. So maybe someone had similar problems or have some ideas how to warmup an application without calling original endpoint in warmup service.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source