Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

kvserver: separate loadstats cpu nanos to raft/req #95387

Merged
merged 1 commit into from
Jan 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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