Skip to content

Commit 09baa0d

Browse files
committed
asim: add write bytes per sec to capacity & range usage
Previously, we added WriteBytesPerSecond to roachpb.StoreCapacity. This commit plumbs it through store capacity aggregation, range load usage, and StoreMetrics. MMA will later use to track write bandwidth usage across stores. Epic: none Release note: none
1 parent c3d41ff commit 09baa0d

File tree

4 files changed

+35
-23
lines changed

4 files changed

+35
-23
lines changed

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ func MakeTS(metrics [][]StoreMetrics) map[string][][]float64 {
2424
ret["cpu"] = make([][]float64, stores)
2525
ret["write"] = make([][]float64, stores)
2626
ret["write_b"] = make([][]float64, stores)
27+
ret["write_bytes_per_second"] = make([][]float64, stores)
2728
ret["read"] = make([][]float64, stores)
2829
ret["read_b"] = make([][]float64, stores)
2930
ret["replicas"] = make([][]float64, stores)
@@ -41,6 +42,7 @@ func MakeTS(metrics [][]StoreMetrics) map[string][][]float64 {
4142
ret["cpu"][i] = append(ret["cpu"][i], float64(sm.CPU))
4243
ret["write"][i] = append(ret["write"][i], float64(sm.WriteKeys))
4344
ret["write_b"][i] = append(ret["write_b"][i], float64(sm.WriteBytes))
45+
ret["write_bytes_per_second"][i] = append(ret["write_bytes_per_second"][i], float64(sm.WriteBytesPerSecond))
4446
ret["read"][i] = append(ret["read"][i], float64(sm.ReadKeys))
4547
ret["read_b"][i] = append(ret["read_b"][i], float64(sm.ReadBytes))
4648
ret["replicas"][i] = append(ret["replicas"][i], float64(sm.Replicas))

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

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -18,16 +18,17 @@ import (
1818
// StoreMetrics tracks metrics per-store in a simulation run. Each metrics
1919
// struct is associated with a tick.
2020
type StoreMetrics struct {
21-
Tick time.Time
22-
StoreID int64
23-
QPS int64
24-
CPU int64
25-
WriteKeys int64
26-
WriteBytes int64
27-
ReadKeys int64
28-
ReadBytes int64
29-
Replicas int64
30-
Leases int64
21+
Tick time.Time
22+
StoreID int64
23+
QPS int64
24+
CPU int64
25+
WriteKeys int64
26+
WriteBytes int64
27+
WriteBytesPerSecond int64
28+
ReadKeys int64
29+
ReadBytes int64
30+
Replicas int64
31+
Leases int64
3132
// LeaseTransfers tracks the number of lease transfer that this store has
3233
// authored. Only the leaseholder store authors transfers.
3334
LeaseTransfers int64
@@ -48,12 +49,12 @@ func (sm *StoreMetrics) GetMetricValue(stat string) float64 {
4849
return float64(sm.QPS)
4950
case "cpu":
5051
return float64(sm.CPU)
51-
// case "write_bytes_per_second":
52-
// value = float64(sm.WriteBytesPerSecond)
5352
case "write":
5453
return float64(sm.WriteKeys)
5554
case "write_b":
5655
return float64(sm.WriteBytes)
56+
case "write_bytes_per_second":
57+
return float64(sm.WriteBytesPerSecond)
5758
case "read":
5859
return float64(sm.ReadKeys)
5960
case "read_b":

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -270,6 +270,7 @@ func (s *state) capacity(storeID StoreID) roachpb.StoreCapacity {
270270
capacity := store.desc.Capacity
271271
capacity.QueriesPerSecond = 0
272272
capacity.WritesPerSecond = 0
273+
capacity.WriteBytesPerSecond = 0
273274
capacity.LogicalBytes = 0
274275
capacity.CPUPerSecond = 0
275276
capacity.LeaseCount = 0
@@ -285,6 +286,7 @@ func (s *state) capacity(storeID StoreID) roachpb.StoreCapacity {
285286
// special handling needed here.
286287
capacity.QueriesPerSecond += usage.QueriesPerSecond
287288
capacity.WritesPerSecond += usage.WritesPerSecond
289+
capacity.WriteBytesPerSecond += usage.WriteBytesPerSecond
288290
capacity.LogicalBytes += usage.LogicalBytes
289291
capacity.CPUPerSecond += usage.RequestCPUNanosPerSecond + usage.RaftCPUNanosPerSecond
290292
capacity.RangeCount++

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

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@ func (rl *ReplicaLoadCounter) ApplyLoad(le workload.LoadEvent) {
7575
// are used.
7676
rl.loadStats.RecordReqCPUNanos(float64(le.RequestCPU))
7777
rl.loadStats.RecordRaftCPUNanos(float64(le.RaftCPU))
78+
rl.loadStats.RecordWriteBytes(float64(le.WriteSize))
7879
}
7980

8081
// Load translates the recorded key accesses and size into range usage
@@ -83,14 +84,15 @@ func (rl *ReplicaLoadCounter) Load() allocator.RangeUsageInfo {
8384
stats := rl.loadStats.Stats()
8485

8586
return allocator.RangeUsageInfo{
86-
QueriesPerSecond: stats.QueriesPerSecond,
87+
QueriesPerSecond: stats.QueriesPerSecond,
8788
// NB: WritesPerSecond is the sum of writes, rather than the rate. It is
8889
// only used for testing and could be removed.
8990
// TODO(wenyihu6): TestWorkloadApply and TestCapacityOverride tests this
9091
// field as a way to check if replicas have received the load. It is a bit
9192
// tricky to assert on the rate of writes per second. We should try
9293
// refactoring.
9394
WritesPerSecond: float64(rl.WriteKeys),
95+
WriteBytesPerSecond: stats.WriteBytesPerSecond,
9496
RaftCPUNanosPerSecond: stats.RaftCPUNanosPerSecond,
9597
RequestCPUNanosPerSecond: stats.RequestCPUNanosPerSecond,
9698
}
@@ -133,15 +135,16 @@ type CapacityOverride roachpb.StoreCapacity
133135
// NewCapacityOverride returns a capacity override where no overrides are set.
134136
func NewCapacityOverride() CapacityOverride {
135137
return CapacityOverride{
136-
Capacity: capacityOverrideSentinel,
137-
Available: capacityOverrideSentinel,
138-
Used: capacityOverrideSentinel,
139-
LogicalBytes: capacityOverrideSentinel,
140-
RangeCount: capacityOverrideSentinel,
141-
LeaseCount: capacityOverrideSentinel,
142-
QueriesPerSecond: capacityOverrideSentinel,
143-
WritesPerSecond: capacityOverrideSentinel,
144-
CPUPerSecond: capacityOverrideSentinel,
138+
Capacity: capacityOverrideSentinel,
139+
Available: capacityOverrideSentinel,
140+
Used: capacityOverrideSentinel,
141+
LogicalBytes: capacityOverrideSentinel,
142+
RangeCount: capacityOverrideSentinel,
143+
LeaseCount: capacityOverrideSentinel,
144+
QueriesPerSecond: capacityOverrideSentinel,
145+
WritesPerSecond: capacityOverrideSentinel,
146+
WriteBytesPerSecond: capacityOverrideSentinel,
147+
CPUPerSecond: capacityOverrideSentinel,
145148
IOThresholdMax: admissionpb.IOThreshold{
146149
L0NumSubLevels: capacityOverrideSentinel,
147150
L0NumSubLevelsThreshold: capacityOverrideSentinel,
@@ -156,7 +159,7 @@ func NewCapacityOverride() CapacityOverride {
156159
func (co CapacityOverride) String() string {
157160
return fmt.Sprintf(
158161
"capacity=%d, available=%d, used=%d, logical_bytes=%d, range_count=%d, lease_count=%d, "+
159-
"queries_per_sec=%.2f, writes_per_sec=%.2f, cpu_per_sec=%.2f, io_threshold_max=%v",
162+
"queries_per_sec=%.2f, writes_per_sec=%.2f, write_bytes_per_sec=%.2f, cpu_per_sec=%.2f, io_threshold_max=%v",
160163
co.Capacity,
161164
co.Available,
162165
co.Used,
@@ -165,6 +168,7 @@ func (co CapacityOverride) String() string {
165168
co.LeaseCount,
166169
co.QueriesPerSecond,
167170
co.WritesPerSecond,
171+
co.WriteBytesPerSecond,
168172
co.CPUPerSecond,
169173
co.IOThresholdMax,
170174
)
@@ -198,6 +202,9 @@ func mergeOverride(
198202
if override.WritesPerSecond != capacityOverrideSentinel {
199203
ret.WritesPerSecond = override.WritesPerSecond
200204
}
205+
if override.WriteBytesPerSecond != capacityOverrideSentinel {
206+
ret.WriteBytesPerSecond = override.WriteBytesPerSecond
207+
}
201208
if override.CPUPerSecond != capacityOverrideSentinel {
202209
ret.CPUPerSecond = override.CPUPerSecond
203210
}

0 commit comments

Comments
 (0)