Asynchronous processing in SQL Server vs. .NET Asynchronous processing

后端 未结 5 2007
情深已故
情深已故 2021-01-02 23:25

What\'s is the advantage of using Asynchronous processing in SQL Server over .NET Asynchronous processing? Aren\'t they the same? I have a hard time to understand what is th

5条回答
  •  醉酒成梦
    2021-01-02 23:50

    As mentioned in the earlier answers, BeginInvoke uses a .NET thread. Equally important, though, is that thread comes from the ASP.NET thread pool, so it competes with clients for the very limited thread resources. The same is true for ThreadPool.QueueUserWorkItem().

    The SqlClient async calls require a SqlConnection that has async=true enabled. That mode requires a little more network overhead (which is why it's not enabled by default), but it doesn't consume a thread from the .NET thread pool. Instead, it uses async I/O.

    The advantage of the latter approach is that it's much more scalable. You can process hundreds or thousands of simultaneous requests that way, where the overhead with a thread-per-call would be extreme. Plus, you would consume the entire ASP.NET thread pool very quickly (it only has a maximum of around 12 threads by default).

提交回复
热议问题