hc-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Ortwin Glück <ortwin.glu...@nose.ch>
Subject Re: Logging
Date Mon, 27 Dec 2004 15:38:03 GMT


Pfingstl Gernot wrote:
> In httpclient-3.0-beta1 source I saw, that calls to the logging api is always done directly:
> 	LOG.trace("some logging text");
> 
> This may produce a runtime overhead - see http://jakarta.apache.org/commons/logging/guide.html,
chapter "Best Practices (General)", "Code Guards":
> "Code guards are typically used to guard code that only needs to execute in support of
logging, that otherwise introduces undesirable runtime overhead in the general case (logging
disabled). Examples are multiple parameters, or expressions (i.e. string + " more") for parameters.
Use the guard methods of the form log.is<Priority>() to verify that logging should be
performed, before incurring the overhead of the logging method call. Yes, the logging methods
will perform the same check, but only after resolving parameters."
> 
> Do you plan to refactor the above code to:
> 	if(LOG.isTraceEnabled())
> 	{
> 		LOG.trace("some logging text");
> 	}
> 
> Gernot

Gernot,

I quickly hacked up a test case which compares an unguarded call to a 
guarded one. The log string is constant. I used Log4J with WARN level 
and a log.debug call. So no actual log was generated.

I performed a 100 million calls to log.debug. I run the test 3 times in 
a row to give HotSpot a chance to kick in.

unguarded: 6669ms
guarded: 7431ms
Difference: 762ms, 0.1142600089968511

unguarded: 6660ms
guarded: 7411ms
Difference: 751ms, 0.11276276276276276

unguarded: 6600ms
guarded: 7460ms
Difference: 860ms, 0.1303030303030303

So we loose around 10% performance for an unguarded call, if the payload 
is not logged. Logging can take up as much as 40% of the CPU time in 
very extreme cases like our no-host test suite. So best we can achieve 
is a 4% performance gain. Is that worth the trouble?

Ortwin Glück

-- 
  _________________________________________________________________
  NOSE applied intelligence ag

  ortwin glück                      [www]      http://www.nose.ch
  software engineer
  hardturmstrasse 171               [pgp id]           0x81CF3416
  8005 zürich                       [office]      +41-1-277 57 35
  switzerland                       [fax]         +41-1-277 57 12

Mime
View raw message