tanks for you reply.
I write test program to show my appliaction case.
package com.iss.cnooc.test.ebank;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public class LoggerTest
{
Logger logger = LoggerFactory.getLogger(LoggerTest.class);
public static void main(String[] args)
{
int i = 0;
while (i < 2)
{
LoggerThread t = new LoggerThread();
t.start();
i++;
}
}
}
package com.iss.cnooc.test.ebank;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public class LoggerThread extends Thread
{
Logger logger = LoggerFactory.getLogger(LoggerThread.class);
@Override
public void run()
{
int i = 0;
long start = System.currentTimeMillis();
while (i < 1000000)
{
logger.debug("i = " + i);
i++;
}
long ecl = System.currentTimeMillis() - start;
System.out.println(this.getName() + "-" + this.getId() + " spend "
+ ecl);
}
}
The test reslut is
thread number | cost
1 | 46859
2 | 96593
4 | 196921
16 | 717703
I use fileappender.
why?
2010-12-16
刘东
发件人: Curt Arnold
发送时间: 2010-12-16 14:15:03
收件人: Log4J Users List
抄送:
主题: Re: performance problem in multithread environment
On Dec 13, 2010, at 10:54 AM, Jacob Kjome wrote:
> 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);
> }
>
alternatively use LogMF or LogSF (in the extras companion or in the SVN HEAD)
LogMF.debug(logger, "product: {0}, price: {1}", price,somePrice);
will have performance generally comparable to using logger.isDebugEnabled when
logging is disabled since any conversion and concatenation is deferred until
after the logging level is checked.
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]