Skip to content
This repository was archived by the owner on May 30, 2024. It is now read-only.

Commit 0815938

Browse files
committed
Merge branch 'eb/ch76240/benchmarks-4.x' into eb/ch76240/benchmarks-4.x-report
2 parents d80d245 + 2bd5a37 commit 0815938

File tree

2 files changed

+50
-46
lines changed

2 files changed

+50
-46
lines changed

benchmarks/src/jmh/java/com/launchdarkly/sdk/server/EventProcessorBenchmarks.java

Lines changed: 35 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
import com.launchdarkly.client.EventProcessor;
66
import com.launchdarkly.client.EventProcessorInternals;
77
import com.launchdarkly.client.LDConfig;
8-
import com.launchdarkly.client.LDUser;
98
import com.launchdarkly.client.interfaces.EventSender;
109
import com.launchdarkly.client.interfaces.EventSenderFactory;
1110
import com.launchdarkly.client.interfaces.HttpConfiguration;
@@ -17,8 +16,14 @@
1716

1817
import java.io.IOException;
1918
import java.net.URI;
19+
import java.util.ArrayList;
20+
import java.util.List;
2021
import java.util.Random;
2122

23+
import static com.launchdarkly.sdk.server.TestValues.BASIC_USER;
24+
import static com.launchdarkly.sdk.server.TestValues.CUSTOM_EVENT;
25+
import static com.launchdarkly.sdk.server.TestValues.TEST_EVENTS_COUNT;
26+
2227
public class EventProcessorBenchmarks {
2328
private static final int EVENT_BUFFER_SIZE = 1000;
2429
private static final int FLAG_COUNT = 10;
@@ -30,7 +35,8 @@ public static class BenchmarkInputs {
3035
// Initialization of the things in BenchmarkInputs does not count as part of a benchmark.
3136
final EventProcessor eventProcessor;
3237
final EventSender eventSender;
33-
final LDUser basicUser;
38+
final List<Event.FeatureRequest> featureRequestEventsWithoutTracking = new ArrayList<>();
39+
final List<Event.FeatureRequest> featureRequestEventsWithTracking = new ArrayList<>();
3440
final Random random;
3541

3642
public BenchmarkInputs() {
@@ -44,9 +50,30 @@ public BenchmarkInputs() {
4450
.eventSender(new MockEventSenderFactory())
4551
.createEventProcessor(TestValues.SDK_KEY, new LDConfig.Builder().build());
4652

47-
basicUser = new LDUser("userkey");
48-
4953
random = new Random();
54+
55+
for (int i = 0; i < TEST_EVENTS_COUNT; i++) {
56+
String flagKey = "flag" + random.nextInt(FLAG_COUNT);
57+
int version = random.nextInt(FLAG_VERSIONS) + 1;
58+
int variation = random.nextInt(FLAG_VARIATIONS);
59+
for (boolean trackEvents: new boolean[] { false, true }) {
60+
Event.FeatureRequest event = new Event.FeatureRequest(
61+
System.currentTimeMillis(),
62+
flagKey,
63+
BASIC_USER,
64+
version,
65+
variation,
66+
LDValue.of(variation),
67+
LDValue.ofNull(),
68+
null,
69+
null,
70+
trackEvents,
71+
null,
72+
false
73+
);
74+
(trackEvents ? featureRequestEventsWithTracking : featureRequestEventsWithoutTracking).add(event);
75+
}
76+
}
5077
}
5178

5279
public String randomFlagKey() {
@@ -64,22 +91,7 @@ public int randomFlagVariation() {
6491

6592
@Benchmark
6693
public void summarizeFeatureRequestEvents(BenchmarkInputs inputs) throws Exception {
67-
for (int i = 0; i < 1000; i++) {
68-
int variation = inputs.randomFlagVariation();
69-
Event.FeatureRequest event = new Event.FeatureRequest(
70-
System.currentTimeMillis(),
71-
inputs.randomFlagKey(),
72-
inputs.basicUser,
73-
inputs.randomFlagVersion(),
74-
variation,
75-
LDValue.of(variation),
76-
LDValue.ofNull(),
77-
null,
78-
null,
79-
false, // trackEvents == false: only summary counts are generated
80-
null,
81-
false
82-
);
94+
for (Event.FeatureRequest event: inputs.featureRequestEventsWithoutTracking) {
8395
inputs.eventProcessor.sendEvent(event);
8496
}
8597
inputs.eventProcessor.flush();
@@ -88,22 +100,7 @@ public void summarizeFeatureRequestEvents(BenchmarkInputs inputs) throws Excepti
88100

89101
@Benchmark
90102
public void featureRequestEventsWithFullTracking(BenchmarkInputs inputs) throws Exception {
91-
for (int i = 0; i < 1000; i++) {
92-
int variation = inputs.randomFlagVariation();
93-
Event.FeatureRequest event = new Event.FeatureRequest(
94-
System.currentTimeMillis(),
95-
inputs.randomFlagKey(),
96-
inputs.basicUser,
97-
inputs.randomFlagVersion(),
98-
variation,
99-
LDValue.of(variation),
100-
LDValue.ofNull(),
101-
null,
102-
null,
103-
true, // trackEvents == true: the full events are included in the output
104-
null,
105-
false
106-
);
103+
for (Event.FeatureRequest event: inputs.featureRequestEventsWithTracking) {
107104
inputs.eventProcessor.sendEvent(event);
108105
}
109106
inputs.eventProcessor.flush();
@@ -112,16 +109,8 @@ public void featureRequestEventsWithFullTracking(BenchmarkInputs inputs) throws
112109

113110
@Benchmark
114111
public void customEvents(BenchmarkInputs inputs) throws Exception {
115-
LDValue data = LDValue.of("data");
116-
for (int i = 0; i < 1000; i++) {
117-
Event.Custom event = new Event.Custom(
118-
System.currentTimeMillis(),
119-
"event-key",
120-
inputs.basicUser,
121-
data,
122-
null
123-
);
124-
inputs.eventProcessor.sendEvent(event);;
112+
for (int i = 0; i < TEST_EVENTS_COUNT; i++) {
113+
inputs.eventProcessor.sendEvent(CUSTOM_EVENT);
125114
}
126115
inputs.eventProcessor.flush();
127116
EventProcessorInternals.waitUntilInactive(inputs.eventProcessor);

benchmarks/src/jmh/java/com/launchdarkly/sdk/server/TestValues.java

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package com.launchdarkly.sdk.server;
22

3+
import com.launchdarkly.client.Event;
34
import com.launchdarkly.client.LDUser;
45
import com.launchdarkly.client.value.LDValue;
56

@@ -11,6 +12,8 @@ private TestValues() {}
1112

1213
public static final String SDK_KEY = "sdk-key";
1314

15+
public static final LDUser BASIC_USER = new LDUser("userkey");
16+
1417
public static final String BOOLEAN_FLAG_KEY = "flag-bool";
1518
public static final String INT_FLAG_KEY = "flag-int";
1619
public static final String STRING_FLAG_KEY = "flag-string";
@@ -49,4 +52,16 @@ private TestValues() {}
4952
new LDUser.Builder("key").custom(CLAUSE_MATCH_ATTRIBUTE, NOT_MATCHED_VALUE).build();
5053

5154
public static final String EMPTY_JSON_DATA = "{\"flags\":{},\"segments\":{}}";
55+
56+
public static final int TEST_EVENTS_COUNT = 1000;
57+
58+
public static final LDValue CUSTOM_EVENT_DATA = LDValue.of("data");
59+
60+
public static final Event.Custom CUSTOM_EVENT = new Event.Custom(
61+
System.currentTimeMillis(),
62+
"event-key",
63+
BASIC_USER,
64+
CUSTOM_EVENT_DATA,
65+
null
66+
);
5267
}

0 commit comments

Comments
 (0)