ASP.NET:如何处理并行请求
让我们想象一下网站上有 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
由于 asp.net 会话锁定,如果两个请求使用具有读/写访问权限的相同会话状态,则必须在服务器端按顺序处理请求。
您可以在这里找到更多信息:
http://msdn.microsoft.com/en-us/library/ie /ms178581.aspx
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
你原来的想法是对的,文档也是对的。 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.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.