RWS / dxa-web-application-dotnet

SDL Digital Experience Accelerator .NET MVC web application
Apache License 2.0
19 stars 35 forks source link

reuse HttpClient object / SNAT port exhaustion #87

Open cmstroscio opened 2 years ago

cmstroscio commented 2 years ago

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

neilgibbons commented 2 years ago

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)