如何在套接字级别拦截 Tomcat 请求?
我正在对在 Apache Tomcat 6 上运行的 Web 应用程序框架进行性能研究。
我正在尝试测量处理 HTTP 请求的时间开销。
我想做的是:
//
// just before first request byte is read
long t1 = System.nanoTime();
// request is processed...
// just after final byte is written to response
long t2 = System.nanoTime();
然后
我会计算总时间(t2 - t1)。
有办法做到这一点吗?感谢您的帮助!
I'm doing a performance study for a web application framework running on Apache Tomcat 6.
I'm trying to measure the time overhead of handling HTTP requests.
What I would like to do is:
/
// just before first request byte is read
long t1 = System.nanoTime();
// request is processed...
// just after final byte is written to response
long t2 = System.nanoTime();
/
Then I would compute the total time (t2 - t1).
Is there a way to do this? Thanks for your help!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
跟踪此问题的最佳方法可能是使用 Valve。
但如果 Tomcat 导出的 MBean 中尚未对此进行跟踪,我会感到惊讶。特别是,MBean
Catalina:name=http-,type=GlobalRequestProcessor
列出了以下属性:查看有关 监控和管理 Tomcat 以了解如何使用 JMX 访问这些 MBean。
The best way to track this is probably with a Valve.
But I would be surprised if this isn't already tracked in the MBeans that Tomcat exports. In particular, the MBean
Catalina:name=http-<my port num>,type=GlobalRequestProcessor
lists the following attributes:Take a look at the documentation on Monitoring and Managing Tomcat to figure out how to access these MBeans with JMX.
一种替代方法是使用 Wireshark。
One alternative, that wouldn't require any coding at all, is to look at the network traffic with a tool like Wireshark.
我认为您可以通过添加 Filter 并在调用 doFilter 之前和之后将计时代码放在过滤器链的其余部分上。
I think you can achieve this by adding a Filter and put your timing code before and after your call to doFilter on the rest of the filter chain.
AspectJ 你的解决方案。使用它,您可以对应用程序 CL(但不能通过引导 CL)加载的类执行任何操作。
AspectJ you solution. Using it you can do anything__ with classes loaded by application CL(but not by bootstrap CL).