在SQL Server与.NET异步处理异步处理 [英] Asynchronous processing in SQL Server vs. .NET Asynchronous processing

查看:119
本文介绍了在SQL Server与.NET异步处理异步处理的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

什么是使用SQL Server异步处理过.NET异步处理的优势在哪里?他们不是一样吗?我也很难理解什么是SQL Server而不是.NET APM采用异步处理的好处。我可以很容易地包装在一个lambda EX pression一个SQL调用,并做了BeginInvoke的(......)。

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 the benefit of using Asynchronous processing in SQL Server instead of .NET APM. I can easily wrap a SQL call in a lambda expression and do a BeginInvoke(...).

有人可以帮助我的差异,双方的利益?

Can someone help me the difference and the benefit of both?

推荐答案

使用.NET异步处理(的BeginInvoke(...))的是,这一切的问题做的是分拆一个线程同步处理code。只需5分钟。查询将占用一个线程5分钟,阻塞(如什么都不做的〜99%的时间),而结果被计算在远端。在株(许多查询一次),这将耗尽线程池,占用所有线程处于阻塞状态。线程池会变得反应迟钝和新的工作要求将遭受很大的延时等待线程池火了额外的线程。这不是预期的使用线程池的,因为它的设计以期望它被要求完成任务是是短暂的和无阻塞。

The problem with .NET asynchronous processing (BeginInvoke(...)) is that all this is doing is spinning off a thread to process the code synchronously. A 5 minute query will tie up a thread for 5 minutes, blocking (i.e. doing nothing for ~99% of the time) while a result is calculated at the remote end. Under strain (many queries at once) this will exhaust the threadpool, tying up all threads in a blocked state. The threadpool will become unresponsive and new work requests will suffer big latency waiting for the threadpool to fire up extra threads. This is not the intended use of the threadpool, as it is designed with the expectation that the tasks it is asked to complete are to be short-lived and non-blocking.

使用开始/ EndAction APM对,人们可以在一个非阻塞方式调用相同的动作,并且只有当所述结果是通过它被排队作为线程池工作项一个IO完工口返回。没有你的线程都绑在过渡期间,并在此排队的响应处理时,数据可意味着用户code IO上不挡,可以快速完成......一个更有效用它可以扩展到更多的客户端请求,而每个优秀的操作线程的成本线程池的。

With Begin/EndAction APM pairs, one can invoke the same action in a non-blocking way, and it is only when the result is returned via an IO completion port that it is queued as a work item in the threadpool. None of your threads are tied up in the interim, and at the point that the queued response is dealt with, data is available meaning user code does not block on IO, and can be completed quickly... a much more efficient use of the threadpool which scales to many more client requests without the cost of a thread per outstanding operation.

这篇关于在SQL Server与.NET异步处理异步处理的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆