dxa-web-application-dotnet
dxa-web-application-dotnet copied to clipboard
reuse HttpClient object / SNAT port exhaustion
Hello,
We've been seeing SNAT port exhaustion in our DXA application when traffic is heavy and we have a lot of requests to the RWS content delivery endpoint. One of the recommendations from Azure, where we host our origin servers, is "For C# applications, ensure that the HttpClient object is created once and reused again."
See: https://docs.microsoft.com/en-us/azure/architecture/antipatterns/improper-instantiation/#how-to-fix-the-problem.
I have been told: Lots of http client usages (including DXA) would recreate the http client which is what is causing the issue. This needs to be a shared instance.. the only way to fix this would be to make code changes in DXA. DXA is open source and not supported It would need to be done in the area below:
https://github.com/RWS/dxa-web-application-dotnet/blob/develop/Sdl.Web.Tridion/ApiClient/ApiClientFactory.cs#L166
Thanks Marshall
Marshall,
But that line points to a GraphQLClient object (https://github.com/RWS/graphql-client-dotnet/blob/develop/net/src/Sdl.Tridion.Api.Client/GraphQLClient/GraphQLClient.cs) which uses its own internal IHttpClient object (https://github.com/RWS/graphql-client-dotnet/blob/develop/net/src/Sdl.Tridion.Api.Client/HttpClient/HttpClient.cs) which itself uses System.Net.WebRequest internally, not HttpClient (https://github.com/RWS/graphql-client-dotnet/blob/develop/net/src/Sdl.Tridion.Api.Client/HttpClient/HttpClient.cs#L174)