logging-log4j-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Jacob Kjome" <h...@visi.com>
Subject Re: performance problem in multithread environment
Date Mon, 13 Dec 2010 16:54:03 GMT
You will get better performance by not logging at all, no question.  However, 
there are tuning possibilities.  I see you mention "logger.info()".  In 
production, I generally only have "warn()" and above for the vast majority of 
loggers.  In fact, I configure the root logger up with the "WARN" level and 
selectively set other loggers to something less than WARN (if need be).

The other thing you might look at is whether you are concatenating strings in 
your logging statements.  For instance the following will incur an unnecessary 
cost in concatenating strings even when the "DEBUG" level is not enabled....

logger.debug("product: " + someProduct + ", price: " + somePrice);

A more efficient way to define this in your code is....

if (logger.isDebugEnabled()) {
    logger.debug("product: " + someProduct + ", price: " + somePrice);
}

In this case, you will only incur the cost of a simple boolean check when 
"DEBUG" is disabled.

Note that this is unnecessary if you are not concatenating, as 
isDebugEnabled() is called internally to the debug() method prior to sending 
your message to the appender anway.  Avoiding concatenation altogether in your 
logging statements is generally recommended, but really doesn't hurt much if 
you are only doing it for trace(), debug(), or info() statements that are 
surrounded by is[Level]Enabled() and you only have "WARN" and above enabled in 
production.

So, when you are profiling, you must take into account how your loggers 
perform logging in the code as well as the configuration you are using.  
Simply saying that logging is super costly without taking these issues into 
account is not useful.  Feel free to post more specifics, especially if you 
feel you truly are taking these issues into account and are still getting 
ridiculously bad performance while using Log4j.


Jake

On Mon, 13 Dec 2010 09:54:04 +0800
  <betterjonah@hotmail.com> wrote:
> I need your help!!!
> Please help me ,thanks.
> 
> 
> 2010-12-13 
> 
> 
>
> 
> 
> 
>  2010-12-11  01:52:03 
> Log4J Users List 
> 
> Re: Re: performance problem in multithread environment 
> 
> hi,
> through jprofiler I found that many thread are blocked at 
>logger.info(message).I saw that each logger.info() call will cost 2,200 
>us,the application are running at a machine which has one phyical cpu(64 
>virtual cpu),1.5Ghz,32G memory,solaris 10.
> If I comment all logger message(means no logging message),the application 
>performance will be faster more than ten times.
> If I crate new logger instance for each log message,the application 
>performance will be faster more than four times.
> Could tell me the difference between category and logger.
> Api shows that logger extends category,logger.info() just is 
>category.info()。
> The code show that synchronization is by category,but code category = 
>this,shows that at this time category just is logger.
> BTW:
> In my application,when process one order,it will log about 700 messages.
> With log,application will process three orders one second,But without 
>log,application will process 40 orders one second.
> Is there any mistakes by using log4j?need more config?
> thanks. 
> 2010-12-11 
>
> Sebastien Tardif 
> 2010-12-11  01:10:40 
> log4j-user 
> 
> Re: performance problem in multithread environment 
> 
> The code show that synchronization is by category.
> If appendLoopOnAppenders is faster, like if the underline code use
> asynchronous appender, that should not be a problem.
> So you should investigate what the thread having the lock is doing.
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: log4j-user-unsubscribe@logging.apache.org
>For additional commands, e-mail: log4j-user-help@logging.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: log4j-user-unsubscribe@logging.apache.org
For additional commands, e-mail: log4j-user-help@logging.apache.org


Mime
View raw message