C
C#2y ago
pip

Concurrent REST requests best practices if any? [Answered]

Reading a lot online on if running REST requests with something like a Task.WhenAll is actually a good practice. I've gotten mixed responses so far. I'm aware that if you use HttpClient directly and some requests fail, you'll exhaust all of your ports over time. There's some methodology to prevent this(like using an alternate request queue instead of relying on HttpClient), but I guess my question boils down to -> is running REST requests concurrently bad practice? If it isn't, can you provide links/info for best practices?
8 Replies
Unknown User
Unknown User2y ago
Message Not Public
Sign In & Join Server To View
pip
pip2y ago
will do, ty
Unknown User
Unknown User2y ago
Message Not Public
Sign In & Join Server To View
Cisien
Cisien2y ago
using http client, even with failed requests doesn't lead to port exhaustion -- that's caused by destroying and re-creating your http client handler it's mitigated by using HttpClientFactory, or (mostly) by using HttpClient with a SocketsClientHandler which pools connections internally that handler is default in .net 6 Task.WhenAll is fine, the requests won't necessarily run concurrently, if that's your goal you're leaving it up to the async framework to schedule work, which is often on i/o threads and/or the thread pool
Unknown User
Unknown User2y ago
Message Not Public
Sign In & Join Server To View
Cisien
Cisien2y ago
it's not bad practice at all
Unknown User
Unknown User2y ago
Message Not Public
Sign In & Join Server To View
Accord
Accord2y ago
✅ This post has been marked as answered!