.NET HttpClient GET request very slow after ~100 seconds idle
<p>The first request or a request after idling roughly 100 seconds is very slow and takes 15-30 seconds.  Any request without idling takes less than a second.  I am fine with the first request taking time, just not the small idle time causing the slowdown.</p>

<p>The slowdown is not unique to the client, if I keep making requests on one client then it stays quick on the other.  Only when all are idle for 100 seconds does it slowdown.</p>

<p>Here are some changes that I have tried:</p>

<ul>
<li>Setting <strong>HttpClient</strong> to a singleton and not disposing it using a using() block</li>
<li>Setting <strong>ServicePointManager.MaxServicePointIdleTime</strong> to a higher value since by default it is 100 seconds.  Since the time period is the same as mine I thought this was the issue but it did not solve it.</li>
<li>Setting a higher <strong>ServicePointManager.DefaultConnectionLimit</strong></li>
<li>Default proxy settings set via web.config</li>
<li>using <strong>await</strong> instead of <strong>httpClient.SendAsync(request).Result</strong></li>
</ul>

<p>It is not related to IIS application pool recycling since the default there is set to 20mn and the rest of the application remains quick.</p>

<p>The requests are to a web service which communicates with AWS S3 to get files.  I am at a loss for ideas at this point and all my research has led me to the above points that I already tried.  Any ideas would be appreciated!</p>

<p>Here is the method:
`</p>

<pre><code>//get httpclient singleton or create
var httpClient = HttpClientProvider.FileServiceHttpClient;
var queryString = string.Format("?key={0}", key);

var request = new HttpRequestMessage(HttpMethod.Get, queryString);

var response = httpClient.SendAsync(request).Result;
if (response.IsSuccessStatusCode)
{

    var metadata = new Dictionary&lt;string, string&gt;();
    foreach (var header in response.Headers)
    {
        //grab tf headers
        if (header.Key.StartsWith(_metadataHeaderPrefix))
        {
            metadata.Add(header.Key.Substring(_metadataHeaderPrefix.Length), header.Value.First());
        }
    }

    var virtualFile = new VirtualFile
    {
        QualifiedPath = key,
        FileStream = response.Content.ReadAsStreamAsync().Result,
        Metadata = metadata
    };
    return virtualFile;
}
return null;
</code></pre>