Skip to content

Commit 037996b

Browse files
committed
asim: support node_cpu_rate_capacity with gen_cluster
Previously, we added roachpb.NodeCapacity for MMA to compute resource utilization across stores. This commit integrates it into the asim setup, enabling gen_cluster to use the node_cpu_rate_capacity option. Note that no functions currently access node capacity; future MMA integration commits will utilize it. Epic: none Release note: none
1 parent 09baa0d commit 037996b

File tree

7 files changed

+70
-28
lines changed

7 files changed

+70
-28
lines changed

pkg/kv/kvserver/asim/gen/generator.go

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -193,17 +193,19 @@ func (lc LoadedCluster) Regions() []state.Region {
193193

194194
// BasicCluster implements the ClusterGen interace.
195195
type BasicCluster struct {
196-
Nodes int
197-
StoresPerNode int
198-
StoreByteCapacity int64
199-
Region []string
200-
NodesPerRegion []int
196+
Nodes int
197+
StoresPerNode int
198+
StoreByteCapacity int64
199+
Region []string
200+
NodesPerRegion []int
201+
NodeCPURateCapacity int64
201202
}
202203

203204
func (bc BasicCluster) String() string {
204205
var b strings.Builder
205-
_, _ = fmt.Fprintf(&b, "basic cluster with nodes=%d, stores_per_node=%d, store_byte_capacity=%d",
206-
bc.Nodes, bc.StoresPerNode, bc.StoreByteCapacity)
206+
_, _ = fmt.Fprintf(&b,
207+
"basic cluster with nodes=%d, stores_per_node=%d, store_byte_capacity=%d, node_cpu_rate_capacity=%d",
208+
bc.Nodes, bc.StoresPerNode, bc.StoreByteCapacity, bc.NodeCPURateCapacity)
207209
if len(bc.Region) != 0 {
208210
_, _ = fmt.Fprintf(&b, ", region=%v, nodes_per_region=%v", bc.Region, bc.NodesPerRegion)
209211
}
@@ -217,6 +219,7 @@ func (bc BasicCluster) String() string {
217219
func (bc BasicCluster) Generate(seed int64, settings *config.SimulationSettings) state.State {
218220
info := bc.info()
219221
info.StoreDiskCapacityBytes = bc.StoreByteCapacity
222+
info.NodeCPURateCapacityNanos = bc.NodeCPURateCapacity
220223
return state.LoadClusterInfo(info, settings)
221224
}
222225

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -276,8 +276,9 @@ type Region struct {
276276
// ClusterInfo contains cluster information needed for allocation decisions.
277277
// TODO(lidor): add cross region network latencies.
278278
type ClusterInfo struct {
279-
Regions []Region
280-
StoreDiskCapacityBytes int64
279+
Regions []Region
280+
StoreDiskCapacityBytes int64
281+
NodeCPURateCapacityNanos int64
281282
}
282283

283284
func (c ClusterInfo) String() (s string) {
@@ -373,6 +374,7 @@ func LoadClusterInfo(c ClusterInfo, settings *config.SimulationSettings) State {
373374
for i := 0; i < z.NodeCount; i++ {
374375
node := s.AddNode()
375376
s.SetNodeLocality(node.NodeID(), locality)
377+
s.SetNodeCPURateCapacity(node.NodeID(), c.NodeCPURateCapacityNanos)
376378
storesRequired := z.StoresPerNode
377379
if storesRequired < 1 {
378380
panic(fmt.Sprintf("storesPerNode cannot be less than one but found %v", storesRequired))

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

Lines changed: 31 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -437,6 +437,34 @@ func (s *state) SetNodeLocality(nodeID NodeID, locality roachpb.Locality) {
437437
}
438438
}
439439

440+
func (s *state) SetNodeCPURateCapacity(nodeID NodeID, cpuRateCapacity int64) {
441+
node, ok := s.nodes[nodeID]
442+
if !ok {
443+
panic(fmt.Sprintf("programming error: node with ID %d doesn't exist", nodeID))
444+
}
445+
node.cpuRateCapacity = cpuRateCapacity
446+
}
447+
448+
// NodeCapacity returns the capacity of the Node with ID NodeID. Note that it is
449+
// currently unused.
450+
// TODO(wenyihu6): MMA integration should later use it.
451+
func (s *state) NodeCapacity(nodeID NodeID) roachpb.NodeCapacity {
452+
node := s.nodes[nodeID]
453+
stores := node.Stores()
454+
cpuRate := 0
455+
for _, storeID := range stores {
456+
capacity := s.capacity(storeID)
457+
cpuRate += int(capacity.CPUPerSecond)
458+
}
459+
460+
return roachpb.NodeCapacity{
461+
StoresCPURate: int64(cpuRate),
462+
NumStores: int32(len(stores)),
463+
NodeCPURateUsage: int64(cpuRate),
464+
NodeCPURateCapacity: node.cpuRateCapacity,
465+
}
466+
}
467+
440468
// Topology represents the locality hierarchy information for a cluster.
441469
type Topology struct {
442470
children map[string]*Topology
@@ -1351,8 +1379,9 @@ func (s *state) SetSimulationSettings(Key string, Value interface{}) {
13511379

13521380
// node is an implementation of the Node interface.
13531381
type node struct {
1354-
nodeID NodeID
1355-
desc roachpb.NodeDescriptor
1382+
nodeID NodeID
1383+
desc roachpb.NodeDescriptor
1384+
cpuRateCapacity int64
13561385

13571386
stores []StoreID
13581387
}

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -199,6 +199,11 @@ type State interface {
199199
RegisterConfigChangeListener(ConfigChangeListener)
200200
// SetSimulationSettings sets the simulation settings for the state.
201201
SetSimulationSettings(Key string, Value interface{})
202+
// NodeCapacity returns the capacity of the node with ID NodeID.
203+
NodeCapacity(NodeID) roachpb.NodeCapacity
204+
// SetNodeCPURateCapacity sets the CPU rate capacity for the node with ID
205+
// NodeID to be equal to the value given.
206+
SetNodeCPURateCapacity(NodeID, int64)
202207
}
203208

204209
// Node is a container for stores and is part of a cluster.

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

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -263,19 +263,22 @@ func TestDataDriven(t *testing.T) {
263263
var nodes = 3
264264
var storesPerNode = 1
265265
var storeByteCapacity int64 = 256 << 30 /* 256 GiB */
266+
var nodeCPURateCapacity int64
266267
var region []string
267268
var nodesPerRegion []int
268269
scanIfExists(t, d, "nodes", &nodes)
269270
scanIfExists(t, d, "stores_per_node", &storesPerNode)
270271
scanIfExists(t, d, "store_byte_capacity", &storeByteCapacity)
271272
scanIfExists(t, d, "region", &region)
272273
scanIfExists(t, d, "nodes_per_region", &nodesPerRegion)
274+
scanIfExists(t, d, "node_cpu_rate_capacity", &nodeCPURateCapacity)
273275
clusterGen = gen.BasicCluster{
274-
Nodes: nodes,
275-
StoresPerNode: storesPerNode,
276-
StoreByteCapacity: storeByteCapacity,
277-
Region: region,
278-
NodesPerRegion: nodesPerRegion,
276+
Nodes: nodes,
277+
StoresPerNode: storesPerNode,
278+
StoreByteCapacity: storeByteCapacity,
279+
Region: region,
280+
NodesPerRegion: nodesPerRegion,
281+
NodeCPURateCapacity: nodeCPURateCapacity,
279282
}
280283
return ""
281284
case "load_cluster":

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

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -73,23 +73,23 @@ eval verbose=(config_gen)
7373
----------------------------------
7474
sample1: start running
7575
configurations generated using seed 3440579354231278675
76-
basic cluster with nodes=3, stores_per_node=1, store_byte_capacity=274877906944
76+
basic cluster with nodes=3, stores_per_node=1, store_byte_capacity=274877906944, node_cpu_rate_capacity=0
7777
basic ranges with placement_type=even, ranges=10, min_key=0, max_key=200000, replication_factor=3, bytes=0
7878
basic load with rw_ratio=0.00, rate=0.00, skewed_access=false, min_block_size=1, max_block_size=1, min_key=0, max_key=200000, request_cpu_per_access=0, raft_cpu_per_write=0
7979
number of mutation events=0, number of assertion events=0
8080
sample1: pass
8181
----------------------------------
8282
sample2: start running
8383
configurations generated using seed 608747136543856411
84-
basic cluster with nodes=3, stores_per_node=1, store_byte_capacity=274877906944
84+
basic cluster with nodes=3, stores_per_node=1, store_byte_capacity=274877906944, node_cpu_rate_capacity=0
8585
basic ranges with placement_type=even, ranges=10, min_key=0, max_key=200000, replication_factor=3, bytes=0
8686
basic load with rw_ratio=0.00, rate=0.00, skewed_access=false, min_block_size=1, max_block_size=1, min_key=0, max_key=200000, request_cpu_per_access=0, raft_cpu_per_write=0
8787
number of mutation events=0, number of assertion events=0
8888
sample2: pass
8989
----------------------------------
9090
sample3: start running
9191
configurations generated using seed 5571782338101878760
92-
basic cluster with nodes=3, stores_per_node=1, store_byte_capacity=274877906944
92+
basic cluster with nodes=3, stores_per_node=1, store_byte_capacity=274877906944, node_cpu_rate_capacity=0
9393
basic ranges with placement_type=even, ranges=10, min_key=0, max_key=200000, replication_factor=3, bytes=0
9494
basic load with rw_ratio=0.00, rate=0.00, skewed_access=false, min_block_size=1, max_block_size=1, min_key=0, max_key=200000, request_cpu_per_access=0, raft_cpu_per_write=0
9595
number of mutation events=0, number of assertion events=0
@@ -171,7 +171,7 @@ generating settings configurations using static option
171171
----------------------------------
172172
sample1: start running
173173
configurations generated using seed 3440579354231278675
174-
basic cluster with nodes=3, stores_per_node=1, store_byte_capacity=274877906944
174+
basic cluster with nodes=3, stores_per_node=1, store_byte_capacity=274877906944, node_cpu_rate_capacity=0
175175
basic ranges with placement_type=even, ranges=10, min_key=0, max_key=200000, replication_factor=3, bytes=0
176176
basic load with rw_ratio=0.00, rate=0.00, skewed_access=false, min_block_size=1, max_block_size=1, min_key=0, max_key=200000, request_cpu_per_access=0, raft_cpu_per_write=0
177177
number of mutation events=0, number of assertion events=0
@@ -181,7 +181,7 @@ sample1: pass
181181
----------------------------------
182182
sample2: start running
183183
configurations generated using seed 608747136543856411
184-
basic cluster with nodes=3, stores_per_node=1, store_byte_capacity=274877906944
184+
basic cluster with nodes=3, stores_per_node=1, store_byte_capacity=274877906944, node_cpu_rate_capacity=0
185185
basic ranges with placement_type=even, ranges=10, min_key=0, max_key=200000, replication_factor=3, bytes=0
186186
basic load with rw_ratio=0.00, rate=0.00, skewed_access=false, min_block_size=1, max_block_size=1, min_key=0, max_key=200000, request_cpu_per_access=0, raft_cpu_per_write=0
187187
number of mutation events=0, number of assertion events=0
@@ -191,7 +191,7 @@ sample2: pass
191191
----------------------------------
192192
sample3: start running
193193
configurations generated using seed 5571782338101878760
194-
basic cluster with nodes=3, stores_per_node=1, store_byte_capacity=274877906944
194+
basic cluster with nodes=3, stores_per_node=1, store_byte_capacity=274877906944, node_cpu_rate_capacity=0
195195
basic ranges with placement_type=even, ranges=10, min_key=0, max_key=200000, replication_factor=3, bytes=0
196196
basic load with rw_ratio=0.00, rate=0.00, skewed_access=false, min_block_size=1, max_block_size=1, min_key=0, max_key=200000, request_cpu_per_access=0, raft_cpu_per_write=0
197197
number of mutation events=0, number of assertion events=0
@@ -221,7 +221,7 @@ generating settings configurations using static option
221221
----------------------------------
222222
sample1: start running
223223
configurations generated using seed 3440579354231278675
224-
basic cluster with nodes=3, stores_per_node=1, store_byte_capacity=274877906944
224+
basic cluster with nodes=3, stores_per_node=1, store_byte_capacity=274877906944, node_cpu_rate_capacity=0
225225
basic ranges with placement_type=even, ranges=10, min_key=0, max_key=200000, replication_factor=3, bytes=0
226226
basic load with rw_ratio=0.00, rate=0.00, skewed_access=false, min_block_size=1, max_block_size=1, min_key=0, max_key=200000, request_cpu_per_access=0, raft_cpu_per_write=0
227227
number of mutation events=0, number of assertion events=0
@@ -236,7 +236,7 @@ sample1: pass
236236
----------------------------------
237237
sample2: start running
238238
configurations generated using seed 608747136543856411
239-
basic cluster with nodes=3, stores_per_node=1, store_byte_capacity=274877906944
239+
basic cluster with nodes=3, stores_per_node=1, store_byte_capacity=274877906944, node_cpu_rate_capacity=0
240240
basic ranges with placement_type=even, ranges=10, min_key=0, max_key=200000, replication_factor=3, bytes=0
241241
basic load with rw_ratio=0.00, rate=0.00, skewed_access=false, min_block_size=1, max_block_size=1, min_key=0, max_key=200000, request_cpu_per_access=0, raft_cpu_per_write=0
242242
number of mutation events=0, number of assertion events=0
@@ -251,7 +251,7 @@ sample2: pass
251251
----------------------------------
252252
sample3: start running
253253
configurations generated using seed 5571782338101878760
254-
basic cluster with nodes=3, stores_per_node=1, store_byte_capacity=274877906944
254+
basic cluster with nodes=3, stores_per_node=1, store_byte_capacity=274877906944, node_cpu_rate_capacity=0
255255
basic ranges with placement_type=even, ranges=10, min_key=0, max_key=200000, replication_factor=3, bytes=0
256256
basic load with rw_ratio=0.00, rate=0.00, skewed_access=false, min_block_size=1, max_block_size=1, min_key=0, max_key=200000, request_cpu_per_access=0, raft_cpu_per_write=0
257257
number of mutation events=0, number of assertion events=0

pkg/kv/kvserver/asim/tests/testdata/rand/weighted_rand

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ generating settings configurations using static option
6868
----------------------------------
6969
sample1: start running
7070
configurations generated using seed 5571782338101878760
71-
basic cluster with nodes=3, stores_per_node=2, store_byte_capacity=274877906944
71+
basic cluster with nodes=3, stores_per_node=2, store_byte_capacity=274877906944, node_cpu_rate_capacity=0
7272
weighted randomized ranges with placement_type=weighted_rand, weighted_rand=[0 0 0 0.3 0.3 0.4], ranges=563, min_key=0, max_key=160411, replication_factor=3, bytes=0
7373
basic load with rw_ratio=0.00, rate=0.00, skewed_access=false, min_block_size=1, max_block_size=1, min_key=0, max_key=200000, request_cpu_per_access=0, raft_cpu_per_write=0
7474
number of mutation events=0, number of assertion events=0
@@ -78,7 +78,7 @@ sample1: pass
7878
----------------------------------
7979
sample2: start running
8080
configurations generated using seed 4299969443970870044
81-
basic cluster with nodes=3, stores_per_node=2, store_byte_capacity=274877906944
81+
basic cluster with nodes=3, stores_per_node=2, store_byte_capacity=274877906944, node_cpu_rate_capacity=0
8282
weighted randomized ranges with placement_type=weighted_rand, weighted_rand=[0 0 0 0.3 0.3 0.4], ranges=299, min_key=0, max_key=9542, replication_factor=3, bytes=0
8383
basic load with rw_ratio=0.00, rate=0.00, skewed_access=false, min_block_size=1, max_block_size=1, min_key=0, max_key=200000, request_cpu_per_access=0, raft_cpu_per_write=0
8484
number of mutation events=0, number of assertion events=0
@@ -88,7 +88,7 @@ sample2: pass
8888
----------------------------------
8989
sample3: start running
9090
configurations generated using seed 4157513341729910236
91-
basic cluster with nodes=3, stores_per_node=2, store_byte_capacity=274877906944
91+
basic cluster with nodes=3, stores_per_node=2, store_byte_capacity=274877906944, node_cpu_rate_capacity=0
9292
weighted randomized ranges with placement_type=weighted_rand, weighted_rand=[0 0 0 0.3 0.3 0.4], ranges=521, min_key=0, max_key=82660, replication_factor=3, bytes=0
9393
basic load with rw_ratio=0.00, rate=0.00, skewed_access=false, min_block_size=1, max_block_size=1, min_key=0, max_key=200000, request_cpu_per_access=0, raft_cpu_per_write=0
9494
number of mutation events=0, number of assertion events=0

0 commit comments

Comments
 (0)