Skip to content

Commit eda2569

Browse files
committed
results
1 parent 3d3626e commit eda2569

File tree

16 files changed

+287
-59
lines changed

16 files changed

+287
-59
lines changed

README.md

Lines changed: 52 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,52 @@
1-
# java-logger-benchmar
2-
A benchmark for several different Java loggers
1+
# Java Logger Benchmark
2+
3+
This project is a benchmark for several Java logging libraries. It is using JMH to measure the performance of the
4+
different logging libraries.
5+
6+
## What libraries are tested?
7+
8+
Currently, the following libraries are tested:
9+
10+
- Java Util Logging
11+
- Log4j 2
12+
- Log4j 2 with Async Logger
13+
- SLF4J Simple
14+
- Chronicle Logger
15+
16+
## How to run the benchmark?
17+
18+
The project is based on Maven and the Maven wrapper is included. To run the benchmark, simply execute the following
19+
command:
20+
21+
```
22+
./mvnw clean test
23+
```
24+
25+
The JMH benchmark is executed by several parameters that are all defined in the
26+
`com.openelements.logger.api.BenchmarkConstants` class in the `logger-api` module.
27+
28+
## How to add a new logging library?
29+
30+
To add a new logging library, you need to create a new module that contains the implementation of the logging library.
31+
The `logger-api` module contains a simple interface that needs to be implemented by the logging library. By doing so a
32+
benchmark for the new logging library can be created that executes the `LogLikeHell` Runnable. All logging libraries
33+
execute that code to generate comparable results.
34+
35+
## What are the results?
36+
37+
I still need to run the code in a long running benchmark. For a short running benchmark the values look like that (
38+
sorted from fastest to slowest):
39+
40+
| Logger | Logging Appender | Operations per second |
41+
|-------------------|------------------------|----------------------:|
42+
| Log4J2 | FILE_ASYNC | 26443,286 |
43+
| Chronicle Logger | FILE_ASYNC | 23435,042 |
44+
| Log4J2 | FILE | 13262,229 |
45+
| Java Util Logging | FILE | 5793,153 |
46+
| Log4J2 | FILE_ASYNC_AND_CONSOLE | 3853,433 |
47+
| Log4J2 | FILE_AND_CONSOLE | 3686,111 |
48+
| Log4J2 | CONSOLE | 3720,956 |
49+
| Java Util Logging | CONSOLE | 3430,061 |
50+
| Java Util Logging | FILE_AND_CONSOLE | 2712,309 |
51+
52+

chronicle-logger/src/main/java/com/openelements/logger/chronicle/ChronicleLogger.java

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
import com.openelements.logger.api.Logger;
44
import java.util.HashMap;
55
import java.util.Map;
6-
import java.util.stream.IntStream;
76
import net.openhft.chronicle.logger.ChronicleLogLevel;
87
import net.openhft.chronicle.logger.ChronicleLogManager;
98
import net.openhft.chronicle.logger.ChronicleLogWriter;
@@ -71,12 +70,4 @@ public Logger withMarker(String marker) {
7170
}
7271
return this;
7372
}
74-
75-
@Override
76-
public String createMessageWithPlaceholders(int placeholderCount) {
77-
return IntStream.range(0, placeholderCount)
78-
.mapToObj(i -> "{},")
79-
.reduce((a, b) -> a + " " + b)
80-
.orElse("");
81-
}
8273
}

jmh-benchmarks/src/test/java/com/openelements/logger/benchmarks/ChronicleLoggerBenchmark.java

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
package com.openelements.logger.benchmarks;
22

3-
import static com.openelements.logger.benchmarks.BenchmarkConstants.MEASUREMENT_ITERATIONS;
4-
import static com.openelements.logger.benchmarks.BenchmarkConstants.MEASUREMENT_TIME_IN_SECONDS_PER_ITERATION;
5-
import static com.openelements.logger.benchmarks.BenchmarkConstants.PARALLEL_THREAD_COUNT;
6-
import static com.openelements.logger.benchmarks.BenchmarkConstants.WARMUP_ITERATIONS;
7-
import static com.openelements.logger.benchmarks.BenchmarkConstants.WARMUP_TIME_IN_SECONDS_PER_ITERATION;
3+
import static com.openelements.logger.api.BenchmarkConstants.MEASUREMENT_ITERATIONS;
4+
import static com.openelements.logger.api.BenchmarkConstants.MEASUREMENT_TIME_IN_SECONDS_PER_ITERATION;
5+
import static com.openelements.logger.api.BenchmarkConstants.PARALLEL_THREAD_COUNT;
6+
import static com.openelements.logger.api.BenchmarkConstants.WARMUP_ITERATIONS;
7+
import static com.openelements.logger.api.BenchmarkConstants.WARMUP_TIME_IN_SECONDS_PER_ITERATION;
88

9+
import com.openelements.logger.api.LogLikeHell;
910
import com.openelements.logger.api.Logger;
1011
import com.openelements.logger.chronicle.ChronicleLogger;
1112
import java.nio.file.Files;

jmh-benchmarks/src/test/java/com/openelements/logger/benchmarks/JulLoggerBenchmark.java

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
package com.openelements.logger.benchmarks;
22

3-
import static com.openelements.logger.benchmarks.BenchmarkConstants.MEASUREMENT_ITERATIONS;
4-
import static com.openelements.logger.benchmarks.BenchmarkConstants.MEASUREMENT_TIME_IN_SECONDS_PER_ITERATION;
5-
import static com.openelements.logger.benchmarks.BenchmarkConstants.PARALLEL_THREAD_COUNT;
6-
import static com.openelements.logger.benchmarks.BenchmarkConstants.WARMUP_ITERATIONS;
7-
import static com.openelements.logger.benchmarks.BenchmarkConstants.WARMUP_TIME_IN_SECONDS_PER_ITERATION;
3+
import static com.openelements.logger.api.BenchmarkConstants.MEASUREMENT_ITERATIONS;
4+
import static com.openelements.logger.api.BenchmarkConstants.MEASUREMENT_TIME_IN_SECONDS_PER_ITERATION;
5+
import static com.openelements.logger.api.BenchmarkConstants.PARALLEL_THREAD_COUNT;
6+
import static com.openelements.logger.api.BenchmarkConstants.WARMUP_ITERATIONS;
7+
import static com.openelements.logger.api.BenchmarkConstants.WARMUP_TIME_IN_SECONDS_PER_ITERATION;
88

9+
import com.openelements.logger.api.LogLikeHell;
910
import com.openelements.logger.api.Logger;
1011
import com.openelements.logger.jul.JulLogger;
1112
import java.io.InputStream;

jmh-benchmarks/src/test/java/com/openelements/logger/benchmarks/Log4JLoggerBenchmark.java

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
package com.openelements.logger.benchmarks;
22

3-
import static com.openelements.logger.benchmarks.BenchmarkConstants.MEASUREMENT_ITERATIONS;
4-
import static com.openelements.logger.benchmarks.BenchmarkConstants.MEASUREMENT_TIME_IN_SECONDS_PER_ITERATION;
5-
import static com.openelements.logger.benchmarks.BenchmarkConstants.PARALLEL_THREAD_COUNT;
6-
import static com.openelements.logger.benchmarks.BenchmarkConstants.WARMUP_ITERATIONS;
7-
import static com.openelements.logger.benchmarks.BenchmarkConstants.WARMUP_TIME_IN_SECONDS_PER_ITERATION;
3+
import static com.openelements.logger.api.BenchmarkConstants.MEASUREMENT_ITERATIONS;
4+
import static com.openelements.logger.api.BenchmarkConstants.MEASUREMENT_TIME_IN_SECONDS_PER_ITERATION;
5+
import static com.openelements.logger.api.BenchmarkConstants.PARALLEL_THREAD_COUNT;
6+
import static com.openelements.logger.api.BenchmarkConstants.WARMUP_ITERATIONS;
7+
import static com.openelements.logger.api.BenchmarkConstants.WARMUP_TIME_IN_SECONDS_PER_ITERATION;
88

9+
import com.openelements.logger.api.LogLikeHell;
910
import com.openelements.logger.api.Logger;
1011
import com.openelements.logger.log4j.Log4JLogger;
1112
import java.nio.file.Files;

jul-logger/src/main/java/com/openelements/logger/jul/JulLogger.java

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
import java.util.HashMap;
55
import java.util.Map;
66
import java.util.logging.Level;
7-
import java.util.stream.IntStream;
87
import org.slf4j.helpers.MessageFormatter;
98

109
public class JulLogger implements com.openelements.logger.api.Logger {
@@ -50,14 +49,6 @@ public void log(String message, Throwable throwable, Object... args) {
5049
metadata.clear();
5150
}
5251

53-
@Override
54-
public String createMessageWithPlaceholders(int placeholderCount) {
55-
return IntStream.range(0, placeholderCount)
56-
.mapToObj(i -> "{},")
57-
.reduce((a, b) -> a + " " + b)
58-
.orElse("");
59-
}
60-
6152
@Override
6253
public Logger withMetadata(String key, Object value) {
6354
metadata.put(key, value.toString());

log4j2-logger/src/main/java/com/openelements/logger/log4j/Log4JLogger.java

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
package com.openelements.logger.log4j;
22

33
import com.openelements.logger.api.Logger;
4-
import java.util.stream.Collectors;
5-
import java.util.stream.IntStream;
64
import org.apache.logging.log4j.Level;
75
import org.apache.logging.log4j.Marker;
86
import org.apache.logging.log4j.MarkerManager;
@@ -79,11 +77,4 @@ public Logger withMarker(String marker) {
7977
}
8078
return this;
8179
}
82-
83-
@Override
84-
public String createMessageWithPlaceholders(int placeholderCount) {
85-
return IntStream.range(0, placeholderCount)
86-
.mapToObj(i -> "{},")
87-
.collect(Collectors.joining(" "));
88-
}
8980
}

jmh-benchmarks/src/test/java/com/openelements/logger/benchmarks/BenchmarkConstants.java renamed to logger-api/src/main/java/com/openelements/logger/api/BenchmarkConstants.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
1-
package com.openelements.logger.benchmarks;
1+
package com.openelements.logger.api;
22

33
public class BenchmarkConstants {
44

5-
public final static int WARMUP_ITERATIONS = 10;
5+
public final static int WARMUP_ITERATIONS = 2;
66

7-
public final static int WARMUP_TIME_IN_SECONDS_PER_ITERATION = 4;
7+
public final static int WARMUP_TIME_IN_SECONDS_PER_ITERATION = 2;
88

9-
public final static int MEASUREMENT_ITERATIONS = 10;
9+
public final static int MEASUREMENT_ITERATIONS = 2;
1010

11-
public final static int MEASUREMENT_TIME_IN_SECONDS_PER_ITERATION = 4;
11+
public final static int MEASUREMENT_TIME_IN_SECONDS_PER_ITERATION = 2;
1212

1313
public final static int PARALLEL_THREAD_COUNT = 4;
1414

jmh-benchmarks/src/test/java/com/openelements/logger/benchmarks/LogLikeHell.java renamed to logger-api/src/main/java/com/openelements/logger/api/LogLikeHell.java

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
1-
package com.openelements.logger.benchmarks;
1+
package com.openelements.logger.api;
22

3-
import com.openelements.logger.api.Logger;
43
import java.util.UUID;
54

65
public class LogLikeHell implements Runnable {
@@ -13,22 +12,23 @@ public LogLikeHell(Logger logger) {
1312

1413
@Override
1514
public void run() {
16-
String messageWithPlaceholder = "Hello " + logger.createMessageWithPlaceholders(1) + "!";
17-
String messageWith9Placeholder = "Hello " + logger.createMessageWithPlaceholders(9) + "!";
15+
String messageWithPlaceholder = "Hello {}!";
16+
String messageWith9Placeholder = "Hello {}, {}, {}, {}, {}, {}, {}, {}, {}!";
1817

1918
logger.log("L1, Hello world!");
2019
logger.log("L2, Hello world!", new RuntimeException("Oh no!"));
21-
logger.log("L3, " + messageWithPlaceholder, "placeholder");
22-
logger.log("L4, " + messageWithPlaceholder, new RuntimeException("Oh no!"), "placeholder");
20+
logger.log("L3, Hello {}!", "placeholder");
21+
logger.log("L4, Hello {}!", new RuntimeException("Oh no!"), "placeholder");
2322

2423
logger.withMetadata("key", "value").log("L5, Hello world!");
2524
logger.withMarker("marker").log("L6, Hello world!");
2625

2726
final String id = UUID.randomUUID().toString();
2827
logger.withMetadata("id", id).log("L7, Hello world!");
29-
logger.withMetadata("id", id).log("L8, " + messageWith9Placeholder, 1, 2, 3, 4, 5, 6, 7, 8, 9);
28+
logger.withMetadata("id", id).log("L8, Hello {}, {}, {}, {}, {}, {}, {}, {}, {}!", 1, 2, 3, 4, 5, 6, 7, 8, 9);
3029
logger.withMetadata("id", id)
31-
.log("L9, " + messageWith9Placeholder, new RuntimeException("Oh no!"), 1, 2, 3, 4, 5, 6, 7,
30+
.log("L9, Hello {}, {}, {}, {}, {}, {}, {}, {}, {}!", new RuntimeException("Oh no!"), 1, 2, 3, 4, 5, 6,
31+
7,
3232
8, 9);
3333

3434
logger.withMetadata("id", id)

logger-api/src/main/java/com/openelements/logger/api/Logger.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,4 @@ public interface Logger {
1414

1515
Logger withMarker(String marker);
1616

17-
String createMessageWithPlaceholders(int placeholderCount);
18-
1917
}

0 commit comments

Comments
 (0)