Skip to content

Commit

Permalink
Add metering into height index repair script (ava-labs#1183)
Browse files Browse the repository at this point in the history
  • Loading branch information
aaronbuchwald authored Feb 8, 2022
1 parent 639a345 commit 81901ab
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion vms/proposervm/indexer/height_indexer.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,12 @@ import (
)

// default number of heights to index before committing
const defaultCommitFrequency = 1024
const (
defaultCommitFrequency = 1024
// Sleep [sleepDurationMultiplier]x (5x) the amount of time we spend processing the block
// to ensure the async indexing does not bottleneck the node.
sleepDurationMultiplier = 5
)

var _ HeightIndexer = &heightIndexer{}

Expand Down Expand Up @@ -103,6 +108,7 @@ func (hi *heightIndexer) doRepair(ctx context.Context, currentProBlkID ids.ID) e
if err := ctx.Err(); err != nil {
return err
}
processingStart := time.Now()
currentAcceptedBlk, err := hi.server.GetWrappingBlk(currentProBlkID)
if err == database.ErrNotFound {
// We have visited all the proposerVM blocks. Because we previously
Expand Down Expand Up @@ -170,6 +176,11 @@ func (hi *heightIndexer) doRepair(ctx context.Context, currentProBlkID ids.ID) e
// keep checking the parent
currentProBlkID = currentAcceptedBlk.Parent()
previousHeight = currentHeight

processingDuration := time.Since(processingStart)
// Sleep [sleepDurationMultiplier]x (5x) the amount of time we spend processing the block
// to ensure the indexing does not bottleneck the node.
time.Sleep(processingDuration * sleepDurationMultiplier)
}
}

Expand Down

0 comments on commit 81901ab

Please sign in to comment.