如何分析 spring mvc 应用程序的页面请求
在 spring mvc 应用程序中,我必须使用哪些选项来分析页面请求?
我想详细了解页面请求需要多长时间,以及各个阶段,例如渲染 freemarker 模板、hibernate 数据库调用等需要多长时间。
what options do I have to profile a page request in a spring mvc app?
I want to get a breakdown of how long the page request takes, along with the various stages like how long it takes to render the freemarker template, hibernate db calls, etc.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我们刚刚使用拦截器和自定义标签完成了类似的事情。该解决方案足够“轻”,足以在生产中使用,将其数据以 HTML 注释的形式显示在响应的底部,并允许您选择使用请求参数进行更详细的日志记录。您可以将下面的拦截器应用到您想要分析的所有请求路径,并将自定义标记添加到所需页面的底部。自定义标签的位置很重要;它应该尽可能接近请求处理结束时调用,因为它只知道调用之前花费的时间(和加载的对象)。
自定义标记查找请求属性,并使用它们来计算处理程序时间、查看时间和总时间。它还可以查询当前 Hibernate 会话的一级缓存统计信息,这可以揭示处理程序和视图加载了多少对象。如果不需要 Hibernate 信息,可以删除大的
if
块。We just accomplished something similar with an interceptor and a custom tag. This solution is "light" enough to be used in production, presents its data as HTML comments at the bottom of the response, and allows you to opt into the more verbose logging with a request parameter. You apply the interceptor below to all request paths you want to profile, and you add the custom tag to the bottom of the desired pages. The placement of the custom tag is important; it should be invoked as close to the end of request processing as possible, as it's only aware of time spent (and objects loaded) prior to its invocation.
The custom tag looks for the request attributes, and uses them to compute the handler time, the view time, and the total time. It can also query the current Hibernate session for first-level cache statistics, which can shed some light on how many objects were loaded by the handler and view. If you don't need the Hibernate information, you can delete the big
if
block.请查看此处:
在 Linux 上使用 Eclipse 和远程分析代理进行分析
教程:使用 TPTP 和 Tomcat 进行分析
使用 TPTP 分析 Java 应用程序简介
TPTP = Eclipse 测试和性能工具平台
更多堆栈链接:
Java 中的开源分析器
Take a look here:
Profiling with Eclipse and remote profile agents on Linux
Tutorial: Profiling with TPTP and Tomcat
An introduction to profiling Java applications using TPTP
TPTP = Eclipse Test and Performance Tools Platform
More links to the stack:
Open Source Profilers in Java