views:

82

answers:

4

Hi,

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!

+1  A: 

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

torak
It's possible but it is hard to correlate the requests with the server thread handling the request. I intend to test simultaneous requests.
Miguel Pardal
+1  A: 

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.

Simon Groenewolt
Thanks for your help, but the Filter is only invoked after the HTTP request processing.
Miguel Pardal
A: 

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:

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 Managing Tomcat to figure out how to access these MBeans with JMX.

matt b
The Valve has a similar problem to the Filter. It is only invoked after the HTTP request is parsed.I'll look into the JMX option. Thanks!
Miguel Pardal
I don't think this is true. Looking at the Javadocs, some Valves do pre-processing work, then they invoke the next valve in the pipeline, and then they do post-processing work (such as the RequestDumperValve and ReplicationValve). When you invoke the next Valve, control returns to you after that valve (and all the valves that it invokes) returns. You can do the same with filters.
matt b
A: 

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

artemv