Skip to content

Commit

Permalink
add snapshot stats
Browse files Browse the repository at this point in the history
Signed-off-by: bufferflies <1045931706@qq.com>
  • Loading branch information
bufferflies committed Jun 9, 2023
1 parent 40c5dcb commit 0f48d0d
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 12 deletions.
2 changes: 1 addition & 1 deletion tools/pd-simulator/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ import (
)

var (
pdAddr = flag.String("pd", "", "pd address")
pdAddr = flag.String("pd-endpoints", "", "pd address")
configFile = flag.String("config", "conf/simconfig.toml", "config file")
caseName = flag.String("case", "", "case name")
serverLogLevel = flag.String("serverLog", "info", "pd server log level")
Expand Down
3 changes: 0 additions & 3 deletions tools/pd-simulator/simulator/cases/balance_region.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ package cases
import (
"time"

"github.com/docker/go-units"
"github.com/pingcap/kvproto/pkg/metapb"
"github.com/tikv/pd/pkg/core"
"github.com/tikv/pd/tools/pd-simulator/simulator/info"
Expand Down Expand Up @@ -55,8 +54,6 @@ func newRedundantBalanceRegion() *Case {
ID: IDAllocator.nextID(),
Peers: peers,
Leader: peers[0],
Size: 96 * units.MiB,
Keys: 960000,
})
}

Expand Down
3 changes: 3 additions & 0 deletions tools/pd-simulator/simulator/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,9 @@ func (sc *SimConfig) Adjust(meta *toml.MetaData) error {

return sc.ServerConfig.Adjust(meta, false)
}
func (sc *SimConfig) speed() uint64 {
return uint64(time.Second / sc.SimTickInterval.Duration)
}

// PDConfig saves some config which may be changed in PD.
type PDConfig struct {
Expand Down
4 changes: 2 additions & 2 deletions tools/pd-simulator/simulator/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,8 +92,8 @@ func NewNode(s *cases.Store, pdAddr string, config *SimConfig) (*Node, error) {
cancel()
return nil, err
}
ratio := int64(time.Second) / config.SimTickInterval.Milliseconds()
speed := config.StoreIOMBPerSecond * units.MiB * ratio
ratio := config.speed()
speed := config.StoreIOMBPerSecond * units.MiB * int64(ratio)
return &Node{
Store: store,
stats: stats,
Expand Down
13 changes: 7 additions & 6 deletions tools/pd-simulator/simulator/task.go
Original file line number Diff line number Diff line change
Expand Up @@ -415,13 +415,14 @@ func (a *addPeer) tick(engine *RaftEngine, region *core.RegionInfo) (newRegion *
pendingPeers := append(region.GetPendingPeers(), a.peer)
return region.Clone(core.WithAddPeer(a.peer), core.WithIncConfVer(), core.WithPendingPeers(pendingPeers)), false
}
speed := engine.storeConfig.speed()
// Step 2: Process Snapshot
if !processSnapshot(sendNode, a.sendingStat) {
if !processSnapshot(sendNode, a.sendingStat, speed) {
return nil, false
}
sendStoreID := fmt.Sprintf("store-%d", sendNode.Id)
snapshotCounter.WithLabelValues(sendStoreID, "send").Inc()
if !processSnapshot(recvNode, a.receivingStat) {
if !processSnapshot(recvNode, a.receivingStat, speed) {
return nil, false
}
recvStoreID := fmt.Sprintf("store-%d", recvNode.Id)
Expand Down Expand Up @@ -511,7 +512,7 @@ func newSnapshotState(size int64, action snapAction) *snapshotStat {
}
}

func processSnapshot(n *Node, stat *snapshotStat) bool {
func processSnapshot(n *Node, stat *snapshotStat, speed uint64) bool {
if stat.status == finished {
return true
}
Expand Down Expand Up @@ -544,9 +545,9 @@ func processSnapshot(n *Node, stat *snapshotStat) bool {
}
if stat.status == running {
stat.status = finished
totalSec := time.Since(stat.start).Seconds()
generateSec := time.Since(stat.generateStart).Seconds()
n.registerSnapStats(uint64(generateSec), 0, uint64(totalSec))
totalSec := uint64(time.Since(stat.start).Seconds()) * speed
generateSec := uint64(time.Since(stat.generateStart).Seconds()) * speed
n.registerSnapStats(generateSec, 0, totalSec)
if stat.action == generate {
n.stats.SendingSnapCount--
} else {
Expand Down

0 comments on commit 0f48d0d

Please sign in to comment.