> ## Documentation Index
> Fetch the complete documentation index at: https://www.cockroachlabs.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Performance Benchmarking with TPC-C

export const InternalLink = ({version, path = "", children, ...props}) => {
  let detectedVersion = version || "stable";
  if (typeof window !== 'undefined' && !version) {
    const match = window.location.pathname.match(/\/docs\/([^/]+)/);
    if (match) {
      detectedVersion = match[1];
    }
  }
  const normalizedPath = path.startsWith("/") ? path.slice(1) : path;
  return <a href={`/docs/${detectedVersion}/${normalizedPath}`} {...props}>
      {children}
    </a>;
};

This page shows you how to reproduce <InternalLink path="performance#scale">CockroachDB TPC-C performance benchmarking results</InternalLink>. Across all scales, CockroachDB can process tpmC (new order transactions per minute) at near maximum efficiency. Start by choosing the scale you're interested in:

| Workload             | Cluster size                                            | Warehouses | Data size |
| -------------------- | ------------------------------------------------------- | ---------- | --------- |
| Local                | 3 nodes on your laptop                                  | 10         | 2 GB      |
| Local (multi-region) | 9 in-memory nodes on your laptop using `cockroach demo` | 10         | 2 GB      |
| Small                | 3 nodes on `c5d.4xlarge` machines                       | 2500       | 200 GB    |
| Medium               | 15 nodes on `c5d.4xlarge` machines                      | 13,000     | 1.04 TB   |
| Large                | 81 nodes on `c5d.9xlarge` machines                      | 140,000    | 11.2 TB   |

## Before you begin

* TPC-C provides the most realistic and objective measure for OLTP performance at various scale factors. Before you get started, consider reviewing <InternalLink path="performance#tpc-c">what TPC-C is and how it is measured</InternalLink>.
* Make sure you have already <InternalLink path="install-cockroachdb">installed CockroachDB</InternalLink>.

## Step 1. Start CockroachDB

<Danger>
  The `--insecure` flag used in this tutorial is intended for non-production testing only. To run CockroachDB in production, use a secure cluster instead.
</Danger>

In the terminal, use the <InternalLink path="cockroach-demo">`cockroach demo`</InternalLink> command to start a simulated multi-region cluster with 9 nodes:

```shell theme={"theme":{"light":"catppuccin-mocha","dark":"catppuccin-mocha"}}
cockroach demo --global --nodes 9 --no-example-database --insecure
```

This simulated multi-region deployment will take advantage of CockroachDB's <InternalLink path="multiregion-overview">multi-region SQL statements</InternalLink> to deliver improved ease of use and performance.

<Note>
  You must use the IP address shown at the SQL prompt to run the following steps.

  This is necessary because the demo cluster may use a randomly allocated local IP that is not the `127.0.0.1` shown here.
</Note>

## Step 2. Import the TPC-C dataset

CockroachDB comes with a number of <InternalLink path="cockroach-workload">built-in workloads</InternalLink> for simulating client traffic. This step features CockroachDB's version of the [TPC-C](http://www.tpc.org/tpcc) workload.

In a second terminal window (call it terminal 2), use <InternalLink path="cockroach-workload">`cockroach workload`</InternalLink> to load the initial schema and data:

```shell theme={"theme":{"light":"catppuccin-mocha","dark":"catppuccin-mocha"}}
cockroach workload init tpcc \
--warehouses=10 \
--partitions=3 \
--survival-goal zone \
--regions=europe-west1,us-east1,us-west1 \
'postgresql://root@127.0.0.1:26257/tpcc?sslmode=disable'
```

This will load 2 GB of data for 10 "warehouses", and spread the data across all 3 regions with a <InternalLink path="multiregion-survival-goals#survive-zone-failures">`ZONE` survival goal</InternalLink>.

## Step 3. Run the benchmark

Run the workload for 10 "warehouses" of data for ten minutes. In order to spread the simulated workload across the 3 regions specified in the previous step, you will need to start each of the following commands from 3 different terminals:

In terminal 2:

```sql theme={"theme":{"light":"catppuccin-mocha","dark":"catppuccin-mocha"}}
cockroach workload run tpcc \
--warehouses=10 \
--duration=10m \
--wait=true \
--partitions=3 \
--partition-affinity=0 \
--tolerate-errors \
--survival-goal zone \
--regions=europe-west1,us-east1,us-west1 \
'postgresql://root@127.0.0.1:26257/tpcc?sslmode=disable'
```

In terminal 3:

```sql theme={"theme":{"light":"catppuccin-mocha","dark":"catppuccin-mocha"}}
cockroach workload run tpcc \
--warehouses=10 \
--duration=10m \
--wait=true \
--partitions=3 \
--partition-affinity=1 \
--tolerate-errors \
--survival-goal zone \
--regions=europe-west1,us-east1,us-west1 \
'postgresql://root@127.0.0.1:26260/tpcc?sslmode=disable'
```

In terminal 4:

```sql theme={"theme":{"light":"catppuccin-mocha","dark":"catppuccin-mocha"}}
cockroach workload run tpcc \
--warehouses=10 \
--duration=10m \
--wait=true \
--partitions=3 \
--partition-affinity=2 \
--tolerate-errors \
--survival-goal zone \
--regions=europe-west1,us-east1,us-west1 \
'postgresql://root@127.0.0.1:26263/tpcc?sslmode=disable'
```

You'll see per-operation statistics every second:

```text theme={"theme":{"light":"catppuccin-mocha","dark":"catppuccin-mocha"}}
Initializing 20 connections...
Initializing 100 workers and preparing statements...
_elapsed___errors__ops/sec(inst)___ops/sec(cum)__p50(ms)__p95(ms)__p99(ms)_pMax(ms)
    1.0s        0            0.0            0.0      0.0      0.0      0.0      0.0 delivery
    1.0s        0            0.0            0.0      0.0      0.0      0.0      0.0 newOrder
...
  105.0s        0            0.0            0.2      0.0      0.0      0.0      0.0 delivery
  105.0s        0            4.0            1.8     44.0     46.1     46.1     46.1 newOrder
  105.0s        0            0.0            0.2      0.0      0.0      0.0      0.0 orderStatus
  105.0s        0            1.0            2.0     14.7     14.7     14.7     14.7 payment
  105.0s        0            0.0            0.2      0.0      0.0      0.0      0.0 stockLevel
...
```

<Tip>
  For more `tpcc` options, use `cockroach workload run tpcc --help`. For details about other built-in load generators, use `cockroach workload run --help`.
</Tip>

## Step 4. Interpret the results

Once the `workload` has finished running, you'll see a final output line in each terminal window.

In terminal 2:

```text theme={"theme":{"light":"catppuccin-mocha","dark":"catppuccin-mocha"}}
_elapsed_______tpmC____efc__avg(ms)__p50(ms)__p90(ms)__p95(ms)__p99(ms)_pMax(ms)
  600.0s       36.5  33.2%    170.6     44.0    536.9    872.4   1543.5   3087.0
```

In terminal 3:

```text theme={"theme":{"light":"catppuccin-mocha","dark":"catppuccin-mocha"}}
_elapsed_______tpmC____efc__avg(ms)__p50(ms)__p90(ms)__p95(ms)__p99(ms)_pMax(ms)
  600.0s       36.5  28.4%    147.0     41.9    453.0    671.1   1342.2   1946.2
```

In terminal 4:

```text theme={"theme":{"light":"catppuccin-mocha","dark":"catppuccin-mocha"}}
_elapsed_______tpmC____efc__avg(ms)__p50(ms)__p90(ms)__p95(ms)__p99(ms)_pMax(ms)
  600.0s       36.5  28.4%    222.8     46.1    704.6   1140.9   1744.8   2952.8
```

You will also see some audit checks and latency statistics for each individual query in each terminal. Some of those checks might indicate that they were `SKIPPED` due to insufficient data since this is a small run on a small machine. For a more comprehensive test, run `workload` for a longer duration (e.g., two hours). The `tpmC` (new order transactions/minute) number is the headline number and `efc` ("efficiency") tells you how close CockroachDB gets to theoretical maximum `tpmC`. In a perfect execution, the sum of efficiency across all partitions would be 100%.

## Step 5. Clean up

When you're done with your test cluster, switch back to terminal 1 where <InternalLink path="cockroach-demo">`cockroach demo`</InternalLink> is still running and issue `\q` at the SQL prompt to gracefully shut down the demo cluster.

```sql theme={"theme":{"light":"catppuccin-mocha","dark":"catppuccin-mocha"}}
\q
```
