On Dec 16, 2010, at 9:02 AM, 刘东 wrote:

> 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 
> 
> 


The elapsed time is roughly linear with the number of threads.  You did not 
indicate how many processors was involved in the tests, but if it were IO bound 
or CPU bound with a single processor, the results are exactly what you'd expect.

>           logger.debug("i = " + i);            
>  

This is likely the expensive statement.  Regardless of the configuration, this 
statement will always do:

convert an integer to a string (which can be a surprisingly expensive statement)
append two strings
make a call into SLF4J

Your benchmark is most likely measuring the performance of your JVM's 
implementation to String.toString(int).







---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to