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•3y ago
Message Not Public
Sign In & Join Server To View
will do, ty
Unknown User•3y ago
Message Not Public
Sign In & Join Server To View
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•3y ago
Message Not Public
Sign In & Join Server To View
it's not bad practice at all
Unknown User•3y ago
Message Not Public
Sign In & Join Server To View
✅ This post has been marked as answered!