ASP.NET:如何处理并行请求

发布于 2024-09-28 15:00:52 字数 537 浏览 3 评论 0原文

让我们想象一下网站上有 2 个页面:快速页面和慢速页面。对慢速页面的请求执行 1 分钟,对快速页面的请求执行 5 秒。

在我的整个开发生涯中,我认为如果第一个启动的请求很慢:他将对数据库进行(同步)调用...等待答案...如果在此期间完成对快速页面的请求,则该请求将在同时处理系统正在等待 DB 的响应。

但今天我发现: http://msdn.microsoft.com/en-us/library /system.web.httpapplication.aspx

HttpApplication 类的一个实例用于在其生命周期内处理许多请求。但是,它一次只能处理一个请求。因此,成员变量可用于存储每个请求的数据。

难道说我原来的想法是错误的吗?

您能澄清一下它们的意思吗?我很确定事情正如我所期望的那样......

Let's imaging there are 2 pages on the web site: quick and slow. Requests to slow page are executed for a 1 minute, request to quick 5 seconds.

Whole my development career I thought that if 1st started request is slow: he will do a (synchronous) call to DB... wait answer... If during this time request to quick page will be done, this request will be processed while system is waiting for response from DB.

But today I've found:
http://msdn.microsoft.com/en-us/library/system.web.httpapplication.aspx

One instance of the HttpApplication class is used to process many requests in its lifetime. However, it can process only one request at a time. Thus, member variables can be used to store per-request data.

Does it mean that my original thoughts are wrong?

Could you please clarify what they mean? I am pretty sure that thing are as I expect...

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

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

发布评论

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

评论(3

云雾 2024-10-05 15:00:52

由于 asp.net 会话锁定,如果两个请求使用具有读/写访问权限的相同会话状态,则必须在服务器端按顺序处理请求。

您可以在这里找到更多信息:
http://msdn.microsoft.com/en-us/library/ie /ms178581.aspx

并发请求和会话状态

对 ASP.NET 会话状态的访问是每个会话独占的,这意味着如果两个不同的用户并发请求,则同时授予对每个单独会话的访问权限。但是,如果对同一会话发出两个并发请求(通过使用相同的 SessionID 值),则第一个请求将独占访问会话信息。第二个请求仅在第一个请求完成后执行。 (如果由于第一个请求超过锁定超时而释放了信息上的独占锁,则第二个会话也可以获得访问权限。)如果@ Page 指令中的 EnableSessionState 值设置为 ReadOnly,则只读请求会话信息不会导致会话数据上的独占锁定。但是,对会话数据的只读请求可能仍需要等待对会话数据的读写请求设置的锁被清除。

The requests have to be be processed in the sequential order on the server side if the both request use the same session state with read/write access, because of asp.net session locking.

You can find more information here:
http://msdn.microsoft.com/en-us/library/ie/ms178581.aspx

Concurrent Requests and Session State

Access to ASP.NET session state is exclusive per session, which means that if two different users make concurrent requests, access to each separate session is granted concurrently. However, if two concurrent requests are made for the same session (by using the same SessionID value), the first request gets exclusive access to the session information. The second request executes only after the first request is finished. (The second session can also get access if the exclusive lock on the information is freed because the first request exceeds the lock time-out.) If the EnableSessionState value in the @ Page directive is set to ReadOnly, a request for the read-only session information does not result in an exclusive lock on the session data. However, read-only requests for session data might still have to wait for a lock set by a read-write request for session data to clear.

守望孤独 2024-10-05 15:00:52

你原来的想法是对的,文档也是对的。 IIS 工作进程可以生成许多线程,每个线程都有自己的 HttpApplication 类实例。

Your original thoughts are right, and so is the documentation. The IIS worker process can spawn many threads, each with their own instance of the HttpApplication class.

两相知 2024-10-05 15:00:52

ASP .NET 将在单个工作进程 (w3wp.exe) 下为您的 Web 应用程序托管多个 AppDomain。它甚至可以在同一工作进程下共享不同 Web 应用程序的 AppDomain(如果它们被分配到同一应用程序池)。

ASP .NET 创建的每个 AppDomain 都可以托管多个 HttpApplication 实例,这些实例为请求提供服务并遍历 ASP .NET 生命周期。每个 HttpApplication 可以(正如您所说)一次响应一个请求。

ASP .NET will host multiple AppDomains for your web application under a single worker process (w3wp.exe). It may even share AppDomains for different web applications under the same worker process (if they are assigned to the same app pool).

Each AppDomain that ASP .NET creates can host multiple HttpApplication instances which serve requests and walk through the ASP .NET lifecycle. Each HttpApplication can (as you've said) respond to one request at a time.

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