Generate Workloads for CockroachDB
A simple workload generator tool for CockroachDB

Search for a command to run...
A simple workload generator tool for CockroachDB

Tips for Efficiently Managing Nulls Using Spring's Named Parameter Binding

A guide to the features of multi-active and multi-region systems

Creating a user-defined composite Money type in CockroachDB

Implementing transaction timeouts in CockroachDB with Spring Boot and JPA/Hibernate

Using 1PC pattern with Spring and CockroachDB

CockroachDB Workload is an easy-to-use command line tool for generating load against CockroachDB.
It includes the following workloads:
ledger - Financial ledger use case using the double-entry principle
order - Purchase orders as part of an e-commerce use case
outbox - Simulates the transactional outbox and inbox patterns
This tool provides an interactive shell for running workloads and monitoring progress and performance. Each workload has an init command to set up the test fixture and one or more run commands to execute the actual workload for a given period of time.
The source code for the workload tool can be found on GitHub.
The project is packaged as a single executable JAR file and runs on any platform for which there is a Java 17+ (LTS) runtime.
CockroachDB, with a trial enterprise license.
Linux / macOS
Java 17
Maven 3+ (optional, embedded wrapper available)
Create a local cluster of at least three nodes:
cockroach start --port=26257 --http-port=8080 --advertise-addr=localhost:26257 --join=localhost:26257 --insecure --store=datafiles/n1 --background
cockroach start --port=26258 --http-port=8081 --advertise-addr=localhost:26258 --join=localhost:26257 --insecure --store=datafiles/n2 --background
cockroach start --port=26259 --http-port=8082 --advertise-addr=localhost:26259 --join=localhost:26257 --insecure --store=datafiles/n3 --background
cockroach init --insecure --host=localhost:26257
Next, set up a database called workload:
cockroach sql --insecure --host=localhost:26257 -e "CREATE database workload"
Install the JDK (Ubuntu example):
sudo apt-get install openjdk-17-jdk
Confirm the installation by running:
java --version
git clone git@github.com:cockroachlabs-field/cockroachdb-workload.git
cd cockroachdb-workload
chmod +x mvnw
./mvnw clean install
Start the shell with:
java -jar target/workload.jar --help
Type help for additional CLI guidance.
The Ledger workload demonstrates a simple financial accounting system using the double-entry bookkeeping principle. The concept is to move funds between accounts using balanced, multi-legged transactions at a high frequency. As a financial system, it will conserve money at all times and provide an audit trail for all transactions performed towards the accounts.
Start the workload shell with:
java -jar target/workload.jar ledger
Then initialize the workload by creating an account plan:
init --help
# or just type 'help'
The commands can run concurrently. The "transfer" command will move funds between random accounts and the "balance" command will just read account balances.
transfer --help
Hint: The ledger workload is implemented using both plain JDBC and JPA with Hibernate as ORM provider. You can switch between these implementations using the
--jpaoption (where JDBC is default).
The Order workload is a basic purchase order creation and reading workload. Order creation and reading workloads can run concurrently.
Start the workload with:
java -jar target/workload.jar order
# Then in the shell:
init
run
The Outbox workload simulates the transactional outbox and inbox design patterns. It writes event records to an outbox table that has TTL and CDC enabled (optional). It can be used to evaluate creating a CDC-based data pipeline and/or the TTL mechanism.
Start the workload with:
java -jar target/workload.jar outbox
# In the shell:
init
run
It's fairly simple to extend this tool with additional workloads. There are skeleton beans available in the "io.cockroachdb.workload.template" namespace that can be copied to a new workload package.
The main steps include:
Implement an init method for setting up the test fixture
Implement a run method for running the workload for a defined period
In this article, we looked at a simple workload tool for CockroachDB using the Java stack. It can be used to send semi-realistic SQL traffic for pure testing and load-testing purposes. It's also quite extendable.