You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@logging.apache.org by rg...@apache.org on 2017/04/21 06:39:58 UTC

[02/11] logging-log4j2 git commit: Add Jenkins toolchain. Create benchmarks

Add Jenkins toolchain. Create benchmarks


Project: http://git-wip-us.apache.org/repos/asf/logging-log4j2/repo
Commit: http://git-wip-us.apache.org/repos/asf/logging-log4j2/commit/bcf0fd78
Tree: http://git-wip-us.apache.org/repos/asf/logging-log4j2/tree/bcf0fd78
Diff: http://git-wip-us.apache.org/repos/asf/logging-log4j2/diff/bcf0fd78

Branch: refs/heads/master
Commit: bcf0fd783a50acac7ba4af834c038a682a92d2a6
Parents: 0854d32
Author: Ralph Goers <rg...@nextiva.com>
Authored: Sat Mar 18 12:42:25 2017 -0700
Committer: Ralph Goers <rg...@nextiva.com>
Committed: Sat Mar 18 12:42:25 2017 -0700

----------------------------------------------------------------------
 jenkins-toolchains.xml                          |  36 ++++++
 log4j-core/pom.xml                              |   6 +
 log4j-java9/pom.xml                             |   3 +
 .../jmh/FileAppenderWithLocationBenchmark.java  | 117 +++++++++++++++++++
 .../src/main/resources/log4j12-perfloc.xml      |  31 +++++
 .../src/main/resources/log4j2-perfloc.xml       |  40 +++++++
 .../src/main/resources/logback-perfloc.xml      |  30 +++++
 pom.xml                                         |   3 +
 8 files changed, 266 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/bcf0fd78/jenkins-toolchains.xml
----------------------------------------------------------------------
diff --git a/jenkins-toolchains.xml b/jenkins-toolchains.xml
new file mode 100644
index 0000000..e81bc4d
--- /dev/null
+++ b/jenkins-toolchains.xml
@@ -0,0 +1,36 @@
+<?xml version="1.0" encoding="UTF8"?>
+<toolchains>
+  <!-- JDK toolchains -->
+  <toolchain>
+    <type>jdk</type>
+    <provides>
+      <version>1.7</version>
+      <vendor>sun</vendor>
+    </provides>
+    <configuration>
+      <jdkHome>/home/jenkins/tools/java/latest1.7</jdkHome>
+    </configuration>
+  </toolchain>
+  <toolchain>
+    <type>jdk</type>
+    <provides>
+      <version>1.8</version>
+      <vendor>sun</vendor>
+    </provides>
+    <configuration>
+      <jdkHome>/home/jenkins/tools/java/latest1.7</jdkHome>
+    </configuration>
+  </toolchain>
+  <toolchain>
+    <type>jdk</type>
+    <provides>
+      <version>9</version>
+      <vendor>sun</vendor>
+    </provides>
+    <configuration>
+      <jdkHome>/home/jenkins/tools/java/jigsaw-jdk-9-ea-b156</jdkHome>
+    </configuration>
+  </toolchain>
+ 
+  <!-- other toolchains -->
+</toolchains>

http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/bcf0fd78/log4j-core/pom.xml
----------------------------------------------------------------------
diff --git a/log4j-core/pom.xml b/log4j-core/pom.xml
index d160c9d..47931da 100644
--- a/log4j-core/pom.xml
+++ b/log4j-core/pom.xml
@@ -38,6 +38,12 @@
       <groupId>org.apache.logging.log4j</groupId>
       <artifactId>log4j-api</artifactId>
     </dependency>
+    <!-- The Java 9 jar is used to pull in the Java 9 specific classes -->
+    <dependency>
+      <groupId>org.apache.logging.log4j</groupId>
+      <artifactId>log4j-java9</artifactId>
+      <scope>provided</scope>
+    </dependency>
     <!-- Used for OSGi bundle support -->
     <dependency>
       <groupId>org.osgi</groupId>

http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/bcf0fd78/log4j-java9/pom.xml
----------------------------------------------------------------------
diff --git a/log4j-java9/pom.xml b/log4j-java9/pom.xml
index 05c25d0..f31366d 100644
--- a/log4j-java9/pom.xml
+++ b/log4j-java9/pom.xml
@@ -76,6 +76,9 @@
   <profiles>
     <profile>
       <id>full</id>
+      <activation>
+        <activeByDefault>true</activeByDefault>
+      </activation>
       <build>
         <plugins>
           <plugin>

http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/bcf0fd78/log4j-perf/src/main/java/org/apache/logging/log4j/perf/jmh/FileAppenderWithLocationBenchmark.java
----------------------------------------------------------------------
diff --git a/log4j-perf/src/main/java/org/apache/logging/log4j/perf/jmh/FileAppenderWithLocationBenchmark.java b/log4j-perf/src/main/java/org/apache/logging/log4j/perf/jmh/FileAppenderWithLocationBenchmark.java
new file mode 100644
index 0000000..43d0ff0
--- /dev/null
+++ b/log4j-perf/src/main/java/org/apache/logging/log4j/perf/jmh/FileAppenderWithLocationBenchmark.java
@@ -0,0 +1,117 @@
+/*
+ * 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.perf.jmh;
+
+import java.io.File;
+import java.util.concurrent.TimeUnit;
+import java.util.logging.FileHandler;
+import java.util.logging.Level;
+
+import org.apache.logging.log4j.LogManager;
+import org.apache.logging.log4j.Logger;
+import org.openjdk.jmh.annotations.Benchmark;
+import org.openjdk.jmh.annotations.BenchmarkMode;
+import org.openjdk.jmh.annotations.Mode;
+import org.openjdk.jmh.annotations.OutputTimeUnit;
+import org.openjdk.jmh.annotations.Scope;
+import org.openjdk.jmh.annotations.Setup;
+import org.openjdk.jmh.annotations.State;
+import org.openjdk.jmh.annotations.TearDown;
+import org.slf4j.LoggerFactory;
+
+/**
+ * Benchmarks Log4j 2, Log4j 1, Logback and JUL using the DEBUG level which is enabled for this test. The configuration
+ * for each uses a FileAppender
+ */
+// HOW TO RUN THIS TEST
+// java -jar log4j-perf/target/benchmarks.jar ".*FileAppenderWithLocationBenchmark.*" -f 1 -wi 10 -i 20
+//
+// RUNNING THIS TEST WITH 4 THREADS:
+// java -jar log4j-perf/target/benchmarks.jar ".*FileAppenderWithLocationBenchmark.*" -f 1 -wi 10 -i 20 -t 4
+@State(Scope.Thread)
+public class FileAppenderWithLocationBenchmark {
+    public static final String MESSAGE = "This is a debug message";
+    private FileHandler julFileHandler;
+
+    Logger log4j2Logger;
+    Logger log4j2RandomLogger;
+    org.slf4j.Logger slf4jLogger;
+    org.apache.log4j.Logger log4j1Logger;
+
+    @Setup
+    public void setUp() throws Exception {
+        System.setProperty("log4j.configurationFile", "log4j2-perfloc.xml");
+        System.setProperty("log4j.configuration", "log4j12-perfloc.xml");
+        System.setProperty("logback.configurationFile", "logback-perfloc.xml");
+
+        deleteLogFiles();
+
+        log4j2Logger = LogManager.getLogger(FileAppenderWithLocationBenchmark.class);
+        log4j2RandomLogger = LogManager.getLogger("TestRandom");
+        slf4jLogger = LoggerFactory.getLogger(FileAppenderWithLocationBenchmark.class);
+        log4j1Logger = org.apache.log4j.Logger.getLogger(FileAppenderWithLocationBenchmark.class);
+    }
+
+    @TearDown
+    public void tearDown() {
+        System.clearProperty("log4j.configurationFile");
+        System.clearProperty("log4j.configuration");
+        System.clearProperty("logback.configurationFile");
+
+        deleteLogFiles();
+    }
+
+    private void deleteLogFiles() {
+        final File logbackFile = new File("target/testlogback.log");
+        logbackFile.delete();
+        final File log4jFile = new File ("target/testlog4j.log");
+        log4jFile.delete();
+        final File log4jRandomFile = new File ("target/testRandomlog4j2.log");
+        log4jRandomFile.delete();
+        final File log4j2File = new File ("target/testlog4j2.log");
+        log4j2File.delete();
+    }
+
+    @BenchmarkMode(Mode.Throughput)
+    @OutputTimeUnit(TimeUnit.SECONDS)
+    @Benchmark
+    public void log4j2RAF() {
+        log4j2RandomLogger.debug(MESSAGE);
+    }
+
+    @BenchmarkMode(Mode.Throughput)
+    @OutputTimeUnit(TimeUnit.SECONDS)
+    @Benchmark
+    public void log4j2File() {
+        log4j2Logger.debug(MESSAGE);
+    }
+
+    @BenchmarkMode(Mode.Throughput)
+    @OutputTimeUnit(TimeUnit.SECONDS)
+    @Benchmark
+    public void logbackFile() {
+        slf4jLogger.debug(MESSAGE);
+    }
+
+    @BenchmarkMode(Mode.Throughput)
+    @OutputTimeUnit(TimeUnit.SECONDS)
+    @Benchmark
+    public void log4j1File() {
+        log4j1Logger.debug(MESSAGE);
+    }
+}

http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/bcf0fd78/log4j-perf/src/main/resources/log4j12-perfloc.xml
----------------------------------------------------------------------
diff --git a/log4j-perf/src/main/resources/log4j12-perfloc.xml b/log4j-perf/src/main/resources/log4j12-perfloc.xml
new file mode 100644
index 0000000..91d384d
--- /dev/null
+++ b/log4j-perf/src/main/resources/log4j12-perfloc.xml
@@ -0,0 +1,31 @@
+<!--
+ 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.
+
+-->
+<!DOCTYPE log4j:configuration SYSTEM "log4j.dtd">
+<log4j:configuration xmlns:log4j="http://jakarta.apache.org/log4j/" debug="false">
+    <appender name="TestLogfile" class="org.apache.log4j.FileAppender">
+        <param name="File" value="target/testlog4j.log"/>
+        <param name="immediateFlush" value="false"/>
+        <layout class="org.apache.log4j.PatternLayout">
+            <param name="ConversionPattern" value="%d %5p [%t] %C{1}.%M:%L %X{transactionId} - %m%n"/>
+        </layout>
+    </appender>
+    <root>
+        <level value="debug"/>
+        <appender-ref ref="TestLogfile"/>
+    </root>
+</log4j:configuration>
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/bcf0fd78/log4j-perf/src/main/resources/log4j2-perfloc.xml
----------------------------------------------------------------------
diff --git a/log4j-perf/src/main/resources/log4j2-perfloc.xml b/log4j-perf/src/main/resources/log4j2-perfloc.xml
new file mode 100644
index 0000000..f38c2ea
--- /dev/null
+++ b/log4j-perf/src/main/resources/log4j2-perfloc.xml
@@ -0,0 +1,40 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ 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.
+
+-->
+<Configuration name="XMLPerfTest" status="error">
+    <Appenders>
+        <File name="TestLogfile" fileName="target/testlog4j2.log" immediateFlush="false">
+            <PatternLayout>
+                <Pattern>%d %5p [%t] %C{1.}.%M:%L %X{transactionId} - %m%n</Pattern>
+            </PatternLayout>
+        </File>
+        <RandomAccessFile name="RandomAccessLogFile" fileName="target/testRandomlog4j2.log" immediateFlush="false">
+            <PatternLayout>
+                <Pattern>%d %5p [%t] %C{1.}.%M:%L %X{transactionId} - %m%n</Pattern>
+            </PatternLayout>
+        </RandomAccessFile>
+    </Appenders>
+    <Loggers>
+        <Logger name="TestRandom" level="debug" additivity="false">
+            <AppenderRef ref="RandomAccessLogFile"/>
+        </Logger>
+        <Root level="debug">
+            <AppenderRef ref="TestLogfile"/>
+        </Root>
+    </Loggers>
+</Configuration>
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/bcf0fd78/log4j-perf/src/main/resources/logback-perfloc.xml
----------------------------------------------------------------------
diff --git a/log4j-perf/src/main/resources/logback-perfloc.xml b/log4j-perf/src/main/resources/logback-perfloc.xml
new file mode 100644
index 0000000..3b99775
--- /dev/null
+++ b/log4j-perf/src/main/resources/logback-perfloc.xml
@@ -0,0 +1,30 @@
+<!--
+ 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.
+
+-->
+<configuration>
+    <appender name="TestLogfile" class="ch.qos.logback.core.FileAppender">
+        <file>target/testlogback.log</file>
+        <immediateFlush>false</immediateFlush>
+        <encoder>
+            <Pattern>%d %5p [%t] %C{0}.%M:%L %X{transactionId} - %m%n</Pattern>
+        </encoder>
+    </appender>
+
+    <root level="debug">
+        <appender-ref ref="TestLogfile" />
+    </root>
+</configuration>
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/bcf0fd78/pom.xml
----------------------------------------------------------------------
diff --git a/pom.xml b/pom.xml
index 5e87f46..be06995 100644
--- a/pom.xml
+++ b/pom.xml
@@ -1266,6 +1266,9 @@
   <profiles>
     <profile>
       <id>full</id>
+      <activation>
+        <activeByDefault>true</activeByDefault>
+      </activation>
       <modules>
         <module>log4j-java9</module>
         <module>log4j-api</module>