Experimental results are listed below in units of
micro-seconds. Measurements were done on a AMD Duron clocked
at 800Mhz running Windows 2000 and Sun's 1.3 JDK.
The results of the measurements (should) show that:
The PatternLayout perforance is very close to the performance of
a dedicated layout of equivalent format.
Format specifiers in conversion patterns have almost no impact
on performance.
Formating time and date information is costly. Using relative
time has the least impact on performance. It is recommended that to
use log4j specific date formatters such as the ISO8601DateFormat instead of the standard SimpleDateFormat because of its poor performance. See
the %d conversion character in PatternLayout.
Avoiding the flush operation at the end of each append
results in a performance gain of 10 to 20 percent. However, there
is safety tradeoff invloved in skipping flushing. Indeed, when
flushing is skipped, then it is likely that the last few log events
will not be recorded on disk when the application exits. This is a
high price to pay even for a 20% performance gain.
The AsyncAppender does not automatically
increase performance. On the contrary, it significantly degrades
performance. The performance tests done here very quickly fill up
the bounded buffer of the AsyncAppender and there is
cosiderable overhead in managing this bounded buffer.
On the other hand, had we interleaved logging operations with
long blocking and non CPU-intensive operations, such as I/O,
network access, sleeping threads, then the
AsyncAppender would have tremendously reduced the cost
of logging in terms of overall application runtime.
In a variant of this test, we have inserted a short sleep
operation between every 10 log operations. When the total slept
time is substracted, logging with the AsyncLogger
takes no time at all. In other words, logging is done for "free".
Extracting location information is comparatively slow. It
implies at least a ten fold increase in logging time! It should be
avoided unless performace is not a concern. It has been reported
from a trusted source that logging with location information on AIX
machines will kill your application's performance.
main(String[] argv) Usage:java org.apache.log4j.performance.Logging confFile runLength [delay] [burstLen]confFile is an XML configuration file and
runLength (integer) is the length of test loop,
delay is the time in millisecs to sleep every
bustLen log requests.
confFile is an XML configuration file and
runLength (integer) is the length of test loop,
delay is the time in millisecs to sleep every
bustLen log requests.
This application just prints the average time it took to log.