I've read that using Task.Run in an ASP.NET web app was a bad idea as it uses another thread from the thread pool and hence prevent this particular thread from being used to serve a request.
Isn't the same situation with Parallel.ForEach? Won't it use multiple threads from the thread pool and hence prevent these particular threads from being used to serve a request ?
Isn't the same problem with Parallel.ForEach? Won't it use multiple threads from the thread pool and hence prevent these particular threads from being used to serve a request?
Yes, it will. This means that you'd be decreasing the total throughput of your server by having requests using up multiple requests like this. That individual request would complete faster, but it would complete faster at the expense of other requests.
This also assumes that your machine is under a high load. If there isn't a sufficiently high load on the thread pool, then it could afford to dedicate more resources for that request without inhibiting the ability of other requests to be served, and dedicating more resources for that request may well speed up that request.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With