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

scheduler: hotspot: solution-based key-rate-aware balance solver #2141

Merged
merged 31 commits into from
Feb 26, 2020
Merged
Show file tree
Hide file tree
Changes from 27 commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
f382b47
try more solution
Luffbee Feb 2, 2020
67d6f24
function betterThan
Luffbee Feb 4, 2020
1edb33a
add pending influence of count
Luffbee Feb 6, 2020
c28388d
introduce storeLoad[Pred]Cmp
Luffbee Feb 5, 2020
e70852b
remove unused function
Luffbee Feb 6, 2020
2a9e000
use resourceType
Luffbee Feb 7, 2020
2085ff6
new byteRateRank; float count
Luffbee Feb 7, 2020
eca28c9
Merge branch 'master' into solution-based
Luffbee Feb 21, 2020
291be85
add key rate for storeLoad, Influence
Luffbee Feb 10, 2020
1b91e04
make getHotPeers key-rate-aware
Luffbee Feb 10, 2020
228ba6c
make filterDstStores key-rate-aware
Luffbee Feb 10, 2020
e15c95c
make betterThan key-rate-aware
Luffbee Feb 11, 2020
bb52fe3
make prepare and influence key-rate-aware
Luffbee Feb 11, 2020
ba561d5
add metric; tune parameters
Luffbee Feb 11, 2020
cb8f562
write leader: remove byte rate constraint
Luffbee Feb 12, 2020
37ca8ac
progressiveRank
Luffbee Feb 15, 2020
f49baed
fix old tests
Luffbee Feb 17, 2020
517247a
remove unused code in test
Luffbee Feb 17, 2020
bff084c
add test for hot cache
Luffbee Feb 17, 2020
acd8281
update TestWithPendingInfluence
Luffbee Feb 20, 2020
5b6abe4
add test for key rate balance
Luffbee Feb 20, 2020
ef25256
fix typo
Luffbee Feb 22, 2020
35ec188
make toResourceType panic with invalid arguments
Luffbee Feb 24, 2020
a7240ad
remove unnecessary = nil
Luffbee Feb 24, 2020
73feca7
add constants minHot{Byte,Key}Rate
Luffbee Feb 24, 2020
f7b7be2
simplify and update comments for calcProgressiveRank
Luffbee Feb 24, 2020
bae99b8
add constants *RankStepRatio
Luffbee Feb 25, 2020
48e689e
add constants: *DecRatio
Luffbee Feb 25, 2020
b0ca960
rename getHotPeers and add comments
Luffbee Feb 25, 2020
4600833
add comments for *RankStepRatio
Luffbee Feb 26, 2020
4ac422a
Merge branch 'master' into solution-based
sre-bot Feb 26, 2020
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
40 changes: 38 additions & 2 deletions pkg/mock/mockcluster/mockcluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -270,9 +270,14 @@ func (mc *Cluster) AddLeaderRegionWithRange(regionID uint64, startKey string, en
}

// AddLeaderRegionWithReadInfo adds region with specified leader, followers and read info.
func (mc *Cluster) AddLeaderRegionWithReadInfo(regionID uint64, leaderID uint64, readBytes uint64, reportInterval uint64, followerIds ...uint64) {
func (mc *Cluster) AddLeaderRegionWithReadInfo(
regionID uint64, leaderID uint64,
readBytes, readKeys uint64,
reportInterval uint64,
followerIds []uint64) {
r := mc.newMockRegionInfo(regionID, leaderID, followerIds...)
r = r.Clone(core.SetReadBytes(readBytes))
r = r.Clone(core.SetReadKeys(readKeys))
r = r.Clone(core.SetReportInterval(reportInterval))
items := mc.HotCache.CheckRead(r, mc.StoresStats)
for _, item := range items {
Expand All @@ -282,9 +287,14 @@ func (mc *Cluster) AddLeaderRegionWithReadInfo(regionID uint64, leaderID uint64,
}

// AddLeaderRegionWithWriteInfo adds region with specified leader, followers and write info.
func (mc *Cluster) AddLeaderRegionWithWriteInfo(regionID uint64, leaderID uint64, writtenBytes uint64, reportInterval uint64, followerIds ...uint64) {
func (mc *Cluster) AddLeaderRegionWithWriteInfo(
regionID uint64, leaderID uint64,
writtenBytes, writtenKeys uint64,
reportInterval uint64,
followerIds []uint64) {
r := mc.newMockRegionInfo(regionID, leaderID, followerIds...)
r = r.Clone(core.SetWrittenBytes(writtenBytes))
r = r.Clone(core.SetWrittenKeys(writtenKeys))
r = r.Clone(core.SetReportInterval(reportInterval))
items := mc.HotCache.CheckWrite(r, mc.StoresStats)
for _, item := range items {
Expand Down Expand Up @@ -404,6 +414,32 @@ func (mc *Cluster) UpdateStorageReadBytes(storeID uint64, bytesRead uint64) {
mc.PutStore(newStore)
}

// UpdateStorageWrittenKeys updates store written keys.
func (mc *Cluster) UpdateStorageWrittenKeys(storeID uint64, keysWritten uint64) {
store := mc.GetStore(storeID)
newStats := proto.Clone(store.GetStoreStats()).(*pdpb.StoreStats)
newStats.KeysWritten = keysWritten
now := time.Now().Second()
interval := &pdpb.TimeInterval{StartTimestamp: uint64(now - statistics.StoreHeartBeatReportInterval), EndTimestamp: uint64(now)}
newStats.Interval = interval
newStore := store.Clone(core.SetStoreStats(newStats))
mc.Set(storeID, newStats)
mc.PutStore(newStore)
}

// UpdateStorageReadKeys updates store read bytes.
func (mc *Cluster) UpdateStorageReadKeys(storeID uint64, keysRead uint64) {
store := mc.GetStore(storeID)
newStats := proto.Clone(store.GetStoreStats()).(*pdpb.StoreStats)
newStats.KeysRead = keysRead
now := time.Now().Second()
interval := &pdpb.TimeInterval{StartTimestamp: uint64(now - statistics.StoreHeartBeatReportInterval), EndTimestamp: uint64(now)}
newStats.Interval = interval
newStore := store.Clone(core.SetStoreStats(newStats))
mc.Set(storeID, newStats)
mc.PutStore(newStore)
}

// UpdateStoreStatus updates store status.
func (mc *Cluster) UpdateStoreStatus(id uint64) {
leaderCount := mc.Regions.GetStoreLeaderCount(id)
Expand Down
4 changes: 4 additions & 0 deletions server/cluster/coordinator.go
Original file line number Diff line number Diff line change
Expand Up @@ -420,6 +420,8 @@ func (c *coordinator) collectHotSpotMetrics() {
infl := pendings[storeID]
// TODO: add to tidb-ansible after merging pending influence into operator influence.
nolouch marked this conversation as resolved.
Show resolved Hide resolved
hotSpotStatusGauge.WithLabelValues(storeAddress, storeLabel, "write_pending_influence_byte_rate").Set(infl.ByteRate)
hotSpotStatusGauge.WithLabelValues(storeAddress, storeLabel, "write_pending_influence_key_rate").Set(infl.KeyRate)
hotSpotStatusGauge.WithLabelValues(storeAddress, storeLabel, "write_pending_influence_count").Set(infl.Count)
}

// Collects hot read region metrics.
Expand All @@ -440,6 +442,8 @@ func (c *coordinator) collectHotSpotMetrics() {

infl := pendings[storeID]
hotSpotStatusGauge.WithLabelValues(storeAddress, storeLabel, "read_pending_influence_byte_rate").Set(infl.ByteRate)
hotSpotStatusGauge.WithLabelValues(storeAddress, storeLabel, "read_pending_influence_key_rate").Set(infl.KeyRate)
hotSpotStatusGauge.WithLabelValues(storeAddress, storeLabel, "read_pending_influence_count").Set(infl.Count)
}
}

Expand Down
Loading