ASP.NET:HttpModule 性能
我已经实现了一个 HttpModule,它拦截每个请求的响应流,并对每个文本/html 类型的响应运行六到十几个 Regex.Replace()。我担心我在这里遭受的性能影响有多大。有什么好方法可以查到吗?我想比较运行和不运行此 HttpModule 的速度。
I've implemented an HttpModule that intercepts the Response stream of every request and runs a half dozen to a dozen Regex.Replace()s on each text/html-typed response. I'm concerned about how much of a performance hit I'm incurring here. What's a good way to find out? I want to compare speed with and without this HttpModule running.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
我有一些连接到 Response.Filter 流管道来提供资源文件集成、JS/CSS 打包以及将静态文件重写为绝对路径。
只要您在 RegexBuddy 中测试正则表达式的速度超过几百万次迭代,请确保使用 RegexOptions.Compiled,并记住通常最快、最有效的技术是使用正则表达式来广泛识别匹配项,然后使用 C# 来磨练它正是您所需要的。
确保您还依赖于缓存和配置。
我们在这方面取得了很大的成功。
I've a few of these that hook into the Response.Filter stream pipeline to provide resource file integration, JS/CSS packing and rewriting of static files to absolute paths.
As long as you test your regexes in RegexBuddy for speed over a few million iterations, ensure you use RegexOptions.Compiled, and remember that often the quickest and most efficient technique is to use a regex to broadly identify matches and then use C# to hone that to exactly what you need.
Make sure you're also caching and configuration that you rely upon.
We've had a lot of success with this.
Http 模块只是一段常见的代码,因此您可以测量这个特定的正则表达式替换内容的执行时间。这就足够了。将一组典型的响应流作为压力测试的输入,并使用 Stopwatch 类测量替换的执行情况。另请考虑
RegexOptions.Compiled
开关。Http module is just common piece of code, so you can measure time of execution of this particular regex replace stuff. It is enough. Have a set of typical response streams as input of your stress test and measure executing of the replace using
Stopwatch
class. Consider alsoRegexOptions.Compiled
switch.以下是一些想法:
Here are a few ideas:
我最近必须对我编写的 HTTPModule 进行一些 pef 测试,并决定执行一些负载测试来模拟 Web 流量并捕获配置和未配置模块的性能时间。这是我真正了解安装模块的影响的唯一方法。
我通常会使用 Apache Bench 做一些事情(请参阅以下内容了解如何安装,如何在 Windows 7 上安装 apache bench?),但我还必须使用 Windows 身份验证。由于
ab
仅具有基本身份验证,因此它不适合我。ab
很灵活,允许不同的请求场景,因此这将是第一个要查看的地方。另一种想法是,您也可以通过使用 glimpse 获得大量可见性。由于我无法使用
ab
我编写了一些自定义内容,允许并发请求并测试不同的 url 时间。以下是我测试该模块时想到的内容,希望对您有所帮助!
I recently had to do some pef tests on an HTTPModule that I wrote and decided to perform a couple of load tests to simulate web traffic and capture the performance times with and without the module configured. It was the only way I could figure to really know the affect of having the module installed.
I would usually do something with Apache Bench (see the following for how to intsall, How to install apache bench on windows 7?), but I had to also use windows authentication. As
ab
only has basic authentication I it wasn't a fit for me.ab
is slick and allows for different request scenarios, so that would be the first place to look. One other thought is you can get a lot of visibility by using glimpse as well.Being that I couldn't use
ab
I wrote something custom that will allow for concurrent requests and test different url times.Below is what I came up with to test the module, hope it helps!