Skip to content

Commit

Permalink
pd-simulator: update import-data case (tikv#2741)
Browse files Browse the repository at this point in the history
* Fix mv peer log parse error

* Delete unused var

* Rename

* Update case

* Address comment

* Update import_data.go

* Add stop condition

Co-authored-by: ShuNing <nolouch@gmail.com>
Signed-off-by: ZenoTan <zenotan1998@gmail.com>
  • Loading branch information
ZenoTan and nolouch authored Aug 11, 2020
1 parent c77593f commit 0475671
Showing 1 changed file with 20 additions and 15 deletions.
35 changes: 20 additions & 15 deletions tools/pd-simulator/simulator/cases/import_data.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@ func newImportData() *Case {
})
}

storeIDs := rand.Perm(3)
for i := 0; i < 40; i++ {
for i := 0; i < getRegionNum(); i++ {
storeIDs := rand.Perm(10)
peers := []*metapb.Peer{
{Id: IDAllocator.nextID(), StoreId: uint64(storeIDs[0] + 1)},
{Id: IDAllocator.nextID(), StoreId: uint64(storeIDs[1] + 1)},
Expand All @@ -63,23 +63,18 @@ func newImportData() *Case {
e := &WriteFlowOnSpotDescriptor{}
table2 := string(codec.EncodeBytes(codec.GenerateTableKey(2)))
table3 := string(codec.EncodeBytes(codec.GenerateTableKey(3)))
table5 := string(codec.EncodeBytes(codec.GenerateTableKey(5)))
e.Step = func(tick int64) map[string]int64 {
if tick < 100 {
return map[string]int64{
table3: 4 * MB,
table5: 32 * MB,
}
if tick > int64(getRegionNum())/10 {
return nil
}
return map[string]int64{
table2: 2 * MB,
table3: 4 * MB,
table5: 16 * MB,
table2: 32 * MB,
}
}
simCase.Events = []EventDescriptor{e}

// Checker description
checkCount := uint64(0)
simCase.Checker = func(regions *core.RegionsInfo, stats []info.StoreStats) bool {
leaderDist := make(map[uint64]int)
peerDist := make(map[uint64]int)
Expand Down Expand Up @@ -120,21 +115,31 @@ func newImportData() *Case {
regionTotal := regions.GetRegionCount()
totalLeaderLog := fmt.Sprintf("%d leader:", regionTotal)
totalPeerLog := fmt.Sprintf("%d peer:", regionTotal*3)
isEnd := true
isEnd := false
var regionProps []float64
for storeID := uint64(1); storeID <= 10; storeID++ {
regions.GetStoreRegionCount(storeID)
totalLeaderLog = fmt.Sprintf("%s [store %d]:%.2f%%", totalLeaderLog, storeID, float64(regions.GetStoreLeaderCount(storeID))/float64(regionTotal)*100)
regionProp := float64(regions.GetStoreRegionCount(storeID)) / float64(regionTotal*3) * 100
if regionProp > 13.8 {
isEnd = false
}
regionProps = append(regionProps, regionProp)
totalPeerLog = fmt.Sprintf("%s [store %d]:%.2f%%", totalPeerLog, storeID, regionProp)
}
simutil.Logger.Info("import data information",
zap.String("table-leader", tableLeaderLog),
zap.String("table-peer", tablePeerLog),
zap.String("total-leader", totalLeaderLog),
zap.String("total-peer", totalPeerLog))
checkCount++
dev := 0.0
for _, p := range regionProps {
dev += (p - 10) * (p - 10) / 100
}
if dev > 0.005 {
simutil.Logger.Warn("Not balanced, change scheduler or store limit", zap.Float64("dev score", dev))
}
if checkCount > uint64(getRegionNum())/10 {
isEnd = dev < 0.002
}
return isEnd
}
return &simCase
Expand Down

0 comments on commit 0475671

Please sign in to comment.