lundi 21 octobre 2019

Async or multithread for 200+ requests with C# HttpClient

I did some research before but could not find any related answers to my current problem. I have situation where in my ASP.NET Core Web API I have method that receives an list of address names, and should return back list of geolocations for each address from request. Method that does job need to make request to an external provider API which receives through query address name and returns back gelocation info, but only ONE by ONE request, and we must use that one API for client requirements.

My question is, do you think that, for sake of performance, is better to go with async await method that simply make request through one shared HttpClient instance, and just put result in the list when response awaited, or to go with multithread solution and build whole mechanism with maybe 4 threads and one shared resource(list for putting results in). Address list will count at average maybe 200-300 address names, but can in some situations goes up to 1000, but very rare. Me personally think that async execution will work fine, it is much simpler than building whole multithread process(that I am not so much familiar with). After the first call I will also use IMemoryCache to cache geolocations to web server cache so every next time I won't make request to external API, but instead will retrieve geolocations from cache using address name as key.

I would appreciate your opinion on this problem, thanks in advance.




Aucun commentaire:

Enregistrer un commentaire