Should I offload work with other threads in ASP.NET?

I am creating an ASP.NET web API where certain operations (synchronous, legacy code) can take some time (mostly IO is limited, but some of them also require intensive computation).

I understand that each incoming request is assigned a thread from the thread pool, but I'm a little fuzzy. Is the request stream “special” in some way, ensuring that work is offloaded to other threads to avoid blocking it? Will unloading help with thread pool starvation and rejected requests? And if so, do I need to create an async shell for each potentially long-lasting function to the end, or do I need only one asynchronous oberter at the highest level?

+4
source share
1 answer

Creating asynchronous shells for lengthy tasks is pointless in the context of ASP.NET and does nothing but degrade performance in several ways.

Executing synchronous methods asynchronously in a thread pool thread makes sense when offloading a GUI thread or other special thread. In this case, the method should be called asynchronously by the caller in this special thread, depending on how the caller is suitable (using, for example Task.Run, which, as a rule, should not be used when implementing the async method). However, in ASP.NET there are only threads thread threads, and no one needs (and really should not) unload them this way for several reasons.

( concurrency #) Task.Run : .

ASP.NET ( , ASP.NET, ). , , ASP.NET Task.Run.

[...]

, , , - .

​​ASP.NET.

:

+4

Source: https://habr.com/ru/post/1694860/


All Articles