This is an automated email from the ASF dual-hosted git repository. ckozak pushed a commit to branch LOG4J2-2606 in repository https://gitbox.apache.org/repos/asf/logging-log4j2.git
commit 4ca0335ee876231f1ed71ded6d3c1c0be6a2e6d7 Author: Carter Kozak <[email protected]> AuthorDate: Wed May 22 13:36:48 2019 -0400 Add benchmarks for AsyncLoggerConfig in addition to global async logging Initial results: ``` Benchmark (asyncLoggerType) (queueFullPolicy) Mode Cnt Score Error Units ConcurrentAsyncLoggerToFileBenchmark.concurrentLoggingThreads ASYNC_CONTEXT ENQUEUE thrpt 3 1218463.815 ± 406974.312 ops/s ConcurrentAsyncLoggerToFileBenchmark.concurrentLoggingThreads ASYNC_CONTEXT ENQUEUE_UNSYNCHRONIZED thrpt 3 326207.651 ± 893515.779 ops/s ConcurrentAsyncLoggerToFileBenchmark.concurrentLoggingThreads ASYNC_CONTEXT SYNCHRONOUS thrpt 3 1019687.569 ± 937342.814 ops/s ConcurrentAsyncLoggerToFileBenchmark.concurrentLoggingThreads ASYNC_CONFIG ENQUEUE thrpt 3 284766.699 ± 733908.666 ops/s ConcurrentAsyncLoggerToFileBenchmark.concurrentLoggingThreads ASYNC_CONFIG ENQUEUE_UNSYNCHRONIZED thrpt 3 318812.152 ± 518897.160 ops/s ConcurrentAsyncLoggerToFileBenchmark.concurrentLoggingThreads ASYNC_CONFIG SYNCHRONOUS thrpt 3 1126545.917 ± 236232.970 ops/s ConcurrentAsyncLoggerToFileBenchmark.singleLoggingThread ASYNC_CONTEXT ENQUEUE thrpt 3 1317415.295 ± 350774.589 ops/s ConcurrentAsyncLoggerToFileBenchmark.singleLoggingThread ASYNC_CONTEXT ENQUEUE_UNSYNCHRONIZED thrpt 3 1336551.396 ± 49006.753 ops/s ConcurrentAsyncLoggerToFileBenchmark.singleLoggingThread ASYNC_CONTEXT SYNCHRONOUS thrpt 3 1284114.582 ± 690222.064 ops/s ConcurrentAsyncLoggerToFileBenchmark.singleLoggingThread ASYNC_CONFIG ENQUEUE thrpt 3 1410076.468 ± 111524.258 ops/s ConcurrentAsyncLoggerToFileBenchmark.singleLoggingThread ASYNC_CONFIG ENQUEUE_UNSYNCHRONIZED thrpt 3 1375629.011 ± 463847.759 ops/s ConcurrentAsyncLoggerToFileBenchmark.singleLoggingThread ASYNC_CONFIG SYNCHRONOUS thrpt 3 1376926.934 ± 2379099.010 ops/s ``` --- .../jmh/ConcurrentAsyncLoggerToFileBenchmark.java | 33 +++++++++++++++++++--- ...rentAsyncLoggerToFileBenchmark-asyncConfig.xml} | 6 ++-- .../ConcurrentAsyncLoggerToFileBenchmark.xml | 2 +- 3 files changed, 33 insertions(+), 8 deletions(-) diff --git a/log4j-perf/src/main/java/org/apache/logging/log4j/perf/jmh/ConcurrentAsyncLoggerToFileBenchmark.java b/log4j-perf/src/main/java/org/apache/logging/log4j/perf/jmh/ConcurrentAsyncLoggerToFileBenchmark.java index f6faad0..20415f0 100644 --- a/log4j-perf/src/main/java/org/apache/logging/log4j/perf/jmh/ConcurrentAsyncLoggerToFileBenchmark.java +++ b/log4j-perf/src/main/java/org/apache/logging/log4j/perf/jmh/ConcurrentAsyncLoggerToFileBenchmark.java @@ -77,14 +77,16 @@ public class ConcurrentAsyncLoggerToFileBenchmark { @Param({"ENQUEUE", "ENQUEUE_UNSYNCHRONIZED", "SYNCHRONOUS"}) private QueueFullPolicy queueFullPolicy; + @Param({"ASYNC_CONTEXT", "ASYNC_CONFIG"}) + private AsyncLoggerType asyncLoggerType; + private Logger logger; @Setup public final void before() { - new File("target/testRandomlog4j2.log").delete(); - System.setProperty("log4j.configurationFile", "ConcurrentAsyncLoggerToFileBenchmark.xml"); - System.setProperty("Log4jContextSelector", "org.apache.logging.log4j.core.async.AsyncLoggerContextSelector"); + new File("target/ConcurrentAsyncLoggerToFileBenchmark.log").delete(); System.setProperty("log4j2.is.webapp", "false"); + asyncLoggerType.setProperties(); queueFullPolicy.setProperties(); logger = LogManager.getLogger(ConcurrentAsyncLoggerToFileBenchmark.class); } @@ -92,7 +94,7 @@ public class ConcurrentAsyncLoggerToFileBenchmark { @TearDown public final void after() { ((LifeCycle) LogManager.getContext(false)).stop(); - new File("target/testRandomlog4j2.log").delete(); + new File("target/ConcurrentAsyncLoggerToFileBenchmark.log").delete(); logger = null; } @@ -119,6 +121,29 @@ public class ConcurrentAsyncLoggerToFileBenchmark { } } } + + @SuppressWarnings("unused") // Used by JMH + public enum AsyncLoggerType { + ASYNC_CONTEXT, + ASYNC_CONFIG; + // TODO(ckozak): Consider adding ASYNC_APPENDER + + void setProperties() { + switch (this) { + case ASYNC_CONTEXT: + System.setProperty("log4j.configurationFile", "ConcurrentAsyncLoggerToFileBenchmark.xml"); + System.setProperty("Log4jContextSelector", + "org.apache.logging.log4j.core.async.AsyncLoggerContextSelector"); + break; + case ASYNC_CONFIG: + System.setProperty("log4j.configurationFile", + "ConcurrentAsyncLoggerToFileBenchmark-asyncConfig.xml"); + break; + default: + throw new IllegalStateException("Unknown type: " + this); + } + } + } } public static final class SynchronousAsyncQueueFullPolicy implements AsyncQueueFullPolicy { diff --git a/log4j-perf/src/main/resources/ConcurrentAsyncLoggerToFileBenchmark.xml b/log4j-perf/src/main/resources/ConcurrentAsyncLoggerToFileBenchmark-asyncConfig.xml similarity index 84% copy from log4j-perf/src/main/resources/ConcurrentAsyncLoggerToFileBenchmark.xml copy to log4j-perf/src/main/resources/ConcurrentAsyncLoggerToFileBenchmark-asyncConfig.xml index f14b3b3..36e309e 100644 --- a/log4j-perf/src/main/resources/ConcurrentAsyncLoggerToFileBenchmark.xml +++ b/log4j-perf/src/main/resources/ConcurrentAsyncLoggerToFileBenchmark-asyncConfig.xml @@ -17,13 +17,13 @@ --> <Configuration status="OFF"> <Appenders> - <RandomAccessFile name="RandomAccessFile" fileName="target/testRandomlog4j2.log" immediateFlush="false"> + <RandomAccessFile name="RandomAccessFile" fileName="target/ConcurrentAsyncLoggerToFileBenchmark.log" immediateFlush="false"> <PatternLayout pattern="%d %p [%t] %c{1} %X{transactionId} - %m%n"/> </RandomAccessFile> </Appenders> <Loggers> - <Root level="info" includeLocation="false"> + <AsyncRoot level="info" includeLocation="false"> <appender-ref ref="RandomAccessFile"/> - </Root> + </AsyncRoot> </Loggers> </Configuration> diff --git a/log4j-perf/src/main/resources/ConcurrentAsyncLoggerToFileBenchmark.xml b/log4j-perf/src/main/resources/ConcurrentAsyncLoggerToFileBenchmark.xml index f14b3b3..3b0e043 100644 --- a/log4j-perf/src/main/resources/ConcurrentAsyncLoggerToFileBenchmark.xml +++ b/log4j-perf/src/main/resources/ConcurrentAsyncLoggerToFileBenchmark.xml @@ -17,7 +17,7 @@ --> <Configuration status="OFF"> <Appenders> - <RandomAccessFile name="RandomAccessFile" fileName="target/testRandomlog4j2.log" immediateFlush="false"> + <RandomAccessFile name="RandomAccessFile" fileName="target/ConcurrentAsyncLoggerToFileBenchmark.log" immediateFlush="false"> <PatternLayout pattern="%d %p [%t] %c{1} %X{transactionId} - %m%n"/> </RandomAccessFile> </Appenders>
