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

statistics: support hotPeerCache maintained in Peer level #3627

Merged
merged 21 commits into from
May 8, 2021
Merged
Show file tree
Hide file tree
Changes from 9 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
72 changes: 72 additions & 0 deletions server/core/peer.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,3 +72,75 @@ func CountInJointState(peers ...*metapb.Peer) int {
}
return count
}

// PeerInfo provides peer information
type PeerInfo struct {
peerID uint64
Yisaer marked this conversation as resolved.
Show resolved Hide resolved
StoreID uint64
Yisaer marked this conversation as resolved.
Show resolved Hide resolved
writtenBytes uint64
writtenKeys uint64
readBytes uint64
readKeys uint64
Comment on lines +79 to +82
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

would you like to replace them with []float64?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We will change it with regionInfo together in future.

}

// GetKeysWritten provides peer written keys
func (p *PeerInfo) GetKeysWritten() uint64 {
return p.writtenKeys
}

// GetBytesWritten provides peer written bytes
func (p *PeerInfo) GetBytesWritten() uint64 {
return p.writtenBytes
}

// GetBytesRead provides peer read bytes
func (p *PeerInfo) GetBytesRead() uint64 {
return p.readBytes
}

// GetKeysRead provides read keys
func (p *PeerInfo) GetKeysRead() uint64 {
return p.readKeys
}

// GetStoreID provides located storeID
func (p *PeerInfo) GetStoreID() uint64 {
return p.StoreID
}

// GetPeerID provides peer id
func (p *PeerInfo) GetPeerID() uint64 {
return p.peerID
}

// FromMetaPeer provides PeerInfo from metapb.Peer
func FromMetaPeer(peer *metapb.Peer) *PeerInfo {
return &PeerInfo{
peerID: peer.GetId(),
StoreID: peer.GetStoreId(),
}
}

// SetBytesRead sets read bytes
func (p *PeerInfo) SetBytesRead(b uint64) *PeerInfo {
p.readBytes = b
return p
}

// SetKeysRead sets read keys
func (p *PeerInfo) SetKeysRead(k uint64) *PeerInfo {
p.readKeys = k
return p
}

// SetBytesWrite sets write bytes
func (p *PeerInfo) SetBytesWrite(b uint64) *PeerInfo {
p.writtenBytes = b
return p
}

// SetKeysWrite sets write keys
func (p *PeerInfo) SetKeysWrite(k uint64) *PeerInfo {
p.writtenKeys = k
return p
}
9 changes: 5 additions & 4 deletions server/statistics/hot_peer.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,9 +88,10 @@ type HotPeerStat struct {
// LastUpdateTime used to calculate average write
LastUpdateTime time.Time `json:"last_update_time"`

needDelete bool
isLeader bool
isNew bool
needDelete bool
isLeader bool
isNew bool
//TODO: remove it when we send peer stat by store info
justTransferLeader bool
interval uint64
thresholds []float64
Expand Down Expand Up @@ -128,7 +129,7 @@ func (stat *HotPeerStat) Log(str string, level func(msg string, fields ...zap.Fi

// IsNeedCoolDownTransferLeader use cooldown time after transfer leader to avoid unnecessary schedule
func (stat *HotPeerStat) IsNeedCoolDownTransferLeader(minHotDegree int) bool {
return time.Since(stat.lastTransferLeaderTime).Seconds() < float64(minHotDegree*RegionHeartBeatReportInterval)
return time.Since(stat.lastTransferLeaderTime).Seconds() < float64(minHotDegree*HotStatReportInterval)
}

// IsNeedDelete to delete the item in cache.
Expand Down
Loading