From c8a27d024ea23446ed1282da3cbcc27ec25bbc76 Mon Sep 17 00:00:00 2001 From: TheR1sing3un Date: Sat, 15 Jul 2023 18:30:06 +0800 Subject: [PATCH 1/2] feat(benchmark): initialize new module: benchmark 1. initialize new module: benchmark --- benchmark/pom.xml | 52 +++++++++++++++++++ .../dledger/DLedgerServerBenchmark.java | 20 +++++++ pom.xml | 13 +++++ 3 files changed, 85 insertions(+) create mode 100644 benchmark/pom.xml create mode 100644 benchmark/src/main/java/io/openmessaging/storage/dledger/DLedgerServerBenchmark.java diff --git a/benchmark/pom.xml b/benchmark/pom.xml new file mode 100644 index 00000000..d2347a24 --- /dev/null +++ b/benchmark/pom.xml @@ -0,0 +1,52 @@ + + + + + 4.0.0 + + io.openmessaging.storage + dledger-all + 0.3.3-SNAPSHOT + + + io.openmessaging.storage.dledger + benchmark + + + + io.openmessaging.storage + dledger + + + org.openjdk.jmh + jmh-core + + + org.openjdk.jmh + jmh-generator-annprocess + + + + + 8 + 8 + UTF-8 + + + \ No newline at end of file diff --git a/benchmark/src/main/java/io/openmessaging/storage/dledger/DLedgerServerBenchmark.java b/benchmark/src/main/java/io/openmessaging/storage/dledger/DLedgerServerBenchmark.java new file mode 100644 index 00000000..88ad9a92 --- /dev/null +++ b/benchmark/src/main/java/io/openmessaging/storage/dledger/DLedgerServerBenchmark.java @@ -0,0 +1,20 @@ +/* + * Copyright 2017-2022 The DLedger Authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package io.openmessaging.storage.dledger; + +public class DLedgerServerBenchmark { +} diff --git a/pom.xml b/pom.xml index adb53d75..04daa45d 100644 --- a/pom.xml +++ b/pom.xml @@ -45,6 +45,8 @@ 5.1.0 jacoco 3.12.0 + 1.23 + 1.23 ${project.basedir}/../test/target/jacoco-it.exec file:**/generated-sources/**,**/test/** @@ -55,6 +57,7 @@ dledger proxy example + benchmark @@ -116,6 +119,16 @@ commons-lang3 ${commons-lang3.version} + + org.openjdk.jmh + jmh-core + ${jmh-core.version} + + + org.openjdk.jmh + jmh-generator-annprocess + ${jmh-generator-annprocess.version} + From 1fc949af79e550ad5267d7d3d21e0845d6af0bb5 Mon Sep 17 00:00:00 2001 From: TheR1sing3un Date: Sat, 15 Jul 2023 21:58:27 +0800 Subject: [PATCH 2/2] feat(example): add latency metrics report in benchmark 1. add latency metrics report in benchmark --- benchmark/pom.xml | 52 ------------------- .../dledger/DLedgerServerBenchmark.java | 20 ------- example/pom.xml | 5 ++ .../example/register/RegisterBenchmark.java | 38 ++++++++++---- pom.xml | 13 ----- 5 files changed, 32 insertions(+), 96 deletions(-) delete mode 100644 benchmark/pom.xml delete mode 100644 benchmark/src/main/java/io/openmessaging/storage/dledger/DLedgerServerBenchmark.java diff --git a/benchmark/pom.xml b/benchmark/pom.xml deleted file mode 100644 index d2347a24..00000000 --- a/benchmark/pom.xml +++ /dev/null @@ -1,52 +0,0 @@ - - - - - 4.0.0 - - io.openmessaging.storage - dledger-all - 0.3.3-SNAPSHOT - - - io.openmessaging.storage.dledger - benchmark - - - - io.openmessaging.storage - dledger - - - org.openjdk.jmh - jmh-core - - - org.openjdk.jmh - jmh-generator-annprocess - - - - - 8 - 8 - UTF-8 - - - \ No newline at end of file diff --git a/benchmark/src/main/java/io/openmessaging/storage/dledger/DLedgerServerBenchmark.java b/benchmark/src/main/java/io/openmessaging/storage/dledger/DLedgerServerBenchmark.java deleted file mode 100644 index 88ad9a92..00000000 --- a/benchmark/src/main/java/io/openmessaging/storage/dledger/DLedgerServerBenchmark.java +++ /dev/null @@ -1,20 +0,0 @@ -/* - * Copyright 2017-2022 The DLedger Authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package io.openmessaging.storage.dledger; - -public class DLedgerServerBenchmark { -} diff --git a/example/pom.xml b/example/pom.xml index 017f180b..80a8bfa5 100644 --- a/example/pom.xml +++ b/example/pom.xml @@ -24,6 +24,11 @@ org.slf4j slf4j-simple + + io.dropwizard.metrics + metrics-core + 4.2.7 + org.junit.jupiter junit-jupiter-api diff --git a/example/src/main/java/io/openmessaging/storage/dledger/example/register/RegisterBenchmark.java b/example/src/main/java/io/openmessaging/storage/dledger/example/register/RegisterBenchmark.java index 6cf46523..85115974 100644 --- a/example/src/main/java/io/openmessaging/storage/dledger/example/register/RegisterBenchmark.java +++ b/example/src/main/java/io/openmessaging/storage/dledger/example/register/RegisterBenchmark.java @@ -16,9 +16,15 @@ package io.openmessaging.storage.dledger.example.register; +import com.codahale.metrics.Counter; +import com.codahale.metrics.Histogram; +import com.codahale.metrics.Meter; +import com.codahale.metrics.MetricRegistry; +import com.codahale.metrics.Slf4jReporter; import io.openmessaging.storage.dledger.example.register.client.RegisterDLedgerClient; import io.openmessaging.storage.dledger.example.register.protocol.RegisterReadResponse; import io.openmessaging.storage.dledger.example.register.protocol.RegisterWriteResponse; +import io.openmessaging.storage.dledger.utils.DLedgerUtils; import java.util.concurrent.CyclicBarrier; import java.util.concurrent.TimeUnit; import org.apache.commons.lang3.time.StopWatch; @@ -39,6 +45,13 @@ public class RegisterBenchmark { private BenchmarkType benchmarkType; + private Slf4jReporter reporter; + private Histogram latency; + + private Meter tps; + + private Counter errorCounter; + public enum BenchmarkType { Write, Read, @@ -51,6 +64,12 @@ public RegisterBenchmark(String group, String peers, int clientNum, long operati this.clientNum = clientNum; this.operationNumPerClient = operationNumPerClient; this.benchmarkType = benchmarkType; + MetricRegistry registry = new MetricRegistry(); + reporter = Slf4jReporter.forRegistry(registry).convertRatesTo(TimeUnit.SECONDS) + .convertDurationsTo(TimeUnit.MILLISECONDS).build(); + latency = registry.histogram("request_latency_ms"); + tps = registry.meter("request_tps"); + errorCounter = registry.counter("error_request_num"); } public void start() throws Exception { @@ -65,14 +84,13 @@ public void start() throws Exception { new Thread() { @Override public void run() { - long success = 0; - long failNum = 0; RegisterDLedgerClient client = new RegisterDLedgerClient(group, peers); client.startup(); try { barrier.await(); - while (success < operationNumPerClient) { + for (int i = 0; i < operationNumPerClient; i++) { int code = 200; + long start = System.currentTimeMillis(); if (benchmarkType == BenchmarkType.Read) { // Read RegisterReadResponse resp = client.read(13); @@ -83,18 +101,16 @@ public void run() { code = resp.getCode(); } if (code == 200) { - success++; + tps.mark(); + latency.update(DLedgerUtils.elapsed(start)); } else { - failNum++; + errorCounter.inc(); } } barrier.await(); - client.shutdown(); } catch (Exception e) { logger.error("client {} error", operationType, e); } finally { - logger.info("client {} finished, need {} total: {}, success: {}, fail: {}", - operationType, operationType, operationNumPerClient, success, failNum); client.shutdown(); } } @@ -104,9 +120,9 @@ public void run() { StopWatch stopWatch = StopWatch.createStarted(); barrier.await(); final long cost = stopWatch.getTime(TimeUnit.MILLISECONDS); - final long tps = Math.round(totalOperation * 1000 / cost); - logger.info("Test type: {}, client num : {}, operation num per client: {}, total operation num: {}, cost: {}, tps: {}", - operationType, clientNum, operationNumPerClient, totalOperation, cost, tps); + logger.info("Test type: {}, client num : {}, operation num per client: {}, total operation num: {}, cost: {}}", + operationType, clientNum, operationNumPerClient, totalOperation, cost); + reporter.report(); } } diff --git a/pom.xml b/pom.xml index 04daa45d..adb53d75 100644 --- a/pom.xml +++ b/pom.xml @@ -45,8 +45,6 @@ 5.1.0 jacoco 3.12.0 - 1.23 - 1.23 ${project.basedir}/../test/target/jacoco-it.exec file:**/generated-sources/**,**/test/** @@ -57,7 +55,6 @@ dledger proxy example - benchmark @@ -119,16 +116,6 @@ commons-lang3 ${commons-lang3.version} - - org.openjdk.jmh - jmh-core - ${jmh-core.version} - - - org.openjdk.jmh - jmh-generator-annprocess - ${jmh-generator-annprocess.version} -