Skip to content

Commit aa30362

Browse files
authored
test: add client performance/benchmark test (#312)
* feat: client performance test
1 parent 123fa8a commit aa30362

6 files changed

Lines changed: 399 additions & 4 deletions

File tree

.circleci/config.yml

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,8 @@ commands:
3838
parameters:
3939
maven-image:
4040
type: string
41+
junit-tests:
42+
type: string
4143
steps:
4244
- restore_cache:
4345
name: Restoring Maven Cache
@@ -47,7 +49,7 @@ commands:
4749
- run:
4850
name: "Running tests"
4951
command: |
50-
mvn -B -U clean install -Dmaven.javadoc.skip=true -Dmaven.dokka.skip=true -Dbuild.env=CI
52+
mvn -B -U clean install -Dmaven.javadoc.skip=true -Dmaven.dokka.skip=true -Dbuild.env=CI << parameters.junit-tests >>
5153
- save_cache:
5254
name: Saving Maven Cache
5355
key: *cache-key
@@ -111,6 +113,9 @@ jobs:
111113
influxdb-image:
112114
type: string
113115
default: &default-influxdb-image "influxdb:latest"
116+
junit-tests:
117+
type: string
118+
default: ""
114119
docker:
115120
- image: << parameters.maven-image >>
116121
- image: &influx-image << parameters.influxdb-image >>
@@ -126,10 +131,12 @@ jobs:
126131
environment:
127132
INFLUXDB_2_ONBOARDING_IP: influxdb_v2_onboarding
128133
INFLUXDB_2_ONBOARDING_PORT: 9999
134+
resource_class: large
129135
steps:
130136
- prepare
131137
- client-test:
132138
maven-image: << parameters.maven-image >>
139+
junit-tests: << parameters.junit-tests>>
133140
- storing-test-results
134141
- storing-artifacts
135142
- run:
@@ -197,6 +204,9 @@ workflows:
197204
- tests-java:
198205
name: jdk-8-nightly
199206
influxdb-image: "quay.io/influxdb/influxdb:nightly"
207+
- tests-java:
208+
name: client-benchmark
209+
junit-tests: "-DclientBenchmark=true -Dit.test=com.influxdb.client.ITBenchmarkTest -DfailIfNoTests=false -Dtest=ignore -DwildcardSuites=ignore"
200210
- deploy-snapshot:
201211
requires:
202212
- jdk-8

client/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,7 @@
171171
<artifactId>toml4j</artifactId>
172172
<scope>test</scope>
173173
</dependency>
174-
174+
175175
</dependencies>
176176

177177
</project>
Lines changed: 122 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,122 @@
1+
/*
2+
* The MIT License
3+
*
4+
* Permission is hereby granted, free of charge, to any person obtaining a copy
5+
* of this software and associated documentation files (the "Software"), to deal
6+
* in the Software without restriction, including without limitation the rights
7+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8+
* copies of the Software, and to permit persons to whom the Software is
9+
* furnished to do so, subject to the following conditions:
10+
*
11+
* The above copyright notice and this permission notice shall be included in
12+
* all copies or substantial portions of the Software.
13+
*
14+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
20+
* THE SOFTWARE.
21+
*/
22+
package com.influxdb.client;
23+
24+
import java.lang.management.ManagementFactory;
25+
import java.time.Duration;
26+
import java.time.Instant;
27+
28+
import com.influxdb.client.benchmark.BenchmarkOptions;
29+
import com.influxdb.client.benchmark.ClientBenchmark;
30+
import com.influxdb.client.domain.Bucket;
31+
import org.assertj.core.api.Assertions;
32+
import org.junit.jupiter.api.AfterEach;
33+
import org.junit.jupiter.api.BeforeEach;
34+
import org.junit.jupiter.api.Test;
35+
import org.junit.jupiter.api.condition.EnabledIfSystemProperty;
36+
import org.junit.platform.runner.JUnitPlatform;
37+
import org.junit.runner.RunWith;
38+
39+
/**
40+
* Client benchmark test
41+
*/
42+
@RunWith(JUnitPlatform.class)
43+
class ITBenchmarkTest extends AbstractITClientTest {
44+
45+
private BucketsApi bucketsApi;
46+
private Bucket bucket;
47+
48+
@BeforeEach
49+
void setUp() {
50+
bucketsApi = influxDBClient.getBucketsApi();
51+
bucket = bucketsApi.createBucket(generateName("benchmark"), findMyOrg());
52+
}
53+
54+
@AfterEach
55+
void tearDown() {
56+
bucketsApi.deleteBucket(bucket);
57+
}
58+
59+
@Test
60+
@EnabledIfSystemProperty(named = "clientBenchmark", matches = "true")
61+
public void benchmarkBenchmark() throws InterruptedException {
62+
63+
//warmup
64+
clientBenchmark(50, 20, 100, 1_000, 5_000, 10_000_000);
65+
clientBenchmark(500, 20, 100, 1_000, 5_000, 10_000_000);
66+
clientBenchmark(1_000, 20, 100, 1_000, 5_000, 10_000_000);
67+
clientBenchmark(1_500, 20, 100, 1_000, 5_000, 10_000_000);
68+
69+
}
70+
71+
public void clientBenchmark(int numberOfThreads,
72+
int secondsCount,
73+
int lineProtocolsCount,
74+
int flushInterval,
75+
int batchSize,
76+
int maxBufferSize) throws InterruptedException {
77+
78+
console(("\n--- BENCHMARK START ---"));
79+
BenchmarkOptions opts = new BenchmarkOptions(getInfluxDb2Url(), "my-token", "my-org", bucket.getName(),
80+
"sensor_" + System.currentTimeMillis(),
81+
numberOfThreads, secondsCount, lineProtocolsCount, batchSize, maxBufferSize, flushInterval);
82+
83+
Instant startWrite = Instant.now();
84+
com.sun.management.OperatingSystemMXBean osMxBean =
85+
ManagementFactory.getPlatformMXBean(com.sun.management.OperatingSystemMXBean.class);
86+
87+
long cpuTimeStart = osMxBean.getProcessCpuTime();
88+
ClientBenchmark benchmarkWriter = new ClientBenchmark(opts).start();
89+
Instant stopWrite = Instant.now();
90+
long cpuTimeWrite = osMxBean.getProcessCpuTime() - cpuTimeStart;
91+
92+
double count = benchmarkWriter.verify();
93+
Instant stopVerify = Instant.now();
94+
long cpuTimeVerify = osMxBean.getProcessCpuTime() - cpuTimeWrite;
95+
96+
Duration writeDuration = Duration.between(startWrite, stopWrite);
97+
Duration verifyDuration = Duration.between(stopWrite, stopVerify);
98+
99+
double duration = (double) writeDuration.toMillis() / 1000;
100+
double rate = count / duration;
101+
console(String.format("--> total rate: %s msg/s", rate));
102+
console(String.format("--> write duration: %s", writeDuration));
103+
console(String.format("--> write cpu time: %s", Duration.ofNanos(cpuTimeWrite)));
104+
console(String.format("--> verify duration: %s", verifyDuration));
105+
console(String.format("--> verity cpu time: %s", Duration.ofNanos(cpuTimeVerify)));
106+
console(String.format("--> total duration: %s", Duration.between(startWrite, stopVerify)));
107+
console(("--- BENCHMARK FINISH ---"));
108+
109+
int idealRate = lineProtocolsCount * numberOfThreads;
110+
//maximal rate Macbook Pro I9 is cca 80_0000 msg/sec
111+
if (idealRate < 70_000) {
112+
Assertions.assertThat(rate).isGreaterThan(idealRate * 0.8);
113+
}
114+
}
115+
116+
private void console(Object msg) {
117+
System.out.println(msg);
118+
}
119+
120+
}
121+
122+
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
/*
2+
* The MIT License
3+
*
4+
* Permission is hereby granted, free of charge, to any person obtaining a copy
5+
* of this software and associated documentation files (the "Software"), to deal
6+
* in the Software without restriction, including without limitation the rights
7+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8+
* copies of the Software, and to permit persons to whom the Software is
9+
* furnished to do so, subject to the following conditions:
10+
*
11+
* The above copyright notice and this permission notice shall be included in
12+
* all copies or substantial portions of the Software.
13+
*
14+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
20+
* THE SOFTWARE.
21+
*/
22+
package com.influxdb.client.benchmark;
23+
24+
public class BenchmarkOptions {
25+
public final String influxUrl;
26+
public final String org;
27+
public final String bucket;
28+
public final String measurementName;
29+
public final int threadsCount;
30+
public final int secondsCount;
31+
public final int lineProtocolsCount;
32+
public final int batchSize;
33+
public final int flushInterval;
34+
public final int bufferLimit;
35+
public final String token;
36+
37+
public BenchmarkOptions(final String influxUrl,
38+
final String token,
39+
final String org,
40+
final String bucket,
41+
final String measurementName,
42+
final int threadsCount,
43+
final int secondsCount,
44+
final int lineProtocolsCount,
45+
final int batchSize,
46+
final int bufferLimit,
47+
final int flushInterval) {
48+
this.influxUrl = influxUrl;
49+
this.token = token;
50+
this.org = org;
51+
this.bucket = bucket;
52+
this.measurementName = measurementName;
53+
this.threadsCount = threadsCount;
54+
this.secondsCount = secondsCount;
55+
this.lineProtocolsCount = lineProtocolsCount;
56+
this.batchSize = batchSize;
57+
this.bufferLimit = bufferLimit;
58+
this.flushInterval = flushInterval;
59+
}
60+
}

0 commit comments

Comments
 (0)