Skip to content

Commit

Permalink
[#22537] YSQL: Benchmark restart read requests metric.
Browse files Browse the repository at this point in the history
  • Loading branch information
pao214 committed Aug 2, 2024
1 parent 29db96c commit 3ceb30e
Show file tree
Hide file tree
Showing 9 changed files with 549 additions and 13 deletions.
12 changes: 6 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,19 +10,19 @@ The workloads here have drivers compatible with the above and emulate a number o
## Running the generator

Download the [latest yb-sample-apps](https://github.com/yugabyte/yb-sample-apps/releases/latest) JAR. The command below downloads version 1.4.1.
```
```console
$ wget https://github.com/yugabyte/yb-sample-apps/releases/download/v1.4.1/yb-sample-apps.jar
```

For help, simply run the following:

```
```console
$ java -jar yb-sample-apps.jar --help
```
You should see the set of workloads available in the app.

To get details on running any app, just pass the app name as a parameter to the `--help` flag:
```
```console
$ java -jar yb-sample-apps.jar --help CassandraKeyValue
1 [main] INFO com.yugabyte.sample.Main - Starting sample app...
Usage and options for workload CassandraKeyValue in YugabyteDB Sample Apps.
Expand Down Expand Up @@ -57,18 +57,18 @@ You need the following to build:
* Maven version 3.3.9 or above

To build, simply run the following:
```
```console
$ mvn -DskipTests -DskipDockerBuild package
```

You can find the executable one-jar at the following location:
```
```console
$ ls target/yb-sample-apps.jar
target/yb-sample-apps.jar
```

To docker image with the package, simply run the following:
```
```console
$ mvn package
```

Expand Down
18 changes: 14 additions & 4 deletions src/main/java/com/yugabyte/sample/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
* |__ Main.java
* |__ apps/
* |__ AppBase.java : Base class for all the apps. Has helper methods for creating
* Cassandra and Redis clients.
* YSQL, Cassandra and Redis clients.
* |__ AppConfig.java : Configuration for all the apps.
* |__ CassandraHelloWorld.java : The simplest app that writes one employee record. Good
* starting point to understand how to write a Cassandra app.
Expand All @@ -51,6 +51,7 @@
* |__ RedisPipelinedKeyValue.java : Similar to RedisKeyValue but uses pipelined mode.
* |__ RedisHashPipelined : Similar to RedisPipelinedKeyValue. Uses HMSET/HMGET instead.
* |__ RedisYBClientKeyValue.java : Similar to RedisKeyValue but uses YBJedis client.
* |__ SqlStaleReadDetector.java : Simple SQL app that detects any stale reads.
*
*
* Usage
Expand Down Expand Up @@ -176,14 +177,21 @@ public void run() throws Exception {
}

// Create the reader and writer threads.
if (AppBase.appConfig.concurrencyDisabled) {
LOG.info("Concurrency is disabled. Executing threads in lock step.");
}
int idx = 0;
for (; idx < cmdLineOpts.getNumWriterThreads(); idx++) {
iopsThreads.add(new IOPSThread(idx, cmdLineOpts.createAppInstance(),
IOType.Write, app.appConfig.printAllExceptions));
IOType.Write, app.appConfig.printAllExceptions,
app.appConfig.concurrencyDisabled,
app.appConfig.maxWriteThreadThroughput));
}
for (; idx < cmdLineOpts.getNumWriterThreads() + cmdLineOpts.getNumReaderThreads(); idx++) {
iopsThreads.add(new IOPSThread(idx, cmdLineOpts.createAppInstance(),
IOType.Read, app.appConfig.printAllExceptions));
IOType.Read, app.appConfig.printAllExceptions,
app.appConfig.concurrencyDisabled,
app.appConfig.maxReadThreadThroughput));
}

app.recordExistingRowCount();
Expand Down Expand Up @@ -222,7 +230,9 @@ private void setupForPureReads() {
LOG.info("Using " + num_writers + " writer threads for pure read setup.");
for (int idx = 0; idx < num_writers; idx++) {
writeThreads.add(new IOPSThread(idx, cmdLineOpts.createAppInstance(false),
IOType.Write, app.appConfig.printAllExceptions));
IOType.Write, app.appConfig.printAllExceptions,
app.appConfig.concurrencyDisabled,
app.appConfig.maxWriteThreadThroughput));
}
// Start the reader and writer threads.
for (IOPSThread writeThread : writeThreads) {
Expand Down
24 changes: 23 additions & 1 deletion src/main/java/com/yugabyte/sample/apps/AppBase.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
package com.yugabyte.sample.apps;

import java.io.FileInputStream;
import java.io.IOException;
import java.net.InetAddress;
import java.net.InetSocketAddress;
import java.net.UnknownHostException;
Expand All @@ -39,6 +40,8 @@
import javax.net.ssl.TrustManagerFactory;

import com.yugabyte.sample.common.metrics.Observation;
import com.yugabyte.sample.common.metrics.PromMetrics;

import org.apache.log4j.Logger;

import com.datastax.driver.core.Cluster;
Expand Down Expand Up @@ -75,7 +78,7 @@

/**
* Abstract base class for all apps. This class does the following:
* - Provides various helper methods including methods for creating Redis and Cassandra clients.
* - Provides various helper methods including methods for creating YSQL, YCQL and Redis clients.
* - Has a metrics tracker object, and internally tracks reads and writes.
* - Has the abstract methods that are implemented by the various apps.
*/
Expand Down Expand Up @@ -127,6 +130,9 @@ public abstract class AppBase implements MetricsTracker.StatusMessageAppender {
// YCQL keyspace name.
public static String keyspace = "ybdemo_keyspace";

// Prometheus metrics.
private static PromMetrics promMetrics;

public enum TableOp {
NoOp,
DropTable,
Expand Down Expand Up @@ -643,6 +649,12 @@ public void run() {}
*/
@Override
public void appendMessage(StringBuilder sb) {
if (promMetrics != null) {
sb.append(
"Num restart read requests: " +
promMetrics.getCounter("restart_read_requests", getTableName()) +
" | ");
}
sb.append("Uptime: " + (System.currentTimeMillis() - workloadStartTime) + " ms | ");
}

Expand Down Expand Up @@ -707,6 +719,16 @@ private synchronized void initMetricsTracker() {
metricsTracker.createMetric(MetricName.Write);
metricsTracker.registerStatusMessageAppender(this);
metricsTracker.start();

if (appConfig.restartReadsReported) {
LOG.info("Reporting restart read requests.");
try {
promMetrics = new PromMetrics(getNodesAsInet());
} catch (IOException e) {
LOG.error("Failed to create prometheus metrics tracker with exception: ", e);
promMetrics = null;
}
}
}
}
}
Expand Down
12 changes: 12 additions & 0 deletions src/main/java/com/yugabyte/sample/apps/AppConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -214,4 +214,16 @@ public static enum Type {

// Replication factor to be used for the SqlGeoPartitionedTable workload.
public int replicationFactor;

// Throttle number of reads per second per thread.
public double maxReadThreadThroughput = -1;

// Throttle number of writes per second per thread.
public double maxWriteThreadThroughput = -1;

// Disable concurrent execution, i.e. exec only a single operation at a time.
public boolean concurrencyDisabled = false;

// Flag to report restart read requests.
public boolean restartReadsReported = false;
}
Loading

0 comments on commit 3ceb30e

Please sign in to comment.