HI @JoshBerry-1267,
You can control the number of HttpClient
opened by using a singleton via AddHttpClient
. To limit the number of connections your HttpClient
uses, you can set MaxConnectionsPerServer to value less than 1K. Getting this right can be tricky so it's advised that you start a low number and increase if needed.
// add to ConfigureServices
services.AddHttpClient(Options.DefaultName).ConfigurePrimaryHttpMessageHandler(()=>
{
return new HttpClientHandler()
{
MaxConnectionsPerServer = 500
};
});
EDIT: The above won't apply to Angular as ASP.NET Core will spin up a Node.js process. The following however, https://zcusa.951200.xyz/en-us/azure/app-service/app-service-web-nodejs-best-practices-and-troubleshoot-guide#my-node-application-is-making-excessive-outbound-calls may help. It suggests using agentKeepAlive
options on your http object to control connections being made.
let keepaliveAgent = new Agent({
maxSockets: 32,
maxFreeSockets: 10,
timeout: 60000,
keepAliveTimeout: 300000
});
Regards,
Ryan