user3626166
user3626166

Reputation: 321

Server processing time in tomcat access logs

In order to debug a performance issue I enabled access logs in tomcat. We are not using any apache server. Its the embedded tomcat that we are using.

I'm using following pattern for access logs.

access-patten = %h %l %u %t "%r" %s %b %D

%D = time at which first byte of the request is received ~ time at which last byte of the response is send.

So %D includes network latency as well.

But how do I print time difference between first byte of the request received and first byte of the response sent.

Upvotes: 6

Views: 23976

Answers (3)

miginside
miginside

Reputation: 436

Try %F

You can use %F:

%F - Time taken to commit the response, in milliseconds

Added in 2013

As mentioned by Tomer, since Tomcat version 7.0.42 there is a new log element %F available in the AccessLogValve implementation. You can find a better description of the difference between %D and %F in the case description:

Bug 55102 - Add ability to report time taken to prepare response:

Tomcat's AccessLogValve is able to report the time taken to send an entire request using %D. This is the total processing time and may be affected by network conditions. It is sometimes useful to be able to record the time taken by the server to prepare the response and send the first content to the client.

Attached is a patch that records the time the response is committed and then allows that to be reported in the access log using a %F pattern (which is the same as used by the mod-log-firstbyte module for HTTPD).

Upvotes: 10

Tomer Ben David
Tomer Ben David

Reputation: 8886

How about:

write time until first byte is written (commit time) in millis - %F

from AccessLogValve.html

Upvotes: 3

Ivan_opt
Ivan_opt

Reputation: 13

In my opinion, access log's duty is to record the informs of the program itself, which means tomcat looks the program package as a whole, so we may not get the byte details only.

If you want to get the application logging details, you can log the program webapp log, may be log4j or logback logging details inner your program. Such as 'System.currentTimeMillis()' at the beginning of your program and also add to the end. Please use your webapp logs but not access logs.

Thanks, hope it helps.

Upvotes: 1

Related Questions