How can I intercept Tomcat request at socket level?
I am researching performance for a web application framework running on Apache Tomcat 6.
I am trying to measure the overhead of handling HTTP requests.
What I would like to do:
/
// 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 calculate the total time (t2 - t1).
Is there a way to do this? Thanks for your help!
a source to share
The best way to track this is probably with Valve .
But I would be surprised if this is not already tracked in the MBeans that Tomcat exports. Specifically, the MBean Catalina:name=http-<my port num>,type=GlobalRequestProcessor
lists the following attributes:
BytesSent = 51829989
bytesReceived = 0
processingTime = 11464
ERRORCOUNT = 8
maxTime = 1250
requestCount = 923
modelerType = org.apache.coyote.RequestGroupInfo
Take a look at the documentation on Monitoring and Controlling Tomcat to figure out how to access these MBeans using JMX.
a source to share