Skip to content

Commit

Permalink
Merge pull request #125 from dbist/shared
Browse files Browse the repository at this point in the history
tpcc workload
  • Loading branch information
dbist authored Apr 22, 2021
2 parents 729b7fe + d2bdb6d commit 2cc8266
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 46 deletions.
66 changes: 21 additions & 45 deletions cockroach-secure-pgbouncer/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,77 +40,53 @@ PGBouncer is being load balanced via `haproxy`, it can be verified by inspecting
```bash
DATABASES_HOST=lb
DATABASES_PORT=26257
DATABASES_DBNAME=defaultdb
DATABASES_DBNAME=tpcc
```

### Connect as root
## Connect to PGBouncer from client, will connect to the database specified by the database PGBouncer is configured to

Connect to `cockroach sql` cli using explicit connection, note, client cert for roach is generated using PGBouncer CA, root will need its own PGBouncer CA generated cert.

```bash
docker exec -it client cockroach sql --insecure --url 'postgres://root@pgbouncer:27000'
docker exec -it client cockroach sql --certs-dir=/shared/certs --host=pgbouncer --port=27000 --user=roach
```

The port for connection string is the PGBouncer port, again inspecting the PGBouncer config file
### Load the TPCC workload

This will load 2 GB of data for 10 warehouses, follow the tutorial [here](https://www.cockroachlabs.com/docs/v20.2/performance-benchmarking-with-tpcc-local.html)

```bash
PGBOUNCER_LISTEN_PORT=27000
docker exec -it client cockroach workload fixtures import tpcc \
--warehouses=10 'postgresql://roach@lb:26257/tpcc?sslcert=/certs%2Fclient.roach.crt&sslkey=/certs%2Fclient.roach.key&sslmode=verify-full&sslrootcert=/certs%2Fca.crt'
```

### Connect as roach
### Run the workload

```bash
docker exec -it client cockroach sql --insecure --url 'postgres://roach@pgbouncer:27000'
docker exec -it client cockroach workload run tpcc \
--warehouses=10 \
--ramp=3m \
--duration=10m \
--concurrency=20 \
'postgresql://roach@pgbouncer:27000/tpcc?sslcert=/shared/certs%2Fclient.roach.crt&sslkey=/shared/certs%2Fclient.roach.key&sslmode=verify-full&sslrootcert=/shared/certs%2Fca.crt'
```

### passing sslmode to the connection string invalidates the need to pass --insecure
### with concurrency=10

```bash
docker exec -it client cockroach sql --url 'postgres://roach@pgbouncer:27000?sslmode=disable'
Initializing 20 connections...
Initializing 100 workers and preparing statements...
I210422 15:35:56.138478 1 workload/cli/run.go:387 creating load generator... done (took 1.3393289s)
```

3. visit the [HAProxy UI](http://localhost:8081)

### Open Interactive Shells
```bash
docker exec -ti roach-0 /bin/bash
docker exec -ti roach-1 /bin/bash
docker exec -ti roach-2 /bin/bash
docker exec -ti lb /bin/sh
docker exec -ti client /bin/bash

# shell
docker exec -ti roach-cert /bin/sh

# cli inside the container
cockroach sql --insecure --host=roach-0

# directly
docker exec -ti client cockroach sql --insecure --host=roach-0
```

4. Inspect the PGBouncer logs

```bash
docker logs pgbouncer
```

5. Connect to `cockroach sql` cli using explicit connection, note, client cert for roach is generated using PGBouncer CA, root will need its own PGBouncer CA generated cert.

```
docker exec -it pgbouncer cockroach sql --certs-dir=certs --host=pgbouncer --port=27000 --user=roach
```

```
docker exec -it pgbouncer cockroach sql --certs-dir=certs --url "postgresql://roach@pgbouncer:27000/defaultdb?sslmode=verify-full"
```

## Run a tpcc workload using PGBouncer connection

TPCC instructions are located [here](https://www.cockroachlabs.com/docs/v20.2/performance-benchmarking-with-tpcc-local.html).

```
docker exec -it pgbouncer cockroach workload run tpcc --duration=120m --concurrency=5 --warehouses 5 --drop --max-rate=1000 --tolerate-errors 'postgresql://roach@pgbouncer:27000/tpcc?sslcert=certs%2Fclient.roach.crt&sslkey=certs%2Fclient.roach.key&sslmode=verify-full&sslrootcert=certs%2Fca.crt&application_name=pgbouncer'
```

6. Connecting to non-PGBouncer connections can be done the following ways

```
Expand Down
4 changes: 4 additions & 0 deletions cockroach-secure-pgbouncer/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ volumes:
certs-roach-2:
certs-pgbouncer:
certs-client:
shared:
driver: local

services:

Expand Down Expand Up @@ -76,6 +78,7 @@ services:
volumes:
- ${PWD}/pgbouncer:/pgbouncer
- certs-pgbouncer:/certs
- shared:/shared
env_file:
- pgbouncer/cockroachdb.env
ulimits:
Expand All @@ -97,3 +100,4 @@ services:
- pgbouncer
volumes:
- certs-client:/certs
- shared:/shared
2 changes: 1 addition & 1 deletion cockroach-secure-pgbouncer/pgbouncer/cockroachdb.env
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
DATABASES_HOST=lb
DATABASES_PORT=26257
DATABASES_DBNAME=defaultdb
DATABASES_DBNAME=tpcc

PGBOUNCER_POOL_MODE=session
PGBOUNCER_LISTEN_PORT=27000
Expand Down
8 changes: 8 additions & 0 deletions cockroach-secure-pgbouncer/up.sh
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,11 @@ docker-compose exec roach-0 \
docker-compose exec roach-0 \
/cockroach/cockroach sql \
--certs-dir=/certs --host=roach-0 --execute="GRANT ADMIN TO roach;"

# Need to copy client certs for roach generated using PGBouncer CA to /shared directory
docker-compose exec --user root pgbouncer \
cp -r certs /shared/

docker-compose exec roach-0 \
/cockroach/cockroach sql \
--certs-dir=/certs --host=roach-0 --execute="CREATE DATABASE tpcc;"

0 comments on commit 2cc8266

Please sign in to comment.