added tools for perf testing
Project: http://git-wip-us.apache.org/repos/asf/logging-log4j2/repo Commit: http://git-wip-us.apache.org/repos/asf/logging-log4j2/commit/14efd5fc Tree: http://git-wip-us.apache.org/repos/asf/logging-log4j2/tree/14efd5fc Diff: http://git-wip-us.apache.org/repos/asf/logging-log4j2/diff/14efd5fc Branch: refs/heads/master Commit: 14efd5fca3e29d6bb4d2f0aa54b666a163128c1e Parents: e7c9f5f Author: rpopma <[email protected]> Authored: Sat Feb 27 19:48:36 2016 +0900 Committer: rpopma <[email protected]> Committed: Sat Feb 27 19:48:36 2016 +0900 ---------------------------------------------------------------------- .../core/async/perftest/SimplePerfTest.bat | 20 +++++ .../core/async/perftest/SimplePerfTest.java | 89 ++++++++++++++++++++ 2 files changed, 109 insertions(+) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/14efd5fc/log4j-core/src/test/java/org/apache/logging/log4j/core/async/perftest/SimplePerfTest.bat ---------------------------------------------------------------------- diff --git a/log4j-core/src/test/java/org/apache/logging/log4j/core/async/perftest/SimplePerfTest.bat b/log4j-core/src/test/java/org/apache/logging/log4j/core/async/perftest/SimplePerfTest.bat new file mode 100644 index 0000000..c1965ff --- /dev/null +++ b/log4j-core/src/test/java/org/apache/logging/log4j/core/async/perftest/SimplePerfTest.bat @@ -0,0 +1,20 @@ +@echo off +REM reject if no arg supplied +IF %1.==. echo Usage: %0 version & exit /b + +set GC_OPTIONS=-verbose:gc -XX:+PrintGCDetails -XX:+PrintGCDateStamps -XX:+PrintTenuringDistribution -XX:+PrintGCApplicationConcurrentTime -XX:+PrintGCApplicationStoppedTime +set GC_OPTIONS= + +set LOG4J_OPTIONS=-Dlog4j.configurationFile=perf-CountingNoOpAppender.xml +:set LOG4J_OPTIONS=-Dlog4j.configurationFile=perf3PlainNoLoc.xml +set LOG4J_OPTIONS=%LOG4J_OPTIONS% -DLog4jContextSelector=org.apache.logging.log4j.core.async.AsyncLoggerContextSelector +set LOG4J_OPTIONS=%LOG4J_OPTIONS% -Dlog4j2.enable.threadlocals=true + +set CP=log4j-api-%1.jar;log4j-core-%1.jar;disruptor-3.3.4.jar;log4j-1.2.17.jar;slf4j-api-1.7.13.jar;logback-classic-1.1.3.jar;logback-core-1.1.3.jar +set CP=%CP%;C:\Users\remko\IdeaProjects\logging-log4j2\log4j-core\target\test-classes +:set CP=%CP%;log4j-core-2.0-tests.jar + +set MAIN=org.apache.logging.log4j.core.async.perftest.SimplePerfTest + +@echo on +java -Xms128m -Xmx128m %GC_OPTIONS% %LOG4J_OPTIONS% -cp %CP% %MAIN% http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/14efd5fc/log4j-core/src/test/java/org/apache/logging/log4j/core/async/perftest/SimplePerfTest.java ---------------------------------------------------------------------- diff --git a/log4j-core/src/test/java/org/apache/logging/log4j/core/async/perftest/SimplePerfTest.java b/log4j-core/src/test/java/org/apache/logging/log4j/core/async/perftest/SimplePerfTest.java new file mode 100644 index 0000000..a35b9e9 --- /dev/null +++ b/log4j-core/src/test/java/org/apache/logging/log4j/core/async/perftest/SimplePerfTest.java @@ -0,0 +1,89 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache license, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the license for the specific language governing permissions and + * limitations under the license. + */ +package org.apache.logging.log4j.core.async.perftest; + +import java.util.concurrent.TimeUnit; + +import org.apache.kafka.common.metrics.stats.Count; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; +import org.apache.logging.log4j.core.async.AsyncLogger; +import org.apache.logging.log4j.core.async.AsyncLoggerContextSelector; + +/** + * Created by remko on 2/26/2016. + */ +public class SimplePerfTest { + public static void main(String[] args) throws Exception { + System.setProperty("Log4jContextSelector", AsyncLoggerContextSelector.class.getName()); + + Logger logger = LogManager.getLogger(); + if (!(logger instanceof AsyncLogger)) { + throw new IllegalStateException(); + } + logger.info("Starting..."); + Thread.sleep(100); + + // warmup + final int ITERATIONS = 100000; + long startMs = System.currentTimeMillis(); + long end = startMs + TimeUnit.SECONDS.toMillis(10); + long total = 0; + int count = 0; + do { + long startNanos = System.nanoTime(); + loop(logger, ITERATIONS); + long endNanos = System.nanoTime(); + long durationNanos = endNanos - startNanos; + final long opsPerSec = (1000L * 1000L * 1000L * ITERATIONS) / durationNanos; + System.out.printf("Warmup: Throughput: %,d ops/s%n", opsPerSec); + total += opsPerSec; + count++; + Thread.sleep(1000);// drain buffer + } while (System.currentTimeMillis() < end); + System.out.printf("Average warmup throughput: %,d ops/s%n", total/count); + + final int COUNT = 10; + final long[] durationNanos = new long[10]; + for (int i = 0; i < COUNT; i++) { + final long startNanos = System.nanoTime(); + loop(logger, ITERATIONS); + long endNanos = System.nanoTime(); + durationNanos[i] = endNanos - startNanos; + Thread.sleep(1000);// drain buffer + } + total = 0; + for (int i = 0; i < COUNT; i++) { + final long opsPerSec = (1000L * 1000L * 1000L * ITERATIONS) / durationNanos[i]; + System.out.printf("Throughput: %,d ops/s%n", opsPerSec); + total += opsPerSec; + } + System.out.printf("Average throughput: %,d ops/s%n", total/COUNT); + } + + private static void loop(final Logger logger, final int iterations) { +// String[] arg7 = new String[] {"arg1", "arg2","arg3", "arg4","arg5", "arg6","arg7", }; +// String[] arg2 = new String[] {"arg1", "arg2", }; +// + for (int i = 0; i < iterations; i ++) { +// logger.info("7 arg message {} {} {} {} {} {} {}"); +// logger.info("7 arg message {} {} "); + + logger.info("simple text message"); + } + } +}
