ASP.NET异步/等待第2部分 [英] ASP.NET async/await part 2
问题描述
我的好处 - 的 - 异步/ await-on-ASP.NET从<一个变化href=\"http://stackoverflow.com/questions/9867005/does-async-and-await-increase-performance-of-an-asp-net-application\">this问题。
我的理解是不同步是不一样的东西并行。因此,在Web服务器上,我不知道多少好处异步/等待带来的ASP.NET页面。
是不是IIS + ASP.NET已经在为请求分配线程真的很不错,如果onen页忙等待资源服务器将只需切换到该处理有工作要做另一个请求?
有线程池中,不过数量有限ASP.NET使用 - ?不异步使用他们的任何更有效地
由于飞碟双向先生在回答上述提问时指出,我们不是在谈论一个阻塞UI线程。我们已经在多线程,不能完成网页的响应,直到所有的请求的任务都做了,异步或没有,对不对?
我猜它归结为是这样的:
有什么好处异步读取一个资源(例如文件或DB要求)在ASP.NET页面与阻塞呢?
如果一个页面是忙等待资源服务器将只需切换到该处理有工作要做另一个请求?
块引用>我不这么认为。我会的非常的惊讶,如果是这样的话。这是理论上的可能,但非常复杂的。
有线程池中,不过数量有限ASP.NET使用 - ?不异步使用他们的任何更有效地
块引用>是的,因为当你
的await
的东西,线程该请求立即返回到池中。
我们已经是多线程的,不能完成网页的响应,直到所有的请求的任务都做了,异步或没有,对不对?
块引用>这是正确的。
异步
在服务器方案是所有关于线程池取出pressure。
有什么好处异步读取一个资源(例如文件或DB要求)在ASP.NET页面与阻塞呢?
块引用>当然!
如果您对文件/服务呼叫/分贝请求方框,则该线程用于该操作的持续时间。如果您
的await
文件/服务电话/ DB请求,则该线程立即返回到线程池中。一(太酷了!)这样的结果是,你可以有正在进行的要求,而这是(一)一些等待的操作,还有的没有的线程服务的要求!零线程的并发性,如果你愿意。
在操作完成后,该方法恢复后的
等待
- 从线程池(可能不同)线程在结论:
异步
鳞比线程好,所以肯定是在服务器端受益I have a variation of the benefits-of-async/await-on-ASP.NET from this question.
My understanding is that asynchrony is not the same thing as parallelism. So, on a web server, I wonder about how much benefit async/await brings to ASP.NET pages.
Isn't IIS+ASP.NET already really good at allocating threads for requests, and if onen page is busy waiting for a resource the server will just switch to processing another request that has work to do?
There are a limited number of threads in the pool for ASP.NET to use - does async use them any more effectively?
As Mr. Skeet pointed out in answering the question above, we're not talking about blocking a UI thread. We're already multi-threaded and the web response can't be completed until all the request's tasks are done, async or not, right?
I guess what it boils down to is this:
Is there any benefit to an async read of a resource (say a file or DB request) in an ASP.NET page vs. blocking on it?
解决方案if one page is busy waiting for a resource the server will just switch to processing another request that has work to do?
I don't think so. I would be very surprised if this were the case. It's theoretically possible, but very complex.
There are a limited number of threads in the pool for ASP.NET to use - does async use them any more effectively?
Yes, because when you
await
something, the thread for that request is immediately returned to the pool.We're already multi-threaded and the web response can't be completed until all the request's tasks are done, async or not, right?
That is correct.
async
in a server scenario is all about removing pressure on the thread pool.Is there any benefit to an async read of a resource (say a file or DB request) in an ASP.NET page vs. blocking on it?
Absolutely!
If you block on a file/service call/db request, then that thread is used for the duration of that operation. If you
await
a file/service call/db request, then that thread is immediately returned to the thread pool.One (really cool!) result of this is that you can have a request in progress, and while it's (a)waiting some operation, there are no threads servicing that request! Zero-threaded concurrency, if you will.
When the operation completes, the method resumes after the
await
- on a (possibly different) thread from the thread pool.In conclusion:
async
scales better than threads, so there is definitely a benefit on the server side.More info: my own intro to
async
post and this awesome video.这篇关于ASP.NET异步/等待第2部分的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!