1
2
3
4
5
6
7
8
9
10
11
12
13
14 package ch.qos.logback.classic;
15
16 import org.junit.jupiter.api.BeforeEach;
17 import org.junit.jupiter.api.Disabled;
18 import org.junit.jupiter.api.Test;
19
20 import ch.qos.logback.classic.corpus.CorpusModel;
21 import ch.qos.logback.core.contention.RunnableWithCounterAndDone;
22 import ch.qos.logback.core.contention.ThreadedThroughputCalculator;
23
24 @Disabled
25 public class LoggerContextPerfTest {
26
27 static int THREAD_COUNT = 10000;
28 int totalTestDuration = 4000;
29
30 LoggerContext loggerContext = new LoggerContext();
31
32 ThreadedThroughputCalculator harness = new ThreadedThroughputCalculator(totalTestDuration);
33 RunnableWithCounterAndDone[] runnableArray = buildRunnableArray();
34
35 CorpusModel corpusMaker;
36
37 @BeforeEach
38 public void setUp() throws Exception {
39 }
40
41 private RunnableWithCounterAndDone[] buildRunnableArray() {
42 RunnableWithCounterAndDone[] runnableArray = new RunnableWithCounterAndDone[THREAD_COUNT];
43 for (int i = 0; i < THREAD_COUNT; i++) {
44 runnableArray[i] = new GetLoggerRunnable();
45 }
46 return runnableArray;
47 }
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70 @Test
71 public void computeResults() throws InterruptedException {
72 harness.execute(runnableArray);
73 harness.printThroughput(runnableArray,"getLogger performance: ", true);
74 }
75
76 private class GetLoggerRunnable extends RunnableWithCounterAndDone {
77
78 final int burstLength = 3;
79
80 public void run() {
81 while (!isDone()) {
82 long i = counter % burstLength;
83
84 loggerContext.getLogger("a" + i);
85 counter++;
86 if (i == 0) {
87 Thread.yield();
88 }
89 }
90 }
91 }
92 }