views:

1723

answers:

2

The server.xml which controls the startup of Apache Tomcat's servlet container contains a debug attribute for nearly every major component. The debug attribute is more or less verbose depending upon the number you give it, zero being least and 99 being most verbose. How does the debug level affect Tomcat's speed when servicing large numbers of users? I assume zero is fast and 99 is relatively slower, but is this true. If there are no errors being thrown, does it matter?

+1  A: 

Extensive logging takes a significant amount of time. This is why it is so important to put

if (log.isDebugEnabled())
  log.debug(bla_bla_bla);

so I would say that seting your production server to being verbose would seriously affect performance. I assume it's a production server you're talking about since you say it must service a large number of users.

entzik
Well, frankly, no. you only need isDebugEnabled() checks if the logging data is very heavy or hard to construct. The logger's debug() or warn() or whatever methods are usually implemented efficiently to check if they are appropriate and then exit immidiately, without too much overhead.
Aleksandar Dimitrov
+1  A: 

Logging is not only responsible for giving you errors, but also for tracking of what's going on. In some cases, code cannot run inside a debugger, then logging is your only option.

This is why logging output can be extremely verbose. And I really mean that. I remember setting Catalina's loglevel to TRACE once and ended up with a several megabyte logfile. That was before the server received any hits at all. It was a huge performance hog. Countable in several seconds.

If you don't need logging for Tomcat itself, don't activate it on any of its components. You will typically only want to tinker with Tomcat's loglevel if you suspect a bug in either your setup or Tomcat itself.

For your own applications, measure the logging cost using a profiler or just some stress testing. Whatever your results, I would recommend against running an application with a high loglevel setting in a production environment. My current project dumps about a megabyte per request at TRACE setting, only about three to four lines on INFO and nothing on WARNING (iff everything goes well :-). I recommend not more than the most necessary logging. Your app should really just report startup, shutdown and failure, and - at most - one line per request.

Aleksandar Dimitrov