You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@logging.apache.org by vy...@apache.org on 2021/10/27 08:11:21 UTC
[logging-log4j2] branch release-2.x updated (07c3c88 -> b677420)
This is an automated email from the ASF dual-hosted git repository.
vy pushed a change to branch release-2.x
in repository https://gitbox.apache.org/repos/asf/logging-log4j2.git.
from 07c3c88 Upgrade from hamcrest-all:1.3 to hamcrest:2.2.
new d21bfa2 Add InstantFormatBenchmark.
new b677420 Add `.java-version` file used by jenv.
The 2 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails. The revisions
listed as "add" were already present in the repository and have only
been added to this reference.
Summary of changes:
.github/workflows/benchmark.yml | 3 +-
.java-version | 1 +
.../log4j/perf/jmh/InstantFormatBenchmark.java | 196 +++++++++++++++++++++
3 files changed, 199 insertions(+), 1 deletion(-)
create mode 100644 .java-version
create mode 100644 log4j-perf/src/main/java/org/apache/logging/log4j/perf/jmh/InstantFormatBenchmark.java
[logging-log4j2] 01/02: Add InstantFormatBenchmark.
Posted by vy...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
vy pushed a commit to branch release-2.x
in repository https://gitbox.apache.org/repos/asf/logging-log4j2.git
commit d21bfa2f31bf9d9eabd50d3fd37ddb020a957418
Author: Volkan Yazici <vo...@yazi.ci>
AuthorDate: Wed Oct 27 10:10:59 2021 +0200
Add InstantFormatBenchmark.
---
.github/workflows/benchmark.yml | 3 +-
.../log4j/perf/jmh/InstantFormatBenchmark.java | 196 +++++++++++++++++++++
2 files changed, 198 insertions(+), 1 deletion(-)
diff --git a/.github/workflows/benchmark.yml b/.github/workflows/benchmark.yml
index 47109e3..544cfe9 100644
--- a/.github/workflows/benchmark.yml
+++ b/.github/workflows/benchmark.yml
@@ -87,7 +87,8 @@ jobs:
jdk: [ 11, 17 ]
concurrency: [ 1, 8 ]
jmhCommand:
- - "-t $CONCURRENCY -f 1 -wi 0 -w 10s -i 1 -r 10s -prof gc -rf json -rff results-layout-jtl.json '.*JsonTemplateLayoutBenchmark.*'"
+ - "-t $CONCURRENCY -f 3 -wi 3 -w 10s -i 4 -r 20s -prof gc -rf json -rff results-layout-jtl.json '.*JsonTemplateLayoutBenchmark.*'"
+ - "-t $CONCURRENCY -f 3 -wi 3 -w 10s -i 4 -r 20s -prof gc -rf json -rff results-util-instant-format.json '.*InstantFormatBenchmark.*'"
steps:
diff --git a/log4j-perf/src/main/java/org/apache/logging/log4j/perf/jmh/InstantFormatBenchmark.java b/log4j-perf/src/main/java/org/apache/logging/log4j/perf/jmh/InstantFormatBenchmark.java
new file mode 100644
index 0000000..0d46e61
--- /dev/null
+++ b/log4j-perf/src/main/java/org/apache/logging/log4j/perf/jmh/InstantFormatBenchmark.java
@@ -0,0 +1,196 @@
+/*
+ * 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.core.time.MutableInstant;
+import org.apache.logging.log4j.core.util.datetime.FastDateFormat;
+import org.apache.logging.log4j.core.util.datetime.FixedDateFormat;
+import org.openjdk.jmh.annotations.*;
+import org.openjdk.jmh.infra.BenchmarkParams;
+import org.openjdk.jmh.infra.Blackhole;
+
+import java.time.Duration;
+import java.time.Instant;
+import java.time.format.DateTimeFormatter;
+import java.time.temporal.ChronoUnit;
+import java.util.*;
+import java.util.stream.IntStream;
+import java.util.stream.Stream;
+
+/**
+ * Benchmarks certain {@link Instant} formatters with various patterns and instant collections.
+ */
+@State(Scope.Thread)
+public class InstantFormatBenchmark {
+
+ private static final TimeZone TIME_ZONE = TimeZone.getTimeZone("UTC");
+
+ /**
+ * Does (should?) have no effect, since {@link #pattern}s must be supported by {@link FixedDateFormat}, which doesn't have any locale support.
+ */
+ private static final Locale LOCALE = Locale.US;
+
+ private static final Instant[] INSTANTS = createInstants();
+
+ /**
+ * Date & time format patterns supported by all formatters and produce the same output.
+ */
+ @Param({
+ "HH:mm:ss.SSS",
+ "yyyy-MM-dd'T'HH:mm:ss.SSS"
+ })
+ public String pattern;
+
+ private Formatter log4jFdf;
+
+ private Formatter commonsFdf;
+
+ private Formatter javaDtf;
+
+ @Setup
+ public void setupFormatters(final BenchmarkParams params) {
+ final String pattern = params.getParam("pattern");
+ log4jFdf = new Log4jFixedDateFormat(pattern);
+ commonsFdf = new CommonsFastDateFormat(pattern);
+ javaDtf = new JavaDateTimeFormatter(pattern);
+ }
+
+ private static Instant[] createInstants() {
+ final Instant loInstant = Instant.EPOCH;
+ // Capping the max. offset to a day to avoid choking at `FixedDateTime#millisSinceMidnight(long)`, which is supposed to be executed once a day in practice.
+ final Instant hiInstant = loInstant.plus(Duration.ofDays(1));
+ final long maxOffsetNanos = Duration.between(loInstant, hiInstant).toNanos();
+ final Random random = new Random(0);
+ return IntStream
+ .range(0, 1_000)
+ .mapToObj(ignored -> {
+ final long offsetNanos = (long) Math.floor(random.nextDouble() * maxOffsetNanos);
+ return loInstant.plus(offsetNanos, ChronoUnit.NANOS);
+ })
+ .toArray(Instant[]::new);
+ }
+
+ @FunctionalInterface
+ interface Formatter {
+
+ void benchmark(Blackhole blackhole);
+
+ }
+
+ private static final class Log4jFixedDateFormat implements Formatter {
+
+ private final org.apache.logging.log4j.core.time.Instant[] log4jInstants;
+
+ private final char[] buffer;
+
+ private final FixedDateFormat formatter;
+
+ private Log4jFixedDateFormat(final String pattern) {
+ this.log4jInstants = Stream
+ .of(INSTANTS)
+ .map(instant -> {
+ final MutableInstant log4jInstant = new MutableInstant();
+ log4jInstant.initFromEpochSecond(instant.getEpochSecond(), instant.getNano());
+ return log4jInstant;
+ })
+ .toArray(org.apache.logging.log4j.core.time.Instant[]::new);
+ this.buffer = new char[pattern.length()];
+ this.formatter = Objects.requireNonNull(FixedDateFormat.createIfSupported(pattern, TIME_ZONE.getID()));
+ }
+
+ @Override
+ public void benchmark(final Blackhole blackhole) {
+ for (final org.apache.logging.log4j.core.time.Instant log4jInstant : log4jInstants) {
+ blackhole.consume(formatter.formatInstant(log4jInstant, buffer, 0));
+ }
+ }
+
+ }
+
+ private static final class CommonsFastDateFormat implements Formatter {
+
+ private final Calendar[] calendars;
+
+ private final StringBuilder stringBuilder = new StringBuilder();
+
+ private final FastDateFormat fastDateFormat;
+
+ private CommonsFastDateFormat(final String pattern) {
+ this.calendars = Arrays
+ .stream(INSTANTS)
+ .map(instant -> {
+ final Calendar calendar = Calendar.getInstance(TIME_ZONE, LOCALE);
+ calendar.setTimeInMillis(instant.toEpochMilli());
+ return calendar;
+ })
+ .toArray(Calendar[]::new);
+ this.fastDateFormat = FastDateFormat.getInstance(pattern, TIME_ZONE, LOCALE);
+ }
+
+ @Override
+ public void benchmark(final Blackhole blackhole) {
+ for (final Calendar calendar : calendars) {
+ stringBuilder.setLength(0);
+ fastDateFormat.format(calendar, stringBuilder);
+ blackhole.consume(stringBuilder.length());
+ }
+ }
+
+ }
+
+ private static final class JavaDateTimeFormatter implements Formatter {
+
+ private final Instant[] instants;
+
+ private final StringBuilder stringBuilder = new StringBuilder();
+
+ private final DateTimeFormatter dateTimeFormatter;
+
+ private JavaDateTimeFormatter(final String pattern) {
+ this.instants = INSTANTS;
+ this.dateTimeFormatter = DateTimeFormatter
+ .ofPattern(pattern, LOCALE)
+ .withZone(TIME_ZONE.toZoneId());
+ }
+
+ @Override
+ public void benchmark(final Blackhole blackhole) {
+ for (final Instant instant : instants) {
+ stringBuilder.setLength(0);
+ dateTimeFormatter.formatTo(instant, stringBuilder);
+ blackhole.consume(stringBuilder.length());
+ }
+ }
+
+ }
+
+ @Benchmark
+ public void log4jFdf(final Blackhole blackhole) {
+ log4jFdf.benchmark(blackhole);
+ }
+
+ @Benchmark
+ public void commonsFdf(final Blackhole blackhole) {
+ commonsFdf.benchmark(blackhole);
+ }
+
+ @Benchmark
+ public void javaDtf(final Blackhole blackhole) {
+ javaDtf.benchmark(blackhole);
+ }
+
+}
[logging-log4j2] 02/02: Add `.java-version` file used by jenv.
Posted by vy...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
vy pushed a commit to branch release-2.x
in repository https://gitbox.apache.org/repos/asf/logging-log4j2.git
commit b6774209e3fed560de37ac0a63a0f655e6491fa0
Author: Volkan Yazici <vo...@yazi.ci>
AuthorDate: Wed Oct 27 10:11:24 2021 +0200
Add `.java-version` file used by jenv.
---
.java-version | 1 +
1 file changed, 1 insertion(+)
diff --git a/.java-version b/.java-version
new file mode 100644
index 0000000..6259340
--- /dev/null
+++ b/.java-version
@@ -0,0 +1 @@
+1.8