Skip to content

Commit a7854ac

Browse files
rgoersppkarwasz
authored andcommitted
LOG4J2-3516 - Move perf tests to log4j-core-its
1 parent 51b4360 commit a7854ac

18 files changed

+84
-64
lines changed

log4j-core-its/pom.xml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,12 @@
153153
<artifactId>wiremock-jre8</artifactId>
154154
<scope>test</scope>
155155
</dependency>
156+
<!-- For Async tests -->
157+
<dependency>
158+
<groupId>org.hdrhistogram</groupId>
159+
<artifactId>HdrHistogram</artifactId>
160+
<scope>test</scope>
161+
</dependency>
156162
</dependencies>
157163
<build>
158164
<plugins>
Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -30,18 +30,15 @@ public abstract class AbstractRunQueue implements IPerfTestRunner {
3030
private final Thread backGroundThread;
3131

3232
AbstractRunQueue() {
33-
backGroundThread = new Thread(new Runnable() {
34-
@Override
35-
public void run() {
36-
for (; ; ) {
37-
try {
38-
if (Objects.equals(queue.take(), STOP)) {
39-
break;
40-
}
41-
} catch (final InterruptedException e) {
42-
e.printStackTrace();
33+
backGroundThread = new Thread(() -> {
34+
for (; ; ) {
35+
try {
36+
if (Objects.equals(queue.take(), STOP)) {
4337
break;
4438
}
39+
} catch (final InterruptedException e) {
40+
e.printStackTrace();
41+
break;
4542
}
4643
}
4744
});
Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -189,9 +189,7 @@ public void clear() {
189189
maxValue = 0L;
190190
minValue = Long.MAX_VALUE;
191191

192-
for (int i = 0, size = counts.length; i < size; i++) {
193-
counts[i] = 0L;
194-
}
192+
Arrays.fill(counts, 0L);
195193
}
196194

197195
/**
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
*
2222
* <h3>Note regarding potential for TTSP(Time To Safe Point) issues</h3>
2323
*
24-
* If the caller spins in a 'counted' loop, and the implementation does not include a safepoint poll this may cause a TTSP
24+
* If the caller spins in a 'counted' loop, and the implementation does not include a a safepoint poll this may cause a TTSP
2525
* (Time To SafePoint) problem. If this is the case for your application you can solve it by preventing the idle method from
2626
* being inlined by using a Hotspot compiler command as a JVM argument e.g:
2727
* <code>-XX:CompileCommand=dontinline,org.apache.logging.log4j.core.async.perftest.NoOpIdleStrategy::idle</code>
Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -37,15 +37,12 @@ public void runTestAndPrintResult(
3737
// warmup at least 2 rounds and at most 1 minute
3838
final Histogram warmupHist = PerfTest.createHistogram();
3939
final long stop = System.nanoTime() + TimeUnit.MINUTES.toNanos(1);
40-
final Runnable run1 = new Runnable() {
41-
@Override
42-
public void run() {
43-
for (int i = 0; i < 10; i++) {
44-
final int LINES = PerfTest.throughput ? 50000 : 200000;
45-
runTest(runner, LINES, null, warmupHist, 2);
46-
if (i > 0 && System.nanoTime() - stop >= 0) {
47-
return;
48-
}
40+
final Runnable run1 = () -> {
41+
for (int i = 0; i < 10; i++) {
42+
final int LINES = PerfTest.throughput ? 50000 : 200000;
43+
runTest(runner, LINES, null, warmupHist, 2);
44+
if (i > 0 && System.nanoTime() - stop >= 0) {
45+
return;
4946
}
5047
}
5148
};
Lines changed: 17 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -28,15 +28,15 @@
2828
import java.util.Collections;
2929
import java.util.List;
3030
import org.apache.logging.log4j.core.async.AsyncLoggerContextSelector;
31-
import org.apache.logging.log4j.core.impl.Log4jPropertyKey;
31+
import org.apache.logging.log4j.core.util.Integers;
3232

3333
/**
3434
* Runs a sequence of performance tests.
3535
*/
3636
public class PerfTestDriver {
3737
private static final String DEFAULT_WAIT_STRATEGY = "Block";
3838

39-
enum WaitStrategy {
39+
static enum WaitStrategy {
4040
Sleep,
4141
Yield,
4242
Block;
@@ -95,17 +95,17 @@ List<String> processArguments(final String java) {
9595
// args.add("-XX:+PrintGCApplicationConcurrentTime");
9696
// args.add("-XX:+PrintSafepointStatistics");
9797

98-
args.add("-D" + Log4jPropertyKey.Constant.CONFIG_V1_FILE_NAME + '=' + log4jConfig); // 1.2
99-
args.add("-D" + Log4jPropertyKey.Constant.CONFIG_LOCATION + '=' + log4jConfig); // 2.x
98+
args.add("-Dlog4j.configuration=" + log4jConfig); // log4j 1.2
99+
args.add("-Dlog4j.configurationFile=" + log4jConfig); // log4j 2
100100
args.add("-Dlogback.configurationFile=" + log4jConfig); // logback
101101

102102
final int ringBufferSize = getUserSpecifiedRingBufferSize();
103103
if (ringBufferSize >= 128) {
104-
args.add("-D" + Log4jPropertyKey.Constant.ASYNC_CONFIG_RING_BUFFER_SIZE + '=' + ringBufferSize);
105-
args.add("-D" + Log4jPropertyKey.Constant.ASYNC_LOGGER_RING_BUFFER_SIZE + '=' + ringBufferSize);
104+
args.add("-DAsyncLoggerConfig.RingBufferSize=" + ringBufferSize);
105+
args.add("-DAsyncLogger.RingBufferSize=" + ringBufferSize);
106106
}
107-
args.add("-D" + Log4jPropertyKey.Constant.ASYNC_CONFIG_WAIT_STRATEGY + '=' + wait);
108-
args.add("-D" + Log4jPropertyKey.Constant.ASYNC_LOGGER_WAIT_STRATEGY + '=' + wait);
107+
args.add("-DAsyncLoggerConfig.WaitStrategy=" + wait);
108+
args.add("-DAsyncLogger.WaitStrategy=" + wait);
109109
if (systemProperties != null) {
110110
Collections.addAll(args, systemProperties);
111111
}
@@ -121,7 +121,7 @@ List<String> processArguments(final String java) {
121121

122122
private int getUserSpecifiedRingBufferSize() {
123123
try {
124-
return Integer.parseInt(System.getProperty("RingBufferSize", "-1"));
124+
return Integers.parseInt(System.getProperty("RingBufferSize", "-1"));
125125
} catch (final Exception ignored) {
126126
return -1;
127127
}
@@ -179,7 +179,7 @@ public Stats(final String raw) {
179179
average += Long.parseLong(parts[i++].split("=")[1]);
180180
pct99 += Long.parseLong(parts[i++].split("=")[1]);
181181
pct99_99 += Long.parseLong(parts[i++].split("=")[1]);
182-
count += Integer.parseInt(parts[i].split("=")[1]);
182+
count += Integers.parseInt(parts[i].split("=")[1]);
183183
} else {
184184
throughputRowCount++;
185185
final String number = line.substring(0, line.indexOf(' '));
@@ -203,14 +203,14 @@ public String toString() {
203203
}
204204
}
205205

206-
enum Runner {
206+
static enum Runner {
207207
Log4j12(RunLog4j1.class), //
208208
Log4j2(RunLog4j2.class), //
209209
Logback(RunLogback.class);
210210

211211
private final Class<? extends IPerfTestRunner> implementationClass;
212212

213-
Runner(final Class<? extends IPerfTestRunner> cls) {
213+
private Runner(final Class<? extends IPerfTestRunner> cls) {
214214
this.implementationClass = cls;
215215
}
216216
}
@@ -232,13 +232,11 @@ private static List<Setup> selectTests() throws IOException {
232232
final List<Setup> tests = new ArrayList<>();
233233

234234
// final String CACHEDCLOCK = "-Dlog4j.Clock=CachedClock";
235-
final String SYSCLOCK = asArgument(Log4jPropertyKey.Constant.CONFIG_CLOCK, "SystemClock");
236-
final String ALL_ASYNC = asArgument(
237-
Log4jPropertyKey.Constant.CONTEXT_SELECTOR_CLASS_NAME, AsyncLoggerContextSelector.class.getName());
235+
final String SYSCLOCK = "-Dlog4j.Clock=SystemClock";
236+
final String ALL_ASYNC = "-DLog4jContextSelector=" + AsyncLoggerContextSelector.class.getName();
238237

239-
final String THREADNAME = asArgument(
240-
Log4jPropertyKey.Constant.ASYNC_LOGGER_THREAD_NAME_STRATEGY,
241-
System.getProperty(Log4jPropertyKey.Constant.ASYNC_LOGGER_THREAD_NAME_STRATEGY, "CACHED"));
238+
final String THREADNAME = "-DAsyncLogger.ThreadNameStrategy=" //
239+
+ System.getProperty("AsyncLogger.ThreadNameStrategy", "CACHED");
242240

243241
// includeLocation=false
244242
add(tests, 1, "perf3PlainNoLoc.xml", Runner.Log4j2, "Loggers all async", ALL_ASYNC, SYSCLOCK, THREADNAME);
@@ -310,7 +308,7 @@ private static void add(
310308
private static void runPerfTests(final String[] args, final List<Setup> tests)
311309
throws IOException, InterruptedException, FileNotFoundException {
312310
final String java = args.length > 0 ? args[0] : "java";
313-
final int repeat = args.length > 1 ? Integer.parseInt(args[1]) : 5;
311+
final int repeat = args.length > 1 ? Integers.parseInt(args[1]) : 5;
314312
int x = 0;
315313
for (final Setup setup : tests) {
316314
System.out.print(setup.description());
@@ -385,8 +383,4 @@ public void run() {
385383
t.start();
386384
return t;
387385
}
388-
389-
private static String asArgument(final String key, final String value) {
390-
return String.format("-D%s=%s", key, value);
391-
}
392386
}
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ private void process(final String line) throws ParseException {
151151

152152
private Comparator<String> sort() {
153153
return new Comparator<String>() {
154-
final List<String> expected = Arrays.asList(
154+
List<String> expected = Arrays.asList(
155155
"1 thread", "2 threads", "4 threads", "8 threads", "16 threads", "32 threads", "64 threads");
156156

157157
@Override

0 commit comments

Comments
 (0)