How would you break down and log the execution times of different parts of your application?

We have built a web application that accepts SOAP messages, does some processing, calls out to another web service, massages the response and sendd it back to the original caller.

We’d like to log, in a single line, the different execution times for these different steps. We use log4j with the JBossWS stack. In other words, we’d like the log output to look something like:

2009-06-10T16:19:31.487 3336/2449/861

where 3336ms is the total time spent serving the request, 2449ms is the time spent waiting for the web service’s response, and 861ms is the time spent internally massaging the data.

These different computations happen in different places in our code and we cannot just time each one of them and make a call to the logger at the end of a single method. One of us has suggested using log4j’s MDC for this as a poor man’s set of global variables to track the different executions times.

So my questions are the following:

  1. Is this a horrible abuse of the MDC’s primary intent?
  2. If yes, how would you do this otherwise?

Answer

Please have a look at SLF4J profiler. Interestingly enough. tt was developed to answer the exact same need, that is to measure and improve the performance of SOAP calls.

Leave a Reply

Your email address will not be published. Required fields are marked *