Skip to content

Commit fab08f4

Browse files
committed
adding example with automatic workload + lb
1 parent 08c86c8 commit fab08f4

File tree

8 files changed

+155
-0
lines changed

8 files changed

+155
-0
lines changed

README.md

+1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
## Examples
44
* [NGINX Example](example-nginx/README.md) - Simple 3 node cluster with `NGINX` as the load balancer
55
* [HAProxy Example](example-haproxy/README.md) - Simple 3 node cluster with `HAProxy` as the load balancer
6+
* [HAProxy Example with Workload](example-haproxy-with-workload/README.md) - Simple 3 node cluster with `HAProxy` as the load balancer and a `client` node running the `tpcc` workload
67
* [Enterprise Backup Example](example-enterprise-backup/README.md) - CockroachDB Enterprise `BACKUP` to `NGINX` based "File Server"
78
* [YCSB Functional Example](example-ycsb/README.md) - Building and running [YCSB](https://github.com/brianfrankcooper/YCSB) against a 3 node CockroachDB cluster
89
* [OLTPBench Functional Example](example-oltpbench/README.md) - Building and running a fork of [OLTPBench](https://github.com/timveil-cockroach/oltpbench) against a 3 node CockroachDB cluster
+46
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
# Basic CockroachDB Cluster with HAProxy
2+
Simple 3 node CockroachDB cluster with HAProxy acting as load balancer
3+
4+
## Services
5+
* `crdb-0` - CockroachDB node
6+
* `crdb-1` - CockroachDB node
7+
* `crdb-2` - CockroachDB node
8+
* `workload-client` - CockroachDB node serving as the `workload` client
9+
* `lb` - HAProxy acting as load balancer
10+
11+
## Getting started
12+
1) run `./up.sh`
13+
2) visit the CockroachDB UI @ http://localhost:8080
14+
2) visit the HAProxy UI @ http://localhost:8081
15+
3) have fun!
16+
17+
## Helpful Commands
18+
19+
### Execute SQL
20+
Use the following to execute arbitrary SQL on the CockroachDB cluster. The following creates a database called `test`.
21+
```bash
22+
docker-compose exec crdb-0 /cockroach/cockroach sql --insecure --execute="CREATE DATABASE test;"
23+
```
24+
25+
### Run the TPC-C Workload
26+
Use the following command to run the `tpcc` sample `workload` for 10 minutes. For more details see [this](https://www.cockroachlabs.com/docs/stable/cockroach-workload.html#run-the-tpcc-workload).
27+
28+
```bash
29+
docker-compose exec workload-client /cockroach/cockroach workload run tpcc --duration=10m "postgresql://root@lb:5432?sslmode=disable"
30+
```
31+
32+
### Open Interactive Shells
33+
```bash
34+
docker exec -ti crdb-0 /bin/bash
35+
docker exec -ti crdb-1 /bin/bash
36+
docker exec -ti crdb-2 /bin/bash
37+
docker exec -ti workload-client /bin/bash
38+
docker exec -ti lb /bin/sh
39+
```
40+
41+
### Stop Individual nodes
42+
```bash
43+
docker-compose stop crdb-0
44+
docker-compose stop crdb-1
45+
docker-compose stop crdb-2
46+
```
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
version: '3.5'
2+
3+
services:
4+
5+
crdb-0:
6+
container_name: crdb-0
7+
hostname: crdb-0
8+
image: cockroachdb/cockroach:latest
9+
command: start --logtostderr=WARNING --log-file-verbosity=WARNING --insecure
10+
11+
crdb-1:
12+
container_name: crdb-1
13+
hostname: crdb-1
14+
image: cockroachdb/cockroach:latest
15+
command: start --logtostderr=WARNING --log-file-verbosity=WARNING --insecure --join=crdb-0
16+
depends_on:
17+
- crdb-0
18+
19+
crdb-2:
20+
container_name: crdb-2
21+
hostname: crdb-2
22+
image: cockroachdb/cockroach:latest
23+
command: start --logtostderr=WARNING --log-file-verbosity=WARNING --insecure --join=crdb-0
24+
depends_on:
25+
- crdb-0
26+
27+
lb:
28+
container_name: lb
29+
hostname: lb
30+
build: haproxy
31+
ports:
32+
- "5432:5432"
33+
- "8080:8080"
34+
- "8081:8081"
35+
links:
36+
- crdb-0
37+
- crdb-1
38+
- crdb-2
39+
40+
workload-client:
41+
container_name: workload-client
42+
hostname: workload-client
43+
image: cockroachdb/cockroach:latest
44+
entrypoint: ["tail", "-f", "/dev/null"]
45+
depends_on:
46+
- lb

example-haproxy-with-workload/down.sh

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
#!/bin/bash
2+
3+
docker-compose down --remove-orphans --volumes
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
FROM haproxy:alpine
2+
3+
LABEL maintainer="[email protected]"
4+
5+
COPY haproxy.cfg /usr/local/etc/haproxy/haproxy.cfg
6+
7+
EXPOSE 5432
8+
EXPOSE 8080
9+
EXPOSE 8081
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
global
2+
log stdout format raw local0 info
3+
maxconn 4096
4+
5+
defaults
6+
log global
7+
timeout connect 10s
8+
timeout client 30m
9+
timeout server 30m
10+
option clitcpka
11+
option tcplog
12+
13+
listen cockroach-jdbc
14+
bind :5432
15+
mode tcp
16+
balance roundrobin
17+
option httpchk GET /health?ready=1
18+
server crdb-0 crdb-0:26257 check port 8080
19+
server crdb-1 crdb-1:26257 check port 8080
20+
server crdb-2 crdb-2:26257 check port 8080
21+
22+
listen cockroach-ui
23+
bind :8080
24+
mode tcp
25+
balance roundrobin
26+
option httpchk GET /health
27+
server crdb-0 crdb-0:8080 check port 8080
28+
server crdb-1 crdb-1:8080 check port 8080
29+
server crdb-2 crdb-2:8080 check port 8080
30+
31+
listen stats
32+
bind :8081
33+
mode http
34+
stats enable
35+
stats hide-version
36+
stats realm Haproxy\ Statistics
37+
stats uri /
+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
#!/bin/bash
2+
3+
docker system prune -a -f --volumes

example-haproxy-with-workload/up.sh

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
#!/bin/bash
2+
3+
docker-compose build --no-cache
4+
5+
docker-compose up -d
6+
7+
sleep 10
8+
9+
docker-compose exec workload-client /cockroach/cockroach workload init tpcc "postgresql://root@lb:5432?sslmode=disable"
10+
docker-compose exec workload-client /cockroach/cockroach workload run tpcc --duration=30m "postgresql://root@lb:5432?sslmode=disable"

0 commit comments

Comments
 (0)