ASP.NET性能的Request.Form [英] ASP.NET Request.Form Performance

查看:309
本文介绍了ASP.NET性能的Request.Form的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我用了一个的HttpHandler 实施针对高性能轻型Web服务。它需要一个 POST 与内容类型应用程序/ x-WWW的形式urlen codeD 。 Web服务做了很多任务,包括解密,数据库的工作,业务逻辑等。在负载测试,性能监视器(蚂蚁和Visual Studio)指向code,它走的是大部分时间的单行线,其实67%。

I used a HttpHandler to implement a light-weight web service targeted for high performance. It requires a POST with content-type application/x-www-form-urlencoded. The web service does many tasks including decryption, database work, business logic and so on. During load testing, the performance monitor (ANTS and Visual Studio) point to a single line of code that is taking the majority of time, in fact 67%.

string value = context.Request.Form[MY_FORM_KEY];

在这一行code,性能监控,调用堆栈的底部说,这电话:

At the bottom of the call stack for this line of code, the performance monitor, says this call:

System.Web.Hosting.UnsafeIISMethods.MgdSyncReadRequest();

是罪魁祸首。

谁能帮助请解释一下?该应用程序是在.NET 4中,出版发行,IIS 7,Windows Server 2008上。

Can anyone help please explain?! The application is in .Net 4, published as release, IIS 7, on Windows Server 2008.

感谢您,
乔伊J.巴雷特

Thank you, Joey J. Barrett

推荐答案

时的时间延迟,因为IIS试图从客户端读取请求的流来检索表单值。这种流是受客户端连接,在某些原因,甚至不会回来。我看到那里的Request.Form会阻止5分钟的情况下,这将导致IIS最终抛出ThreadAbortException。

Time delay occurs because IIS tries to read request stream from the client to retrieve form values. This stream is subject to client connection and in some causes will not even return. I have seen cases where Request.Form would block for over 5 minutes and it would cause IIS to eventually throw ThreadAbortException.

在我们的例子中,我们有一个HttpModule是必须通过的Request.Form值(或请求[钥匙],它重于形式值迭代以及)读取,它会在服务器上随机阻止和永远不会回来。我用这个的HttpModule来跟踪服务器端应用程序的性能,这让我意识到,什么我跟踪使用此模块也将依赖于客户端的连接,这会歪曲我的服务器端执行的结果。

In our case, we had an HttpModule that had to read through Request.Form values (or request["key"] which iterates over form values as well) and it would randomly block on the server and would never return. I used this HttpModule to track application performance on server side, which made me realize that anything I track using this module will also be dependent on client's connectivity, which would skew my server-side execution results.

要解决这个问题,你可以在你的应用程序的安装前反向HTTP代理。反向代理服务器将关闭加载阅读客户端流(在你的应用程序拦截昂贵的线程)的责任,并发送完整的请求到服务器。这将减少对应用程序的负载,因为你可以节省您的precious应用程序线程与您的主要工作量处理,而不是阻止他们从客户端的流读取。

To resolve this issue, you can install reverse HTTP proxy in front of your application. Reverse proxy will off-load the responsibility of reading client stream (and blocking an expensive thread in your application) and send complete request to your server. This will reduce the load on your application, because you can save your precious application threads for dealing with your main workload rather than blocking them for reading from client streams.

另外,你可以分载HTTPS时,负载均衡,甚至在缓存反向代理一些静态内容(取决于你使用哪一个)。

In addition, you can off-load HTTPs, load-balance, and even cache some static content on your reverse proxy (depending on which one you use).

这篇关于ASP.NET性能的Request.Form的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆