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!

+2


a source to share


4 answers


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.

+1


a source


One alternative that doesn't require any coding at all is to look at network traffic with a tool like Wireshark .



+1


a source


I think you can achieve this by adding a Filter and putting your timecode before and after your doFilter call on the rest of the filter chain.

+1


a source


AspectJ's solution you. Using it, you can do anything__ with classes loaded by a CL application (but not with bootstrap CL).

0


a source







All Articles