You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@logging.apache.org by mi...@apache.org on 2016/04/14 15:12:48 UTC
logging-log4j2 git commit: GelfLayoutBenchmark
Repository: logging-log4j2
Updated Branches:
refs/heads/master c3463a810 -> 8f5e2759e
GelfLayoutBenchmark
Project: http://git-wip-us.apache.org/repos/asf/logging-log4j2/repo
Commit: http://git-wip-us.apache.org/repos/asf/logging-log4j2/commit/8f5e2759
Tree: http://git-wip-us.apache.org/repos/asf/logging-log4j2/tree/8f5e2759
Diff: http://git-wip-us.apache.org/repos/asf/logging-log4j2/diff/8f5e2759
Branch: refs/heads/master
Commit: 8f5e2759e0f3ad8f4e3fba3a92c0599ada254759
Parents: c3463a8
Author: Mikael Ståldal <mi...@magine.com>
Authored: Thu Apr 14 15:12:38 2016 +0200
Committer: Mikael Ståldal <mi...@magine.com>
Committed: Thu Apr 14 15:12:38 2016 +0200
----------------------------------------------------------------------
.../log4j/perf/jmh/GelfLayoutBenchmark.java | 75 ++++++++++++++++++++
.../src/main/resources/log4j2-gelf-perf.xml | 30 ++++++++
2 files changed, 105 insertions(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/8f5e2759/log4j-perf/src/main/java/org/apache/logging/log4j/perf/jmh/GelfLayoutBenchmark.java
----------------------------------------------------------------------
diff --git a/log4j-perf/src/main/java/org/apache/logging/log4j/perf/jmh/GelfLayoutBenchmark.java b/log4j-perf/src/main/java/org/apache/logging/log4j/perf/jmh/GelfLayoutBenchmark.java
new file mode 100644
index 0000000..870bc3d
--- /dev/null
+++ b/log4j-perf/src/main/java/org/apache/logging/log4j/perf/jmh/GelfLayoutBenchmark.java
@@ -0,0 +1,75 @@
+/*
+ * 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 org.apache.logging.log4j.LogManager;
+import org.apache.logging.log4j.Logger;
+import org.openjdk.jmh.annotations.*;
+
+import java.io.File;
+import java.util.concurrent.TimeUnit;
+
+/**
+ * Benchmarks Log4j 2 GelfLayout with a FileAppender.
+ */
+// HOW TO RUN THIS TEST
+// java -jar target/benchmarks.jar GelfLayoutBenchmark -f 1 -i 5 -wi 5 -bm sample -tu ns
+@State(Scope.Thread)
+public class GelfLayoutBenchmark {
+ public static final String MESSAGE =
+ "This is rather long and chatty log message with quite some interesting information and a bit of fun in it which is suitable here";
+
+ Logger log4j2Logger;
+ org.apache.log4j.Logger log4j1Logger;
+ int j;
+
+ @Setup
+ public void setUp() {
+ System.setProperty("log4j.configurationFile", "log4j2-gelf-perf.xml");
+
+ File log4j2File = new File("target/testlog4j2.json");
+ log4j2File.delete();
+
+ log4j2Logger = LogManager.getLogger(GelfLayoutBenchmark.class);
+ j = 0;
+ }
+
+ @TearDown
+ public void tearDown() {
+ System.clearProperty("log4j.configurationFile");
+
+ File log4j2File = new File("target/testlog4j2.json");
+ log4j2File.delete();
+ }
+
+ @BenchmarkMode(Mode.Throughput)
+ @OutputTimeUnit(TimeUnit.MILLISECONDS)
+ @Benchmark
+ public boolean baseline() {
+ ++j;
+ return true;
+ }
+
+ @BenchmarkMode(Mode.Throughput)
+ @OutputTimeUnit(TimeUnit.MILLISECONDS)
+ @Benchmark
+ public void log4j2Gelf() {
+ log4j2Logger.debug(MESSAGE);
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/8f5e2759/log4j-perf/src/main/resources/log4j2-gelf-perf.xml
----------------------------------------------------------------------
diff --git a/log4j-perf/src/main/resources/log4j2-gelf-perf.xml b/log4j-perf/src/main/resources/log4j2-gelf-perf.xml
new file mode 100644
index 0000000..94c74e5
--- /dev/null
+++ b/log4j-perf/src/main/resources/log4j2-gelf-perf.xml
@@ -0,0 +1,30 @@
+<?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="GelfPerfTest" status="error">
+ <Appenders>
+ <File name="TestLogfile" fileName="target/testlog4j2.json" immediateFlush="false">
+ <GelfLayout compressionType="OFF"/>
+ </File>
+ </Appenders>
+ <Loggers>
+ <Root level="debug">
+ <AppenderRef ref="TestLogfile"/>
+ </Root>
+ </Loggers>
+</Configuration>
\ No newline at end of file