Skip to content

Commit 34a1a43

Browse files
wenyihu6tbg
authored andcommitted
asim: plumb NodeCPURateCapacity everywhere
Previously, node CPU rate capacity wasn’t consistently plumbed, and some tests treated it as optional. This commit ensures it is passed through everywhere, preventing misconfigurations from being silently missed.
1 parent 7a39b97 commit 34a1a43

File tree

12 files changed

+62
-44
lines changed

12 files changed

+62
-44
lines changed

pkg/kv/kvserver/asim/config/settings.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,11 @@ const (
3232
defaultLBRebalancingObjective = 0 // QPS
3333
)
3434

35+
const DefaultNodeCPURateCapacityNanos = 8 * 1e9 // 8 vcpus
36+
const DefaultStoreDiskCapacityBytes = 1024 << 30 // 1024 GiB
37+
const DoubleDefaultNodeCPURateCapacityNanos = 16 * 1e9 // 16 vcpus
38+
const DoubleDefaultStoreDiskCapacityBytes = 2048 << 30 // 2048 GiB
39+
3540
var (
3641
// DefaultStartTime is used as the default beginning time for simulation
3742
// runs. It isn't necessarily meaningful other than for logging and having

pkg/kv/kvserver/asim/event/BUILD.bazel

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ go_library(
1111
visibility = ["//visibility:public"],
1212
deps = [
1313
"//pkg/kv/kvserver/asim/assertion",
14+
"//pkg/kv/kvserver/asim/config",
1415
"//pkg/kv/kvserver/asim/history",
1516
"//pkg/kv/kvserver/asim/state",
1617
"//pkg/kv/kvserver/liveness/livenesspb",

pkg/kv/kvserver/asim/event/mutation_event.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import (
1010
"fmt"
1111
"strings"
1212

13+
"github.com/cockroachdb/cockroach/pkg/kv/kvserver/asim/config"
1314
"github.com/cockroachdb/cockroach/pkg/kv/kvserver/asim/state"
1415
"github.com/cockroachdb/cockroach/pkg/kv/kvserver/liveness/livenesspb"
1516
"github.com/cockroachdb/cockroach/pkg/roachpb"
@@ -124,6 +125,9 @@ func (se SetSpanConfigEvent) String() string {
124125
func (ae AddNodeEvent) Func() EventFunc {
125126
return MutationFunc(func(ctx context.Context, s state.State) {
126127
node := s.AddNode()
128+
// TDOO(wenyihu6): should we always require node cpu capacity and locality
129+
// string as part of the input
130+
s.SetNodeCPURateCapacity(node.NodeID(), config.DefaultNodeCPURateCapacityNanos)
127131
if ae.LocalityString != "" {
128132
var locality roachpb.Locality
129133
if err := locality.Set(ae.LocalityString); err != nil {

pkg/kv/kvserver/asim/state/config_loader.go

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,8 @@ var AllClusterOptions = [...]string{"single_region", "single_region_multi_store"
2626
// SingleRegionConfig is a simple cluster config with a single region and 3
2727
// zones, all have the same number of nodes.
2828
var SingleRegionConfig = ClusterInfo{
29-
StoreDiskCapacityBytes: 1024 << 30, // 1024 GiB
29+
NodeCPURateCapacityNanos: config.DefaultNodeCPURateCapacityNanos, // 8vpucs
30+
StoreDiskCapacityBytes: config.DefaultStoreDiskCapacityBytes, // 1024 GiB
3031
Regions: []Region{
3132
{
3233
Name: "US",
@@ -42,7 +43,8 @@ var SingleRegionConfig = ClusterInfo{
4243
// SingleRegionMultiStoreConfig is a simple cluster config with a single region
4344
// and 3 zones, all zones have 1 node and 5 stores per node.
4445
var SingleRegionMultiStoreConfig = ClusterInfo{
45-
StoreDiskCapacityBytes: 1024 << 30, // 1024 GiB
46+
NodeCPURateCapacityNanos: config.DefaultNodeCPURateCapacityNanos, // 8 vcpus
47+
StoreDiskCapacityBytes: config.DefaultStoreDiskCapacityBytes, // 1024 GiB
4648
Regions: []Region{
4749
{
4850
Name: "US",
@@ -57,7 +59,8 @@ var SingleRegionMultiStoreConfig = ClusterInfo{
5759

5860
// MultiRegionConfig is a perfectly balanced cluster config with 3 regions.
5961
var MultiRegionConfig = ClusterInfo{
60-
StoreDiskCapacityBytes: 2048 << 30, // 2048 GiB
62+
NodeCPURateCapacityNanos: config.DoubleDefaultNodeCPURateCapacityNanos, // 16 vcpus
63+
StoreDiskCapacityBytes: config.DoubleDefaultStoreDiskCapacityBytes, // 2048 GiB
6164
Regions: []Region{
6265
{
6366
Name: "US_East",
@@ -88,7 +91,8 @@ var MultiRegionConfig = ClusterInfo{
8891

8992
// ComplexConfig is an imbalanced multi-region cluster config.
9093
var ComplexConfig = ClusterInfo{
91-
StoreDiskCapacityBytes: 2048 << 30, // 2048 GiB
94+
NodeCPURateCapacityNanos: config.DoubleDefaultNodeCPURateCapacityNanos, // 16 vcpus
95+
StoreDiskCapacityBytes: config.DoubleDefaultStoreDiskCapacityBytes, // 2048 GiB
9296
Regions: []Region{
9397
{
9498
Name: "US_East",

pkg/kv/kvserver/asim/state/new_state_test_helper.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ func NewStateWithDistribution(
2727
// Currently multi-store is not tested for correctness. Default to a single
2828
// store per node.
2929
clusterInfo := ClusterInfoWithStoreCount(numNodes, 1 /* storesPerNode */)
30+
clusterInfo.NodeCPURateCapacityNanos = config.DefaultNodeCPURateCapacityNanos
3031
s := LoadClusterInfo(clusterInfo, settings)
3132

3233
stores := make([]StoreID, numNodes)

pkg/kv/kvserver/asim/tests/datadriven_simulation_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -313,8 +313,8 @@ func TestDataDriven(t *testing.T) {
313313
case "gen_cluster":
314314
var nodes = 3
315315
var storesPerNode = 1
316-
var storeByteCapacity int64 = 256 << 30 /* 256 GiB */
317-
var nodeCPURateCapacity int64 = 8 * 1e9 // 8 vcpus
316+
var storeByteCapacity int64 = 256 << 30 /* 256 GiB */
317+
var nodeCPURateCapacity int64 = config.DefaultNodeCPURateCapacityNanos // 8 vcpus
318318
var region []string
319319
var nodesPerRegion []int
320320
scanIfExists(t, d, "nodes", &nodes)

pkg/kv/kvserver/asim/tests/default_settings.go

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ type staticOptionSettings struct {
4242
nodes int
4343
storesPerNode int
4444
storeByteCapacity int64
45+
nodeCPURateCapacity int64
4546
rwRatio float64
4647
rate float64
4748
minBlock int
@@ -59,6 +60,7 @@ type staticOptionSettings struct {
5960

6061
func getDefaultStaticOptionSettings() staticOptionSettings {
6162
return staticOptionSettings{
63+
nodeCPURateCapacity: config.DefaultNodeCPURateCapacityNanos,
6264
nodes: defaultNodes,
6365
storesPerNode: defaultStoresPerNode,
6466
storeByteCapacity: defaultStoreByteCapacity,
@@ -80,9 +82,10 @@ func getDefaultStaticOptionSettings() staticOptionSettings {
8082

8183
func (f randTestingFramework) defaultBasicClusterGen() gen.BasicCluster {
8284
return gen.BasicCluster{
83-
Nodes: f.defaultStaticSettings.nodes,
84-
StoresPerNode: f.defaultStaticSettings.storesPerNode,
85-
StoreByteCapacity: f.defaultStaticSettings.storeByteCapacity,
85+
Nodes: f.defaultStaticSettings.nodes,
86+
StoresPerNode: f.defaultStaticSettings.storesPerNode,
87+
StoreByteCapacity: f.defaultStaticSettings.storeByteCapacity,
88+
NodeCPURateCapacity: f.defaultStaticSettings.nodeCPURateCapacity,
8689
}
8790
}
8891

pkg/kv/kvserver/asim/tests/testdata/rand/default_settings.txt

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ eval verbose=(config_gen)
7373
----------------------------------
7474
sample1: start running
7575
configurations generated using seed 3440579354231278675
76-
[nodes: 3, stores_per_node:1, store_disk_capacity: 256GiB, node_capacity: 0cpu-sec/sec]
76+
[nodes: 3, stores_per_node:1, store_disk_capacity: 256GiB, node_capacity: 8cpu-sec/sec]
7777
[0,200000): 10(rf=3), 0MiB
7878
[0,200000): write-only [1B/op, 0ops/s]
7979
scheduled_event:
@@ -82,7 +82,7 @@ sample1: pass
8282
----------------------------------
8383
sample2: start running
8484
configurations generated using seed 608747136543856411
85-
[nodes: 3, stores_per_node:1, store_disk_capacity: 256GiB, node_capacity: 0cpu-sec/sec]
85+
[nodes: 3, stores_per_node:1, store_disk_capacity: 256GiB, node_capacity: 8cpu-sec/sec]
8686
[0,200000): 10(rf=3), 0MiB
8787
[0,200000): write-only [1B/op, 0ops/s]
8888
scheduled_event:
@@ -91,7 +91,7 @@ sample2: pass
9191
----------------------------------
9292
sample3: start running
9393
configurations generated using seed 5571782338101878760
94-
[nodes: 3, stores_per_node:1, store_disk_capacity: 256GiB, node_capacity: 0cpu-sec/sec]
94+
[nodes: 3, stores_per_node:1, store_disk_capacity: 256GiB, node_capacity: 8cpu-sec/sec]
9595
[0,200000): 10(rf=3), 0MiB
9696
[0,200000): write-only [1B/op, 0ops/s]
9797
scheduled_event:
@@ -174,7 +174,7 @@ generating settings configurations using static option
174174
----------------------------------
175175
sample1: start running
176176
configurations generated using seed 3440579354231278675
177-
[nodes: 3, stores_per_node:1, store_disk_capacity: 256GiB, node_capacity: 0cpu-sec/sec]
177+
[nodes: 3, stores_per_node:1, store_disk_capacity: 256GiB, node_capacity: 8cpu-sec/sec]
178178
[0,200000): 10(rf=3), 0MiB
179179
[0,200000): write-only [1B/op, 0ops/s]
180180
scheduled_event:
@@ -185,7 +185,7 @@ sample1: pass
185185
----------------------------------
186186
sample2: start running
187187
configurations generated using seed 608747136543856411
188-
[nodes: 3, stores_per_node:1, store_disk_capacity: 256GiB, node_capacity: 0cpu-sec/sec]
188+
[nodes: 3, stores_per_node:1, store_disk_capacity: 256GiB, node_capacity: 8cpu-sec/sec]
189189
[0,200000): 10(rf=3), 0MiB
190190
[0,200000): write-only [1B/op, 0ops/s]
191191
scheduled_event:
@@ -196,7 +196,7 @@ sample2: pass
196196
----------------------------------
197197
sample3: start running
198198
configurations generated using seed 5571782338101878760
199-
[nodes: 3, stores_per_node:1, store_disk_capacity: 256GiB, node_capacity: 0cpu-sec/sec]
199+
[nodes: 3, stores_per_node:1, store_disk_capacity: 256GiB, node_capacity: 8cpu-sec/sec]
200200
[0,200000): 10(rf=3), 0MiB
201201
[0,200000): write-only [1B/op, 0ops/s]
202202
scheduled_event:
@@ -227,7 +227,7 @@ generating settings configurations using static option
227227
----------------------------------
228228
sample1: start running
229229
configurations generated using seed 3440579354231278675
230-
[nodes: 3, stores_per_node:1, store_disk_capacity: 256GiB, node_capacity: 0cpu-sec/sec]
230+
[nodes: 3, stores_per_node:1, store_disk_capacity: 256GiB, node_capacity: 8cpu-sec/sec]
231231
[0,200000): 10(rf=3), 0MiB
232232
[0,200000): write-only [1B/op, 0ops/s]
233233
scheduled_event:
@@ -243,7 +243,7 @@ sample1: pass
243243
----------------------------------
244244
sample2: start running
245245
configurations generated using seed 608747136543856411
246-
[nodes: 3, stores_per_node:1, store_disk_capacity: 256GiB, node_capacity: 0cpu-sec/sec]
246+
[nodes: 3, stores_per_node:1, store_disk_capacity: 256GiB, node_capacity: 8cpu-sec/sec]
247247
[0,200000): 10(rf=3), 0MiB
248248
[0,200000): write-only [1B/op, 0ops/s]
249249
scheduled_event:
@@ -259,7 +259,7 @@ sample2: pass
259259
----------------------------------
260260
sample3: start running
261261
configurations generated using seed 5571782338101878760
262-
[nodes: 3, stores_per_node:1, store_disk_capacity: 256GiB, node_capacity: 0cpu-sec/sec]
262+
[nodes: 3, stores_per_node:1, store_disk_capacity: 256GiB, node_capacity: 8cpu-sec/sec]
263263
[0,200000): 10(rf=3), 0MiB
264264
[0,200000): write-only [1B/op, 0ops/s]
265265
scheduled_event:

pkg/kv/kvserver/asim/tests/testdata/rand/rand_cluster.txt

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ sample1: start running
1313
configurations generated using seed 608747136543856411
1414
cluster:
1515
region:US [zone=US_1(nodes=1,stores=5), zone=US_2(nodes=1,stores=5), zone=US_3(nodes=1,stores=5)]
16-
store_disk_capacity=1099511627776 bytes, node_cpu_rate_capacity=0 cpu-ns/sec
16+
store_disk_capacity=1099511627776 bytes, node_cpu_rate_capacity=8000000000 cpu-ns/sec
1717
[0,200000): 10(rf=3), 0MiB
1818
[0,200000): write-only [1B/op, 0ops/s]
1919
scheduled_event:
@@ -24,7 +24,7 @@ sample2: start running
2424
configurations generated using seed 1926012586526624009
2525
cluster:
2626
region:US [zone=US_1(nodes=5,stores=1), zone=US_2(nodes=5,stores=1), zone=US_3(nodes=5,stores=1)]
27-
store_disk_capacity=1099511627776 bytes, node_cpu_rate_capacity=0 cpu-ns/sec
27+
store_disk_capacity=1099511627776 bytes, node_cpu_rate_capacity=8000000000 cpu-ns/sec
2828
[0,200000): 10(rf=3), 0MiB
2929
[0,200000): write-only [1B/op, 0ops/s]
3030
scheduled_event:
@@ -35,7 +35,7 @@ sample3: start running
3535
configurations generated using seed 3534334367214237261
3636
cluster:
3737
region:US [zone=US_1(nodes=1,stores=5), zone=US_2(nodes=1,stores=5), zone=US_3(nodes=1,stores=5)]
38-
store_disk_capacity=1099511627776 bytes, node_cpu_rate_capacity=0 cpu-ns/sec
38+
store_disk_capacity=1099511627776 bytes, node_cpu_rate_capacity=8000000000 cpu-ns/sec
3939
[0,200000): 10(rf=3), 0MiB
4040
[0,200000): write-only [1B/op, 0ops/s]
4141
scheduled_event:
@@ -69,7 +69,7 @@ configurations generated using seed 608747136543856411
6969
region:US_East [zone=US_East_1(nodes=1,stores=1), zone=US_East_2(nodes=2,stores=1), zone=US_East_3(nodes=3,stores=1), zone=US_East_4(nodes=10,stores=1)]
7070
region:US_West [zone=US_West_1(nodes=2,stores=1)]
7171
region:EU [zone=EU_1(nodes=3,stores=1), zone=EU_2(nodes=3,stores=1), zone=EU_3(nodes=4,stores=1)]
72-
store_disk_capacity=2199023255552 bytes, node_cpu_rate_capacity=0 cpu-ns/sec
72+
store_disk_capacity=2199023255552 bytes, node_cpu_rate_capacity=16000000000 cpu-ns/sec
7373
[0,200000): 10(rf=3), 0MiB
7474
[0,200000): write-only [1B/op, 0ops/s]
7575
scheduled_event:
@@ -105,7 +105,7 @@ configurations generated using seed 1926012586526624009
105105
region:US_East [zone=US_East_1(nodes=4,stores=1), zone=US_East_2(nodes=4,stores=1), zone=US_East_3(nodes=4,stores=1)]
106106
region:US_West [zone=US_West_1(nodes=4,stores=1), zone=US_West_2(nodes=4,stores=1), zone=US_West_3(nodes=4,stores=1)]
107107
region:EU [zone=EU_1(nodes=4,stores=1), zone=EU_2(nodes=4,stores=1), zone=EU_3(nodes=4,stores=1)]
108-
store_disk_capacity=2199023255552 bytes, node_cpu_rate_capacity=0 cpu-ns/sec
108+
store_disk_capacity=2199023255552 bytes, node_cpu_rate_capacity=16000000000 cpu-ns/sec
109109
[0,200000): 10(rf=3), 0MiB
110110
[0,200000): write-only [1B/op, 0ops/s]
111111
scheduled_event:
@@ -143,7 +143,7 @@ configurations generated using seed 3534334367214237261
143143
region:US_East [zone=US_East_1(nodes=1,stores=1), zone=US_East_2(nodes=2,stores=1), zone=US_East_3(nodes=3,stores=1), zone=US_East_4(nodes=10,stores=1)]
144144
region:US_West [zone=US_West_1(nodes=2,stores=1)]
145145
region:EU [zone=EU_1(nodes=3,stores=1), zone=EU_2(nodes=3,stores=1), zone=EU_3(nodes=4,stores=1)]
146-
store_disk_capacity=2199023255552 bytes, node_cpu_rate_capacity=0 cpu-ns/sec
146+
store_disk_capacity=2199023255552 bytes, node_cpu_rate_capacity=16000000000 cpu-ns/sec
147147
[0,200000): 10(rf=3), 0MiB
148148
[0,200000): write-only [1B/op, 0ops/s]
149149
scheduled_event:
@@ -187,7 +187,7 @@ sample1: start running
187187
configurations generated using seed 608747136543856411
188188
cluster:
189189
region:US [zone=US_1(nodes=1,stores=5), zone=US_2(nodes=1,stores=5), zone=US_3(nodes=1,stores=5)]
190-
store_disk_capacity=1099511627776 bytes, node_cpu_rate_capacity=0 cpu-ns/sec
190+
store_disk_capacity=1099511627776 bytes, node_cpu_rate_capacity=8000000000 cpu-ns/sec
191191
[0,200000): 10(rf=3), 0MiB
192192
[0,200000): write-only [1B/op, 0ops/s]
193193
scheduled_event:
@@ -198,7 +198,7 @@ sample2: start running
198198
configurations generated using seed 1926012586526624009
199199
cluster:
200200
region:US [zone=US_1(nodes=5,stores=1), zone=US_2(nodes=5,stores=1), zone=US_3(nodes=5,stores=1)]
201-
store_disk_capacity=1099511627776 bytes, node_cpu_rate_capacity=0 cpu-ns/sec
201+
store_disk_capacity=1099511627776 bytes, node_cpu_rate_capacity=8000000000 cpu-ns/sec
202202
[0,200000): 10(rf=3), 0MiB
203203
[0,200000): write-only [1B/op, 0ops/s]
204204
scheduled_event:
@@ -211,7 +211,7 @@ configurations generated using seed 3534334367214237261
211211
region:US_East [zone=US_East_1(nodes=1,stores=1), zone=US_East_2(nodes=2,stores=1), zone=US_East_3(nodes=3,stores=1), zone=US_East_4(nodes=10,stores=1)]
212212
region:US_West [zone=US_West_1(nodes=2,stores=1)]
213213
region:EU [zone=EU_1(nodes=3,stores=1), zone=EU_2(nodes=3,stores=1), zone=EU_3(nodes=4,stores=1)]
214-
store_disk_capacity=2199023255552 bytes, node_cpu_rate_capacity=0 cpu-ns/sec
214+
store_disk_capacity=2199023255552 bytes, node_cpu_rate_capacity=16000000000 cpu-ns/sec
215215
[0,200000): 10(rf=3), 0MiB
216216
[0,200000): write-only [1B/op, 0ops/s]
217217
scheduled_event:

pkg/kv/kvserver/asim/tests/testdata/rand/rand_event.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ configurations generated using seed 7894140303635748408
2828
region:US_East [zone=US_East_1(nodes=1,stores=1), zone=US_East_2(nodes=2,stores=1), zone=US_East_3(nodes=3,stores=1), zone=US_East_4(nodes=10,stores=1)]
2929
region:US_West [zone=US_West_1(nodes=2,stores=1)]
3030
region:EU [zone=EU_1(nodes=3,stores=1), zone=EU_2(nodes=3,stores=1), zone=EU_3(nodes=4,stores=1)]
31-
store_disk_capacity=2199023255552 bytes, node_cpu_rate_capacity=0 cpu-ns/sec
31+
store_disk_capacity=2199023255552 bytes, node_cpu_rate_capacity=16000000000 cpu-ns/sec
3232
[0,200000): 1(rf=3), 0MiB
3333
[0,200000): write-only [1B/op, 0ops/s]
3434
scheduled_event:

0 commit comments

Comments
 (0)