Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[ISSUE #299] Add TPS and latency report in benchmark command #300

Merged
merged 2 commits into from
Jul 16, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions example/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,11 @@
<groupId>org.slf4j</groupId>
<artifactId>slf4j-simple</artifactId>
</dependency>
<dependency>
<groupId>io.dropwizard.metrics</groupId>
<artifactId>metrics-core</artifactId>
<version>4.2.7</version>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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,
Expand All @@ -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 {
Expand All @@ -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);
Expand All @@ -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();
}
}
Expand All @@ -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();
}

}