Skip to content

Commit 8d61e62

Browse files
wenyihu6tbg
authored andcommitted
asim: record cpu utilization in StoreMetrics
Previously, StoreMetrics didn't include CPU utilization, making it hard to evaluate the simulation setup. This commit adds CPU utilization to the store metrics. Note that due to the lack of node-level metrics, the same CPU capacity will be repeated for stores on the same node.
1 parent 34a1a43 commit 8d61e62

35 files changed

+98
-68
lines changed

pkg/kv/kvserver/asim/history/history.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ func (h *History) ShowRecordedValueAt(idx int, stat string) (string, bool) {
6565
}
6666
storeID := h.Recorded[idx][i].StoreID
6767

68-
if stat == "disk_fraction_used" {
68+
if stat == "disk_fraction_used" || stat == "cpu_util" {
6969
_, _ = fmt.Fprintf(&buf, "s%v=%.2f", storeID, v)
7070
} else {
7171
_, _ = fmt.Fprintf(&buf, "s%v=%.0f", storeID, v)

pkg/kv/kvserver/asim/metrics/series.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ func MakeTS(metrics [][]StoreMetrics) map[string][][]float64 {
2222
// are partially duplicated with the cluster tracker.
2323
ret["qps"] = make([][]float64, stores)
2424
ret["cpu"] = make([][]float64, stores)
25+
ret["cpu_util"] = make([][]float64, stores)
2526
ret["write"] = make([][]float64, stores)
2627
ret["write_b"] = make([][]float64, stores)
2728
ret["write_bytes_per_second"] = make([][]float64, stores)
@@ -40,6 +41,7 @@ func MakeTS(metrics [][]StoreMetrics) map[string][][]float64 {
4041
for i, sm := range sms {
4142
ret["qps"][i] = append(ret["qps"][i], float64(sm.QPS))
4243
ret["cpu"][i] = append(ret["cpu"][i], float64(sm.CPU))
44+
ret["cpu_util"][i] = append(ret["cpu_util"][i], sm.NodeCPUUtilization)
4345
ret["write"][i] = append(ret["write"][i], float64(sm.WriteKeys))
4446
ret["write_b"][i] = append(ret["write_b"][i], float64(sm.WriteBytes))
4547
ret["write_bytes_per_second"][i] = append(ret["write_bytes_per_second"][i], float64(sm.WriteBytesPerSecond))

pkg/kv/kvserver/asim/metrics/tracker.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ type StoreMetrics struct {
2222
StoreID int64
2323
QPS int64
2424
CPU int64
25+
NodeCPUUtilization float64
2526
WriteKeys int64
2627
WriteBytes int64
2728
WriteBytesPerSecond int64
@@ -75,6 +76,8 @@ func (sm *StoreMetrics) GetMetricValue(stat string) float64 {
7576
return float64(sm.RangeSplits)
7677
case "disk_fraction_used":
7778
return sm.DiskFractionUsed
79+
case "cpu_util":
80+
return sm.NodeCPUUtilization
7881
default:
7982
return 0
8083
}
@@ -139,12 +142,21 @@ func (mt *Tracker) Tick(ctx context.Context, tick time.Time, s state.State) {
139142
}
140143

141144
desc := store.Descriptor()
145+
nodeCapacity := s.NodeCapacity(store.NodeID())
146+
147+
// NodeCPURateUsage is the same as StoresCPURate in asim.
148+
if nodeCapacity.NodeCPURateCapacity == 0 {
149+
panic(fmt.Sprintf("unexpected: node cpu rate capacity is 0 (node cpu rate usage = %d)",
150+
nodeCapacity.NodeCPURateUsage))
151+
}
152+
cpuUtil := float64(nodeCapacity.NodeCPURateUsage) / float64(nodeCapacity.NodeCPURateCapacity)
142153

143154
sm := StoreMetrics{
144155
Tick: tick,
145156
StoreID: int64(storeID),
146157
QPS: int64(desc.Capacity.QueriesPerSecond),
147158
CPU: int64(desc.Capacity.CPUPerSecond),
159+
NodeCPUUtilization: cpuUtil,
148160
WriteKeys: u.WriteKeys,
149161
WriteBytes: u.WriteBytes,
150162
WriteBytesPerSecond: int64(desc.Capacity.WriteBytesPerSecond),

pkg/kv/kvserver/asim/tests/testdata/generated/example_rebalancing/example_rebalancing_mma-only_1.json

Lines changed: 1 addition & 1 deletion
Large diffs are not rendered by default.

pkg/kv/kvserver/asim/tests/testdata/generated/example_rebalancing/example_rebalancing_mma-only_2.json

Lines changed: 1 addition & 1 deletion
Large diffs are not rendered by default.

pkg/kv/kvserver/asim/tests/testdata/generated/example_rebalancing/example_rebalancing_sma-count_1.json

Lines changed: 1 addition & 1 deletion
Large diffs are not rendered by default.

pkg/kv/kvserver/asim/tests/testdata/generated/example_rebalancing/example_rebalancing_sma-count_2.json

Lines changed: 1 addition & 1 deletion
Large diffs are not rendered by default.

pkg/kv/kvserver/asim/tests/testdata/non_rand/decommission_conformance.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ assertion type=conformance under=0 over=0 unavailable=0 violating=0
2828

2929
eval duration=20m cfgs=(sma-count,mma-only)
3030
----
31-
artifacts[sma-count]: 1375509107ab02af
31+
artifacts[sma-count]: 19128202c9e746ab
3232
==========================
33-
artifacts[mma-only]: 398e8cd95b3327fb
33+
artifacts[mma-only]: d80019be362b72f7
3434
==========================

pkg/kv/kvserver/asim/tests/testdata/non_rand/example_add_node.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ eval duration=20m samples=1 seed=42 metrics=(replicas)
3434
----
3535
replicas#1: first: [s1=301, s2=0, s3=0] (stddev=141.89, mean=100.33, sum=301)
3636
replicas#1: last: [s1=301, s2=271, s3=267] (stddev=15.17, mean=279.67, sum=839)
37-
artifacts[sma-count]: 866426beb5ad043b
37+
artifacts[sma-count]: 2ec16a0a9e1fe5b1
3838
failed assertion sample 1
3939
balance stat=replicas threshold=(≤1.05) ticks=6
4040
max/mean=1.08 tick=0

pkg/kv/kvserver/asim/tests/testdata/non_rand/example_conformance.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ assertion type=conformance under=0 over=0 unavailable=0 violating=0
2828

2929
eval duration=10m cfgs=(sma-count,mma-only)
3030
----
31-
artifacts[sma-count]: ca2c6e7399a9dc9c
31+
artifacts[sma-count]: 1dc992474ba09e56
3232
==========================
33-
artifacts[mma-only]: 273dc0cd62dfba6c
33+
artifacts[mma-only]: 412f90f16a6ace6
3434
==========================

0 commit comments

Comments
 (0)