utils

package
v1.1.0-beta.0...-dd8df1a Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 15, 2025 License: Apache-2.0 Imports: 6 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// RegionHeartBeatReportInterval indicates the interval between write interval, the value is the heartbeat report interval of a region.
	RegionHeartBeatReportInterval = 60
	// StoreHeartBeatReportInterval indicates the interval between read stats report, the value is the heartbeat report interval of a store.
	StoreHeartBeatReportInterval = 10

	// HotRegionAntiCount is default value for antiCount
	HotRegionAntiCount = 2

	// DefaultAotSize is default size of average over time.
	DefaultAotSize = 1
	// DefaultWriteMfSize is default size of write median filter.
	DefaultWriteMfSize = 5
	// DefaultReadMfSize is default size of read median filter.
	DefaultReadMfSize = 5
)
View Source
const (
	// BytePriority indicates hot-region-scheduler prefer byte dim
	BytePriority = "byte"
	// KeyPriority indicates hot-region-scheduler prefer key dim
	KeyPriority = "key"
	// QueryPriority indicates hot-region-scheduler prefer query dim
	QueryPriority = "query"
)
View Source
const (
	ByteDim int = iota
	KeyDim
	QueryDim
	DimLen
)

Indicator dims.

Variables

View Source
var MinHotThresholds = [RegionStatCount]float64{
	RegionReadBytes:     8 * units.KiB,
	RegionReadKeys:      128,
	RegionReadQueryNum:  128,
	RegionWriteBytes:    1 * units.KiB,
	RegionWriteKeys:     32,
	RegionWriteQueryNum: 32,
}

MinHotThresholds is the threshold at which this dimension is recorded as a hot spot.

Functions

func DimToString

func DimToString(dim int) string

DimToString return string according to dim.

func ForeachRegionStats

func ForeachRegionStats(f func(RWType, int, RegionStatKind))

ForeachRegionStats foreach all region stats of read and write.

func StringToDim

func StringToDim(name string) int

StringToDim return dim according to string.

Types

type ActionType

type ActionType int

ActionType indicates the action type for the stat item.

const (
	Add ActionType = iota
	Remove
	Update
	ActionTypeLen
)

Flags for action type.

func (ActionType) String

func (t ActionType) String() string

type RWType

type RWType int

RWType is a identify hot region types.

const (
	Write RWType = iota
	Read
	RWTypeLen
)

Flags for r/w type.

func (RWType) DefaultAntiCount

func (rw RWType) DefaultAntiCount() int

DefaultAntiCount returns the default anti count of read or write.

func (RWType) GetLoadRates

func (rw RWType) GetLoadRates(deltaLoads []float64, interval uint64) []float64

GetLoadRates gets the load rates of the read or write type.

func (RWType) Inverse

func (rw RWType) Inverse() RWType

Inverse returns the opposite of kind.

func (RWType) RegionStats

func (rw RWType) RegionStats() []RegionStatKind

RegionStats returns hot items according to kind

func (RWType) ReportInterval

func (rw RWType) ReportInterval() int

ReportInterval returns the report interval of read or write.

func (RWType) SetFullLoadRates

func (rw RWType) SetFullLoadRates(full []float64, loads []float64)

SetFullLoadRates set load rates to full as read or write type.

func (RWType) String

func (rw RWType) String() string

type RegionStatKind

type RegionStatKind int

RegionStatKind represents the statistics type of region.

const (
	RegionReadBytes RegionStatKind = iota
	RegionReadKeys
	RegionReadQueryNum
	RegionWriteBytes
	RegionWriteKeys
	RegionWriteQueryNum

	RegionStatCount
)

Different region statistics kinds.

func (RegionStatKind) String

func (k RegionStatKind) String() string

type SourceKind

type SourceKind int

SourceKind represents the statistics item source.

const (
	Direct  SourceKind = iota // there is a corresponding peer in this store.
	Inherit                   // there is no corresponding peer in this store and we need to copy from other stores.
)

Different statistics item sources.

func (SourceKind) String

func (k SourceKind) String() string

type StoreStatKind

type StoreStatKind int

StoreStatKind represents the statistics type of store.

const (
	StoreReadBytes StoreStatKind = iota
	StoreReadKeys
	StoreWriteBytes
	StoreWriteKeys
	StoreReadQuery
	StoreWriteQuery
	StoreCPUUsage
	StoreDiskReadRate
	StoreDiskWriteRate

	StoreRegionsWriteBytes // Same as StoreWriteBytes, but it is counted by RegionHeartbeat.
	StoreRegionsWriteKeys  // Same as StoreWriteKeys, but it is counted by RegionHeartbeat.

	StoreStatCount
)

Different store statistics kinds.

func (StoreStatKind) String

func (k StoreStatKind) String() string

type TopN

type TopN struct {
	// contains filtered or unexported fields
}

TopN maintains the N largest items of multiple dimensions.

func NewTopN

func NewTopN(k, n int, ttl time.Duration) *TopN

NewTopN returns a k-dimensional TopN with given TTL. NOTE: panic if k <= 0 or n <= 0.

func (*TopN) Get

func (tn *TopN) Get(id uint64) TopNItem

Get returns the item with given id, nil if there is no such item.

func (*TopN) GetAll

func (tn *TopN) GetAll() []TopNItem

GetAll returns all items.

func (*TopN) GetAllTopN

func (tn *TopN) GetAllTopN(k int) []TopNItem

GetAllTopN returns the top N items of the `k`th dimension.

func (*TopN) GetTopNMin

func (tn *TopN) GetTopNMin(k int) TopNItem

GetTopNMin returns the min item in top N of the `k`th dimension.

func (*TopN) Len

func (tn *TopN) Len() int

Len returns number of all items.

func (*TopN) Put

func (tn *TopN) Put(item TopNItem) (isUpdate bool)

Put inserts item or updates the old item if it exists.

func (*TopN) Remove

func (tn *TopN) Remove(id uint64) (item TopNItem)

Remove deletes the item by given ID and returns it.

func (*TopN) RemoveExpired

func (tn *TopN) RemoveExpired() []uint64

RemoveExpired deletes all expired items.

type TopNItem

type TopNItem interface {
	// ID is used to check identity.
	ID() uint64
	// Less tests whether the current item is less than the given argument in the `k`th dimension.
	Less(k int, than TopNItem) bool
}

TopNItem represents a single object in TopN.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL