-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathRequestContextBenchmark.java
94 lines (85 loc) · 3.26 KB
/
RequestContextBenchmark.java
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
package io.quarkus.arc.benchmarks;
import org.openjdk.jmh.annotations.Benchmark;
import org.openjdk.jmh.annotations.Measurement;
import org.openjdk.jmh.annotations.Param;
import org.openjdk.jmh.annotations.Setup;
import org.openjdk.jmh.annotations.TearDown;
import org.openjdk.jmh.annotations.Warmup;
import org.openjdk.jmh.infra.Blackhole;
import io.quarkus.arc.Arc;
import io.quarkus.arc.ArcContainer;
import io.quarkus.arc.ManagedContext;
@Warmup(batchSize = 1024)
@Measurement(batchSize = 1024)
public class RequestContextBenchmark extends BenchmarkBase {
@Param({ "1", "3", "5" })
public int beans;
private ManagedContext requestContext;
private SimpleReqScopedBean1 simpleBean1;
private SimpleReqScopedBean2 simpleBean2;
private SimpleReqScopedBean3 simpleBean3;
private SimpleReqScopedBean4 simpleBean4;
private SimpleReqScopedBean5 simpleBean5;
@Setup
public void setup() {
ArcContainer container = Arc.initialize();
requestContext = container.requestContext();
// Obtain the client proxies
simpleBean1 = container.select(SimpleReqScopedBean1.class).get();
simpleBean2 = container.select(SimpleReqScopedBean2.class).get();
simpleBean3 = container.select(SimpleReqScopedBean3.class).get();
simpleBean4 = container.select(SimpleReqScopedBean4.class).get();
simpleBean5 = container.select(SimpleReqScopedBean5.class).get();
}
@TearDown
public void tearDown() {
Arc.shutdown();
}
@Benchmark
public void run(Blackhole blackhole) throws InterruptedException {
// 1. Activate the context
// 2. Invoke a client proxy method of some @RequestScoped beans
// 3. Terminate the context
requestContext.activate();
try {
if (beans == 1) {
// 1 x 15 client proxy invocations
for (int i = 0; i < 15; i++) {
blackhole.consume(simpleBean1.ping());
}
} else if (beans == 3) {
// 3 x 5 client proxy invocations
int loop = 5;
for (int i = 0; i < loop; i++) {
blackhole.consume(simpleBean1.ping());
}
for (int i = 0; i < loop; i++) {
blackhole.consume(simpleBean2.ping());
}
for (int i = 0; i < loop; i++) {
blackhole.consume(simpleBean3.ping());
}
} else if (beans == 5) {
// 5 x 3 client proxy invocations
int loop = 3;
for (int i = 0; i < loop; i++) {
blackhole.consume(simpleBean1.ping());
}
for (int i = 0; i < loop; i++) {
blackhole.consume(simpleBean2.ping());
}
for (int i = 0; i < loop; i++) {
blackhole.consume(simpleBean3.ping());
}
for (int i = 0; i < loop; i++) {
blackhole.consume(simpleBean4.ping());
}
for (int i = 0; i < loop; i++) {
blackhole.consume(simpleBean5.ping());
}
}
} finally {
requestContext.terminate();
}
}
}