作者:admin | 来源:互联网 | 2023-05-17 04:19
Imwonderinghowtheconcurrencyinawebapplicationactuallyworks.Ivereadseveralarticlesand
I'm wondering how the concurrency in a web application actually works. Ive read several articles and to my understanding multiple instances of HttpApplication would be working at the same time. Now, I created a simple web app to test concurrency and put the following to global.asax:
我想知道Web应用程序中的并发性是如何实际工作的。我已经阅读了几篇文章,据我所知,HttpApplication的多个实例将同时工作。现在,我创建了一个简单的Web应用程序来测试并发性,并将以下内容放到global.asax中:
protected void Application_BeginRequest(object sender, EventArgs e)
{
Response.Write("Request started: " + DateTime.Now);
System.Threading.Thread.Sleep(10000);
Response.Write("
");
Response.Write("Request ended: " + DateTime.Now);
Response.End();
}
I was expecting that if I browse to the web app root in several browser tabs at nearly the same time, they would start and stop concurrently. However, it seems that they don't. Second tab start time is same as first time end time. I then tested by having this same code in an httpmodule or default.aspx page_load and got the same result.
我期待如果我几乎在同一时间浏览几个浏览器标签中的Web应用程序根目录,它们将同时启动和停止。但是,似乎他们没有。第二个标签开始时间与第一个结束时间相同。然后我通过在httpmodule或default.aspx page_load中使用相同的代码进行测试,得到了相同的结果。
What is going on here? Why aren't the requests being served parallel?
这里发生了什么?为什么请求并行服务?
Edit: I'm placing my understanding mainly to two articles:
编辑:我将理解主要放在两篇文章中:
http://msdn.microsoft.com/en-us/magazine/cc188942.aspx says "If multiple requests targeting the same application arrive simultaneously, multiple HttpApplication objects will be used."
http://msdn.microsoft.com/en-us/magazine/cc188942.aspx说“如果针对同一个应用程序的多个请求同时到达,将使用多个HttpApplication对象。”
and http://www.code-magazine.com/article.aspx?quickid=0511061&page=5 has an example for an aspx page doing basically what I tested, with comment "Simulate slow request so we can see multiple requests side by side." next to Thread.Sleep call
和http://www.code-magazine.com/article.aspx?quickid=0511061&page=5有一个aspx页面的例子基本上做我测试的,注释“模拟慢请求所以我们可以看到多个请求并排“。在Thread.Sleep调用旁边
It is possible that I'm completely misunderstanding something... but what?
我可能完全误解了什么......但是什么?
http://www.code-magazine.com/article.aspx?quickid=0511061&page=5
3 个解决方案