[
https://issues.apache.org/jira/browse/LOG4J2-1029?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=14558736#comment-14558736
]
Stefan Leonhartsberger commented on LOG4J2-1029:
------------------------------------------------
Adding very basic JMH Benchmark Results:
{code}
@Benchmark
public void logPerformance() {
LOG.severe("TESTING THE LOGGER");
}
{code}
####################################################################################
*Result with i =5 and using Throwable*
Result "logPerformance":
8618,056 ñ(99.9%) 88,299 ops/s (Average)
(min, avg, max) = (8399,733, 8618,056, 8791,727), stdev = 101,685
CI (99.9%): 8529,758, 8706,355 (assumes normal distribution)
# Run complete. Total time: 00:00:41
Benchmark Mode Cnt Score Error Units
*LogPerformanceTest.logPerformance thrpt 20 8618,056 ñ 88,299 ops/s*
####################################################################################
*Result with i =0 and using Throwable*
Result "logPerformance":
8301,352 ñ(99.9%) 118,063 ops/s (Average)
(min, avg, max) = (8009,909, 8301,352, 8514,371), stdev = 135,962
CI (99.9%): 8183,288, 8419,415 (assumes normal distribution)
# Run complete. Total time: 00:00:41
Benchmark Mode Cnt Score Error Units
*LogPerformanceTest.logPerformance thrpt 20 8301,352 ñ 118,063 ops/s*
####################################################################################
*STACKTRACE NORMAL*
Result "logPerformance":
8285,858 ñ(99.9%) 166,818 ops/s (Average)
(min, avg, max) = (7826,246, 8285,858, 8504,988), stdev = 192,108
CI (99.9%): 8119,040, 8452,676 (assumes normal distribution)
# Run complete. Total time: 00:00:42
Benchmark Mode Cnt Score Error Units
*LogPerformanceTest.logPerformance thrpt 20 8285,858 ñ 166,818 ops/s*
This is a performance gain of ~4-5% - but for a very flat StackTrace - bigger
improvements can be seen by having a larger StackTrace.
> Performance improvement when gathering Location Information
> -----------------------------------------------------------
>
> Key: LOG4J2-1029
> URL: https://issues.apache.org/jira/browse/LOG4J2-1029
> Project: Log4j 2
> Issue Type: Improvement
> Components: Core
> Affects Versions: 2.3
> Environment: Java 1.8.0_45 64-bit
> Maven 3.3.1
> Windows 7
> basically any...
> Reporter: Stefan Leonhartsberger
> Priority: Minor
> Labels: Performance
>
> When gathering Location Information in Log4jLogEvent
> Log4j uses *Thread.currentThread().getStackTrace()*
> Using *(new Throwable()).getStackTrace();* would be more performant
> especially for larger stacks according to various benchmarks:
> * http://alexradzin.blogspot.co.at/2011/12/how-slow-getstacktrace-is.html
> *
> http://stackoverflow.com/questions/2347828/how-expensive-is-thread-getstacktrace
> This can easily be verified with a simple JMH Benchmark test.
> What would help in addition is to skip the Log4j Part when iterating over the
> StackTrace - use i=4 or whatever you may consider as being save enough
> instead of starting with i=0.
> Basically something like:
> {code}
> final StackTraceElement[] stackTrace = (new Throwable()).getStackTrace();
> for (int i = 4; i < stackTrace.length; i++) {
> }
> {code}
--
This message was sent by Atlassian JIRA
(v6.3.4#6332)
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]