Skip to content

Commit aceb12b

Browse files
feat: Asymmetric Workloads
1 parent beec3de commit aceb12b

File tree

12 files changed

+576
-11
lines changed

12 files changed

+576
-11
lines changed

.gitignore

+3
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
# Sensitive
2+
.env
3+
14
# Binaries for programs and plugins
25
*.exe
36
*.exe~

README.md

+5-1
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,13 @@ If you've seen a video and its code doesn't feature here, let us know and we'll
1313
* Ranges
1414
* [Deep Dive](architecture/ranges/deep_dive/README.md)
1515

16+
* Cloud
17+
* Standard
18+
* [Asymmetric Workloads](cloud/standard/asymmetric-workloads/README.md)
19+
1620
* Migration
1721
* To CockroachDB
18-
* [Live Migration Service](migration/to_cockroachdb/live_migration_service/steps.md)
22+
* [Live Migration Service](migration/to_cockroachdb/live_migration_service/README.md)
1923

2024
* Operational Efficiency
2125
* Online Schema Changes
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,170 @@
1+
### Introduction
2+
3+
* If you're planning on self-hosting a multi-region CockroachDB cluster, you'll need to know how many nodes you'll need in each region.
4+
* CockroachDB Cloud's Standard tier gives you a provisioned number of vCPUs to use across your cluster.
5+
* So if one region is busier than the rest, it will receive more vCPU than the others.
6+
* And as usage patterns across the regions change throughout the data, so too will the vCPUs.
7+
8+
### Cluster planning
9+
10+
Using arch.drawio, show how a cluster should be designed, based on the maximum estimated concurrent usage across all regions.
11+
12+
### Setup
13+
14+
Prerequisites
15+
16+
```sh
17+
export COCKROACH_API_KEY="YOUR_API_KEY"
18+
export GCP_PROJECT_NAME="YOUR GPC PROJECT"
19+
```
20+
21+
Create Standard cluster
22+
23+
```sh
24+
response=$(curl -s https://cockroachlabs.cloud/api/v1/clusters \
25+
-H "Authorization: Bearer ${COCKROACH_API_KEY}" \
26+
-H "Content-Type: application/json" \
27+
-d '{
28+
"name": "crdb-asymmetric-workloads",
29+
"provider": "AWS",
30+
"plan": "standard",
31+
"spec": {
32+
"serverless": {
33+
"regions": [
34+
"us-east-1",
35+
"eu-central-1",
36+
"ap-southeast-1"
37+
],
38+
"primary_region": "eu-central-1",
39+
"usage_limits": {
40+
"provisioned_virtual_cpus": 16
41+
}
42+
}
43+
}
44+
}')
45+
```
46+
47+
Create Basic cluster
48+
49+
```sh
50+
response=$(curl -s https://cockroachlabs.cloud/api/v1/clusters \
51+
-H "Authorization: Bearer ${COCKROACH_API_KEY}" \
52+
-H "Content-Type: application/json" \
53+
-d '{
54+
"name": "crdb-asymmetric-workloads",
55+
"provider": "AWS",
56+
"plan": "basic",
57+
"spec": {
58+
"serverless": {
59+
"regions": [
60+
"us-east-1",
61+
"eu-central-1",
62+
"ap-southeast-1"
63+
],
64+
"primary_region": "eu-central-1"
65+
}
66+
}
67+
}')
68+
69+
export CLUSTER_ID=$(echo "$response" | jq -r .id)
70+
71+
export GLOBAL_HOST=$(echo "$response" | jq -r '.sql_dns')
72+
export AP_HOST=$(echo "$response" | jq -r '.regions[0].sql_dns')
73+
export EU_HOST=$(echo "$response" | jq -r '.regions[1].sql_dns')
74+
export US_HOST=$(echo "$response" | jq -r '.regions[2].sql_dns')
75+
76+
pass=$(pa55 --out hex --len 18 --print)
77+
78+
export GLOBAL_URL="postgres://rob:${pass}@${GLOBAL_HOST}:26257/defaultdb?sslmode=verify-full"
79+
export AP_URL="postgres://rob:${pass}@${AP_HOST}:26257/defaultdb?sslmode=verify-full"
80+
export EU_URL="postgres://rob:${pass}@${EU_HOST}:26257/defaultdb?sslmode=verify-full"
81+
export US_URL="postgres://rob:${pass}@${US_HOST}:26257/defaultdb?sslmode=verify-full"
82+
83+
# Check cluster status.
84+
curl -s https://cockroachlabs.cloud/api/v1/clusters/${CLUSTER_ID} \
85+
-H "Authorization: Bearer ${COCKROACH_API_KEY}" | jq .state -r
86+
```
87+
88+
Create user
89+
90+
```sh
91+
curl -s https://cockroachlabs.cloud/api/v1/clusters/${CLUSTER_ID}/sql-users \
92+
-H "Authorization: Bearer ${COCKROACH_API_KEY}" \
93+
-H "Content-Type: application/json" \
94+
-d "{ \"name\": \"rob\", \"password\": \"${pass}\" }"
95+
96+
```
97+
98+
Check connection strings
99+
100+
```sh
101+
cockroach sql --url ${AP_URL} -e "SELECT gateway_region()"
102+
cockroach sql --url ${EU_URL} -e "SELECT gateway_region()"
103+
cockroach sql --url ${US_URL} -e "SELECT gateway_region()"
104+
cockroach sql --url ${GLOBAL_URL} -e "SELECT gateway_region()"
105+
```
106+
107+
Configure multi-region
108+
109+
```sh
110+
cockroach sql --url ${GLOBAL_URL} -f cloud/standard/asymmetric-workloads/create.sql
111+
```
112+
113+
### Demo
114+
115+
Deploy workload (fly.io)
116+
117+
```sh
118+
fly app create crdb-asymmetric-workload --org crl-devrel
119+
120+
fly secrets set --app crdb-asymmetric-workload \
121+
CONNECTION_STRING=${GLOBAL_URL} \
122+
CONNECTION_STRING_US=${US_URL} \
123+
CONNECTION_STRING_EU=${EU_URL} \
124+
CONNECTION_STRING_AP=${AP_URL}
125+
126+
cp go.* cloud/standard/asymmetric-workloads/app
127+
docker build --platform linux/amd64 -t registry.fly.io/crdb-asymmetric-workload:latest cloud/standard/asymmetric-workloads/app
128+
rm cloud/standard/asymmetric-workloads/app/go.*
129+
130+
docker push registry.fly.io/crdb-asymmetric-workload:latest
131+
132+
(cd cloud/standard/asymmetric-workloads/app && fly deploy --ha=false -i registry.fly.io/crdb-asymmetric-workload:latest --remote-only)
133+
134+
(cd cloud/standard/asymmetric-workloads/app && fly scale count 3 --region iad,fra,sin --max-per-region 1 -y)
135+
```
136+
137+
```mermaid
138+
xychart-beta
139+
title "Regional Requests/s Per day"
140+
x-axis ["00","01","02","03","04","05","06","07","08","09","10","11","12","13","14","15","16","17","18","19","20","21","22","23"]
141+
y-axis "Requests/s" 0 --> 2000
142+
line "AP" [500,1000,1000,1000,500,500,1000,1000,1000,1000,500,250,100,100,100,100,100,100,100,100,100,100,100,250]
143+
line "EU" [100,100,100,100,100,100,100,250,500,1000,1000,1000,500,500,1000,1000,1000,1000,500,250,100,100,100,100]
144+
line "US" [500,250,100,100,100,100,100,100,100,100,100,100,100,250,500,1000,1000,1000,500,500,1000,1000,1000,1000]
145+
```
146+
147+
```mermaid
148+
xychart-beta
149+
title "Total Requests/s Per day"
150+
x-axis ["00","01","02","03","04","05","06","07","08","09","10","11","12","13","14","15","16","17","18","19","20","21","22","23"]
151+
y-axis "Requests/s" 0 --> 2500
152+
line "Total" [1100,1350,1200,1200,700,700,1200,1350,1600,2100,1600,1350,700,850,1600,2100,2100,2100,1100,850,1200,1200,1200,1350]
153+
```
154+
155+
### Teardown
156+
157+
App (fly.io)
158+
159+
```sh
160+
fly apps destroy crdb-asymmetric-workload -y
161+
```
162+
163+
CockroachDB
164+
165+
```sh
166+
curl -X DELETE -s https://cockroachlabs.cloud/api/v1/clusters/${CLUSTER_ID} \
167+
-H "Authorization: Bearer ${COCKROACH_API_KEY}" \
168+
-H "Content-Type: application/json" \
169+
| jq .state -r
170+
```
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# Compile
2+
FROM golang:1.23.4-alpine AS build
3+
WORKDIR /src
4+
COPY ./*.go /src
5+
COPY go.* /src
6+
7+
RUN CGO_ENABLED=0 GOOS=linux go build -o /app workload.go
8+
9+
# Build
10+
FROM alpine
11+
COPY --from=build app .
12+
ADD https://github.com/golang/go/raw/master/lib/time/zoneinfo.zip /zoneinfo.zip
13+
ENV ZONEINFO /zoneinfo.zip
14+
CMD ./app
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
app = 'crdb-asymmetric-workload'
2+
primary_region = 'fra'
3+
4+
[build]
5+
6+
[http_service]
7+
internal_port = 3000
8+
force_https = true
9+
auto_stop_machines = false
10+
auto_start_machines = true
11+
min_machines_running = 0
12+
processes = ['app']
13+
14+
[[vm]]
15+
size = 'performance-8x'

0 commit comments

Comments
 (0)