IIS、Asp.NET 管道和并发性

发布于 2024-07-08 22:06:58 字数 1388 浏览 8 评论 0原文

我想知道 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();
}

我期望如果我几乎同时在多个浏览器选项卡中浏览到 Web 应用程序根目录,它们将同时启动和停止。 然而,他们似乎并不这么认为。 第二个选项卡的开始时间与第一个选项卡的结束时间相同。 然后,我通过在 httpmodule 或 default.aspx page_load 中使用相同的代码进行测试,并得到相同的结果。

这里发生了什么? 为什么请求不被并行处理?

编辑:我的理解主要集中在两篇文章上:

http://msdn.microsoft.com/en-us/magazine/cc188942.aspx 表示“如果针对同一应用程序的多个请求同时到达,则将使用多个 HttpApplication 对象。”

http://www.code-magazine.com/article .aspx?quickid=0511061&page=5 有一个 aspx 页面的示例,基本上执行我测试的操作,并带有注释“模拟慢速请求,以便我们可以并排看到多个请求”。 在 Thread.Sleep 调用旁边

我可能完全误解了某些东西......但是什么?

http://www.code-magazine.com/article。 aspx?quickid=0511061&page=5

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:

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.

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."

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

It is possible that I'm completely misunderstanding something... but what?

http://www.code-magazine.com/article.aspx?quickid=0511061&page=5

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

用心笑 2024-07-15 22:06:58

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

在应用程序开始崩溃之前,您需要创建足够的请求来耗尽 ASP.NET 线程池。

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

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.

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

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.

幽梦紫曦~ 2024-07-15 22:06:58

呵呵。 问题出在谷歌浏览器上。 我在其中打开了两个选项卡,似乎当它们指向相同的 url 时,请求会按顺序发送,一个在另一个完成后!

不过还是谢谢你的想法!

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!

Thanks for ideas though!

吝吻 2024-07-15 22:06:58

为什么不修改示例来打印线程 ID? 这将告诉您是否有多个线程同时处理请求。 我敢打赌。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文