Skip to content

Commit

Permalink
kvserver: separate loadstats cpu nanos to raft/req
Browse files Browse the repository at this point in the history
Previously, loadstats tracked replica raft/request cpu nanos per second
separately but returned both summed together in `load.ReplicaLoadStats`.
This patch separates `RaftCPUNanosPerSecond` and
`RequestCPUNanosPerSecond` in the returned `load.ReplicaLoadStats` so
that they may be used independently.

Informs cockroachdb#95380

Release note: None
  • Loading branch information
kvoli committed Jan 17, 2023
1 parent ec92c4e commit 9b55718
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 17 deletions.
10 changes: 6 additions & 4 deletions pkg/kv/kvserver/allocator/range_usage_info.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,12 @@ import (
// RangeUsageInfo contains usage information (sizes and traffic) needed by the
// allocator to make rebalancing decisions for a given range.
type RangeUsageInfo struct {
LogicalBytes int64
QueriesPerSecond float64
WritesPerSecond float64
RequestLocality *RangeRequestLocalityInfo
LogicalBytes int64
QueriesPerSecond float64
WritesPerSecond float64
RequestCPUNanosPerSecond float64
RaftCPUNanosPerSecond float64
RequestLocality *RangeRequestLocalityInfo
}

// RangeRequestLocalityInfo is the same as PerLocalityCounts and is used for
Expand Down
23 changes: 14 additions & 9 deletions pkg/kv/kvserver/load/replica_load.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,12 @@ type ReplicaLoadStats struct {
// ReadBytesPerSecond is the replica's average bytes read per second. A "Read" is as
// described in ReadsPerSecond.
ReadBytesPerSecond float64
// CPUNanosPerSecond is the range's time spent on-processor averaged per second.
CPUNanosPerSecond float64
// RaftCPUNanos is the replica's time spent on-processor for raft averaged
// per second.
RaftCPUNanosPerSecond float64
// RequestCPUNanos is the replica's time spent on-processor for requests
// averaged per second.
RequestCPUNanosPerSecond float64
}

// ReplicaLoad tracks a sliding window of throughput on a replica.
Expand Down Expand Up @@ -188,13 +192,14 @@ func (rl *ReplicaLoad) Stats() ReplicaLoadStats {
defer rl.mu.Unlock()

return ReplicaLoadStats{
QueriesPerSecond: rl.getLocked(Queries),
RequestsPerSecond: rl.getLocked(Requests),
WriteKeysPerSecond: rl.getLocked(WriteKeys),
ReadKeysPerSecond: rl.getLocked(ReadKeys),
WriteBytesPerSecond: rl.getLocked(WriteBytes),
ReadBytesPerSecond: rl.getLocked(ReadBytes),
CPUNanosPerSecond: rl.getLocked(RaftCPUNanos) + rl.getLocked(ReqCPUNanos),
QueriesPerSecond: rl.getLocked(Queries),
RequestsPerSecond: rl.getLocked(Requests),
WriteKeysPerSecond: rl.getLocked(WriteKeys),
ReadKeysPerSecond: rl.getLocked(ReadKeys),
WriteBytesPerSecond: rl.getLocked(WriteBytes),
ReadBytesPerSecond: rl.getLocked(ReadBytes),
RequestCPUNanosPerSecond: rl.getLocked(ReqCPUNanos),
RaftCPUNanosPerSecond: rl.getLocked(RaftCPUNanos),
}
}

Expand Down
8 changes: 5 additions & 3 deletions pkg/kv/kvserver/replicate_queue.go
Original file line number Diff line number Diff line change
Expand Up @@ -2105,9 +2105,11 @@ func RangeUsageInfoForRepl(repl *Replica) allocator.RangeUsageInfo {
loadStats := repl.LoadStats()
localityInfo := repl.loadStats.RequestLocalityInfo()
return allocator.RangeUsageInfo{
LogicalBytes: repl.GetMVCCStats().Total(),
QueriesPerSecond: loadStats.QueriesPerSecond,
WritesPerSecond: loadStats.WriteKeysPerSecond,
LogicalBytes: repl.GetMVCCStats().Total(),
QueriesPerSecond: loadStats.QueriesPerSecond,
WritesPerSecond: loadStats.WriteKeysPerSecond,
RaftCPUNanosPerSecond: loadStats.RaftCPUNanosPerSecond,
RequestCPUNanosPerSecond: loadStats.RequestCPUNanosPerSecond,
RequestLocality: &allocator.RangeRequestLocalityInfo{
Counts: localityInfo.LocalityCounts,
Duration: localityInfo.Duration,
Expand Down
2 changes: 1 addition & 1 deletion pkg/kv/kvserver/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -3155,7 +3155,7 @@ func (s *Store) updateReplicationGauges(ctx context.Context) error {
averageReadsPerSecond += loadStats.ReadKeysPerSecond
averageReadBytesPerSecond += loadStats.ReadBytesPerSecond
averageWriteBytesPerSecond += loadStats.WriteBytesPerSecond
averageCPUNanosPerSecond += loadStats.CPUNanosPerSecond
averageCPUNanosPerSecond += loadStats.RaftCPUNanosPerSecond + loadStats.RequestCPUNanosPerSecond

locks += metrics.LockTableMetrics.Locks
totalLockHoldDurationNanos += metrics.LockTableMetrics.TotalLockHoldDurationNanos
Expand Down

0 comments on commit 9b55718

Please sign in to comment.