Return-Path: Delivered-To: apmail-jakarta-httpclient-dev-archive@www.apache.org Received: (qmail 2259 invoked from network); 27 Dec 2004 17:12:31 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (209.237.227.199) by minotaur-2.apache.org with SMTP; 27 Dec 2004 17:12:31 -0000 Received: (qmail 93841 invoked by uid 500); 27 Dec 2004 17:12:24 -0000 Delivered-To: apmail-jakarta-httpclient-dev-archive@jakarta.apache.org Received: (qmail 93823 invoked by uid 500); 27 Dec 2004 17:12:24 -0000 Mailing-List: contact httpclient-dev-help@jakarta.apache.org; run by ezmlm Precedence: bulk List-Unsubscribe: List-Subscribe: List-Help: List-Post: List-Id: "HttpClient Project" Reply-To: "HttpClient Project" Delivered-To: mailing list httpclient-dev@jakarta.apache.org Received: (qmail 93809 invoked by uid 99); 27 Dec 2004 17:12:24 -0000 X-ASF-Spam-Status: No, hits=0.0 required=10.0 tests= X-Spam-Check-By: apache.org Received-SPF: pass (hermes.apache.org: local policy) Received: from mail.laszlosystems.com (HELO mail.laszlosystems.com) (198.144.202.70) by apache.org (qpsmtpd/0.28) with ESMTP; Mon, 27 Dec 2004 09:12:21 -0800 Received: from [192.168.42.70] ([]) by mail.laszlosystems.com (Merak 5.5.6) with SMTP id HQA74142 for ; Mon, 27 Dec 2004 09:12:19 -0800 Message-ID: <41D04273.6050703@laszlosystems.com> Date: Mon, 27 Dec 2004 09:12:19 -0800 From: Eric Bloch User-Agent: Mozilla Thunderbird 0.9 (Windows/20041103) X-Accept-Language: en-us, en MIME-Version: 1.0 To: HttpClient Project Subject: Re: Logging References: <04Dec27.155306cet.332337@janus.stmk.gv.at> <41D02C5B.9000703@nose.ch> In-Reply-To: <41D02C5B.9000703@nose.ch> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 8bit X-Virus-Checked: Checked X-Spam-Rating: minotaur-2.apache.org 1.6.2 0/1000/N This is just one of those cases where Java fails as a programming language. You want to be able to write LOG.trace("blah") but effectively run if (some bit) { LOG.trace() } -Eric Ortwin Gl�ck wrote: > > > 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() 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 > > > ------------------------------------------------------------------------ > > package test; > > import org.apache.commons.logging.Log; > import org.apache.commons.logging.LogFactory; > > /** > * > * @author Ortwin Gl�ck, NOSE Applied Intelligence AG > * @version $Id$ > */ > public class Test { > public Test() { > try { > test(); > Thread.sleep(1000); > test(); > Thread.sleep(1000); > test(); > } catch (InterruptedException e) { > e.printStackTrace(); > } > } > > public static void main(String[] args) { > new Test(); > } > > public void test() { > long MAX = 10000000; > Log log = LogFactory.getLog(Test.class); > long s = System.currentTimeMillis(); > for (int i=0; i log.debug("a constant string"); > } > long e = System.currentTimeMillis(); > long unguarded = e-s; > System.out.println("unguarded: "+ unguarded +"ms"); > > s = System.currentTimeMillis(); > for (int i=0; i if (log.isDebugEnabled()) { > log.debug("a constant string"); > } > } > e = System.currentTimeMillis(); > long guarded = e-s; > System.out.println("guarded: "+ guarded +"ms"); > > long diff = guarded-unguarded; > double pct = (double) diff / unguarded; > System.out.println("Difference: "+ diff +"ms, "+ pct); > > } > } > > > > ------------------------------------------------------------------------ > > --------------------------------------------------------------------- > To unsubscribe, e-mail: httpclient-dev-unsubscribe@jakarta.apache.org > For additional commands, e-mail: httpclient-dev-help@jakarta.apache.org --------------------------------------------------------------------- To unsubscribe, e-mail: httpclient-dev-unsubscribe@jakarta.apache.org For additional commands, e-mail: httpclient-dev-help@jakarta.apache.org