1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
|
# Log4j2 Benchmark Tool
A minimal Java tool to benchmark Log4j2 logging throughput with configurable concurrent threads and various logging configurations.
## Features
- Configurable number of concurrent logging threads
- Duration-based or event-count-based test modes
- Configurable message size (~100 chars default)
- Multiple Log4j2 configurations to compare:
- `sync-immediate` - Synchronous with immediateFlush=true
- `sync-buffered` - Synchronous with immediateFlush=false (8KB buffer)
- `async-1k` - AsyncLogger with 1024 ring buffer size
- `async-4k` - AsyncLogger with 4096 ring buffer size
- `async-10k` - AsyncLogger with 10240 ring buffer size
- CSV output support for further analysis
## Requirements
- Java 17+
- Maven 3.6+
## Build
```bash
mvn clean package
```
This creates an executable fat JAR at `target/log4jbench-1.0-SNAPSHOT.jar` (~2.7MB).
## Usage
### Basic Run (all configs, 100 threads, 10s duration)
```bash
# With Maven
mvn exec:java
# With standalone JAR
java -jar target/log4jbench-1.0-SNAPSHOT.jar
```
### With Custom Options
```bash
java -jar target/log4jbench-1.0-SNAPSHOT.jar --threads=8 --duration=30 --warmup=5
```
### Event-Count Mode
```bash
java -jar target/log4jbench-1.0-SNAPSHOT.jar --mode=events --events=500000 --threads=2
```
### Test Specific Configs Only
```bash
java -jar target/log4jbench-1.0-SNAPSHOT.jar --configs=sync-immediate,async-4k
```
### Custom Message Size
```bash
java -jar target/log4jbench-1.0-SNAPSHOT.jar --msg-size=200 --threads=4
```
### Export to CSV
```bash
java -jar target/log4jbench-1.0-SNAPSHOT.jar --output=results.csv
```
## Command Line Options
| Option | Description | Default |
|--------|-------------|---------|
| `-t, --threads=N` | Number of concurrent threads | 100 |
| `-m, --mode=MODE` | Test mode: `duration` or `events` | duration |
| `-d, --duration=N` | Test duration in seconds | 10 |
| `-e, --events=N` | Total events (events mode) | 1000000 |
| `-w, --warmup=N` | Warmup duration in seconds | 3 |
| `-s, --msg-size=N` | Message size in characters | 100 |
| `-c, --configs=LIST` | Comma-separated config names | all |
| `-o, --output=FILE` | Output CSV file | stdout only |
## Example Output
```
=== Log4j2 Benchmark ===
Threads: 4 | Mode: DURATION | Message size: 100 chars
Duration: 10s | Warmup: 3s
Configs: [sync-immediate, sync-buffered, async-1k, async-4k, async-10k]
Running: sync-immediate ...
sync-immediate | 4 threads | 1,234,567 events | 10.00s | 123,456 events/s | 12.34 MB/s
Running: async-4k ...
async-4k | 4 threads | 5,678,901 events | 10.00s | 567,890 events/s | 56.78 MB/s
```
## Log Configurations
### sync-immediate
Standard synchronous file appender with `immediateFlush="true"`. Every log event is flushed to disk immediately.
### sync-buffered
Synchronous file appender with `immediateFlush="false"` and 8KB buffer. Events are batched before writing.
### async-1k / async-4k / async-10k
Async loggers using LMAX Disruptor with ring buffer sizes of 1024, 4096, and 10240 respectively. Logging threads hand off events to a background thread for I/O.
## Notes
- **Cache dropping**: Before each test, the tool attempts to drop Linux filesystem caches (`sync; echo 3 > /proc/sys/vm/drop_caches`) for consistent results. Run with `sudo` for this to work.
- **Async loggers**: Use the LMAX Disruptor for high-throughput async logging.
## License
MIT
|