question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Performance Impact due to HttpClient Socket Closure on `SignAsync`

See original GitHub issue

We notice that our calls to SignAsync KeyVault operation averages around 800ms with some requests taking as long as 1.5s. We profiled your code focusing and found that the HTTP send request is the biggest bottleneck. In other words, this line: _httpResponse = await HttpClient.SendAsync(_httpRequest, cancellationToken).ConfigureAwait(false);

Digging through Wireshark logs, we find that the HTTPClient closes the underlying TCP socket in ~1.5s. So requests before this 1.5s window, get a response in ~90ms and requests after the TCP closure get response between 800ms and 1.5s. I am assuming that the TCP closure causes a new set of SSL handshake + some additional logic on the server that takes longer time(?)

image

What would be your recommendation to mitigate this bottleneck? Also, why is the server taking a longer time to respond after the TCP Socket close?

Note:

  • TCP Socket closure might just be the observed side-effect of the real problem but the repros are consistent that way.
  • This issue is not in reference to the first call after KeyVaultClient initialization, which is always longer because of no Bearer token caching(HttpBearerChallengeCache) and hence the longer route through KeyVaultCredential.PostAuthenticate.
  • This prolonged server response is not observed with couple of other calls that we use - GetKeyAsync, GetSecretAsync.

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Reactions:1
  • Comments:11 (6 by maintainers)

github_iconTop GitHub Comments

1reaction
RandalliLamacommented, Jun 1, 2018

@marty2bell Please raise a ticket against the service. That will get it tracked by the correct people for a server side issue.

0reactions
marty2bellcommented, Jun 1, 2018

@herveyw

We are seeing the same behaviour talking to KeyVault…we haven’t went to the network level as far as @antonydeepak went, but we are definitely seeing outliers on our soak tests where decrypt calls to keyvault to taking over a minute to come back.

I was going to raise a ticket against the service, but could piggy back onto this issue ??

Cheers

Marty

Read more comments on GitHub >

github_iconTop Results From Across the Web

Why does HttpClient leave sockets open?
Each instance of HttpClient pools its connections for better performance, but this means that each instance also leaves the pooled ...
Read more >
You're using HttpClient wrong and it is destabilizing your ...
My site was unstable and my clients furious, with a simple fix performance improved greatly and the instability disapear.
Read more >
Beware of the .NET HttpClient - Hi, I am Nima
One naive easy workaround is to set the keep-alive header to false so the socket will be closed after each request, this obviously...
Read more >
Using HttpCompletionOption to Improve HttpClient ...
I'll explain how you can optimise the performance of HttpClient when handling data such as JSON payloads on the HttpResponseMessage .
Read more >
HttpClient guidelines for .NET
Learn about using HttpClient instances to send HTTP requests and how you can manage clients using IHttpClientFactory in your .NET apps.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found