IIS,Asp.NET管道和并发

时间:2020-12-17 03:30:26

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("<br />");
    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 个解决方案

#1


3  

Each request that arrives is routed to a separate HttpApplication object. The HttpApplication object is either created from scratch or allocated from a pool. The maximum number of HttpApplication objects created is limited by the maximum number of threads available. In ASP.NET 1.x I think the default was 20 or so. Under ASP.NET 2.0 this limit is managed dynamically.

到达的每个请求都将路由到单独的HttpApplication对象。 HttpApplication对象可以从头开始创建,也可以从池中分配。创建的HttpApplication对象的最大数量受可用线程的最大数量限制。在ASP.NET 1.x中,我认为默认值是20左右。在ASP.NET 2.0下,此限制是动态管理的。

You would need create enough requests to exhaust the ASP.NET thread pool before seeing your application start to falter.

在看到应用程序开始动摇之前,您需要创建足够的请求以耗尽ASP.NET线程池。

What the comment in the Code article means is not that his code is bottlenecking the server, he's using it as a way to be able to see the state multiple requests side by side such as different thread ID's.

Code文章中的注释意味着他的代码不是瓶颈服务器,他正在使用它作为一种方式,能够并排查看状态多个请求,例如不同的线程ID。

#2


3  

Heh. The problem was Google Chrome. I opened two tabs in it and it seems when they point to same url that the requests get sent sequentially, one after the other has completed!

嘿。问题是Google Chrome。我在其中打开了两个标签,看起来当它们指向相同的网址时,请求按顺序发送,一个接一个地完成!

Thanks for ideas though!

谢谢你的想法!

#3


1  

Why don't you modify the sample to print the thread ID? That will tell you if multiple threads are serving the requests concurrently. I bet it is.

为什么不修改样本来打印线程ID?这将告诉您多个线程是否同时为请求提供服务。我敢打赌。

#1


3  

Each request that arrives is routed to a separate HttpApplication object. The HttpApplication object is either created from scratch or allocated from a pool. The maximum number of HttpApplication objects created is limited by the maximum number of threads available. In ASP.NET 1.x I think the default was 20 or so. Under ASP.NET 2.0 this limit is managed dynamically.

到达的每个请求都将路由到单独的HttpApplication对象。 HttpApplication对象可以从头开始创建,也可以从池中分配。创建的HttpApplication对象的最大数量受可用线程的最大数量限制。在ASP.NET 1.x中,我认为默认值是20左右。在ASP.NET 2.0下,此限制是动态管理的。

You would need create enough requests to exhaust the ASP.NET thread pool before seeing your application start to falter.

在看到应用程序开始动摇之前,您需要创建足够的请求以耗尽ASP.NET线程池。

What the comment in the Code article means is not that his code is bottlenecking the server, he's using it as a way to be able to see the state multiple requests side by side such as different thread ID's.

Code文章中的注释意味着他的代码不是瓶颈服务器,他正在使用它作为一种方式,能够并排查看状态多个请求,例如不同的线程ID。

#2


3  

Heh. The problem was Google Chrome. I opened two tabs in it and it seems when they point to same url that the requests get sent sequentially, one after the other has completed!

嘿。问题是Google Chrome。我在其中打开了两个标签,看起来当它们指向相同的网址时,请求按顺序发送,一个接一个地完成!

Thanks for ideas though!

谢谢你的想法!

#3


1  

Why don't you modify the sample to print the thread ID? That will tell you if multiple threads are serving the requests concurrently. I bet it is.

为什么不修改样本来打印线程ID?这将告诉您多个线程是否同时为请求提供服务。我敢打赌。