aarondcoleman / Fitbit.NET

Fitbit .NET API Client Library
MIT License
193 stars 138 forks source link

Limit concurrent connections to Fitbit API #289

Closed timfitabase closed 3 years ago

timfitabase commented 3 years ago

There needs to be a way to limit concurrent connections to the Fitbit API to prevent resource exhaustion during times of high throughput. Before .NET Core, this was done using ServicePointManager in the calling code when using FitbitClient.CreatePipeline to create a reusable HttpClient instance.

But ServicePointManager does not work with .Net Core. The best way to approach this would be to have an optional parameter on FitbitClient.CreatePipeline() that gets used to populate MaxConnectionsPerServer on FitbitHttpMessageHandler.InnerHandler.

WestDiscGolf commented 3 years ago

How will the Http handler keep track of the number of current connections?

WestDiscGolf commented 3 years ago

I didn't realise there was a property on HttpClientHandler which could manage this for you. Just in case anyone else stumbles across this issue - https://docs.microsoft.com/en-us/dotnet/api/system.net.http.httpclienthandler.maxconnectionsperserver?view=net-5.0

👍