ASP.net - 如何区分页面处理时间和客户端传输时间
博客中的单个计时栏自然包括客户端传输计时。 对于分析,我想将构建时间过长的页面与客户端速度较慢的请求区分开来。
对于缓冲页面,我查看了 ASP.NET 页面生命周期模型,但没有看到可以在哪里利用并以代码方式测量页面刷新到客户端之前的页面处理时间。
我可能应该提到我的目标是生产监控(而不是测试或开发)。 此外,目的是用此测量值对博客进行注释,以供以后分析。 目前,我们使用 Response.AppendToLog() 自由地注释博客。 我相信使用 Response.AppendToLog() 的愿望在某种程度上限制了我潜在的日志点,例如,响应对象在 Application_EndRequest 中不可行。
任何见解将不胜感激。
The single timing column in the weblog naturally includes client transmission timing. For anamoly analysis, I want to differentiate pages that took excessive construction time from requests that simply had a slow client.
For buffered pages, I've looked at the ASP.NET page lifecycle model and do not see where I can tap in and codewise measure just the page-processing time before the page is flushed to the client.
I probably should have mentioned that my goal is production monitoring (not test or dev). In addition, the intent is to annotate the weblogs with this measurement for later analysis. Current we liberally annotate the weblogs with Response.AppendToLog(). I believe the desire to use Response.AppendToLog() somewhat limits my potential logpoints as for instance, the response-object is not viable in Application_EndRequest.
Any insight would be appreciated.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
您可以在 BeginRequest 和 PreSendRequestContent 中使用秒表,如其他两个答案中所述,或者您可以仅在 PreSendRequestContent 中使用请求的时间戳。
例如,在 SingingEels 上,我将其添加到我的母版页的底部(是的,这是一个黑客) :
<%=DateTime.Now.Subtract(HttpContext.Current.Timestamp).TotalSeconds %>
这样我就可以看到任何页面在服务器上实际执行所需的时间,包括访问数据库, ETC。
You could use a Stopwatch in the BeginRequest and the PreSendRequestContent as mentioned in the other two answers, or you could just use the request's Timestamp in the PreSendRequestContent.
For example, on SingingEels, I added this to the bottom of my Master Page (yes, it's a hack) :
<%=DateTime.Now.Subtract(HttpContext.Current.Timestamp).TotalSeconds %>
That way I can see how long any page took to actually execute on the server, including hitting the database, etc.
最简单的方法可能是在 global.asax 文件中使用以下事件:
protected void Application_BeginRequest(Object sender, EventArgs e)
protected void Application_EndRequest(Object sender, EventArgs e)
您还可以实现自定义 httpmodule
the easist way would probably be to use the follow events in the global.asax file:
protected void Application_BeginRequest(Object sender, EventArgs e)
protected void Application_EndRequest(Object sender, EventArgs e)
You could also implement a custom httpmodule
如果您想登录特定页面,我相信 asp.net 页面的生命周期以 PreInit 开始并以 Dispose 结束,因此您可以在这些事件中记录您想要的任何内容。
或者,如果您想登录每个页面,正如 Bob Dizzle 指出的那样,您可以使用 Global.asax 文件,该文件有一千个事件可供选择:http://msdn.microsoft.com/en-us/library/2027ewzw.aspx
If you want to log on a specific page, I believe asp.net pages' lifecycle begin with PreInit and end with Disposed, so you can log anything you want in those events.
Or, if you want to log on every page, as Bob Dizzle pointed out, you can use the Global.asax file, which has a thousand events to choose from : http://msdn.microsoft.com/en-us/library/2027ewzw.aspx
您还可以在 Web 服务器上进行测试。 然后 ClientTransmission 时间实际上变为 0。
You could also do your testing right there on the web server. Then ClientTransmission time becomes effectively 0.
这取决于您拥有的性能工具的功能集。 但如果您只需要记录处理时间,那么您可以采用这种方法。
如果您只想要特定页面,那么您可以在 BeginRequest 事件中检查这一点。
应用程序事件可以附加在 Global.asax 中。
This depends on the feature set of the performance tools you have. But if you just need to log the processing time then you could follow this approach.
If you just want a specific page then you could check for this in the BeginRequest event.
The application events can be attached in Global.asax.