mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-05-15 04:26:37 +00:00
eth/protocols/snap: add healing and syncing metrics (#32258)
Adds the heal time and snap sync time to grafana --------- Co-authored-by: Gary Rong <garyrong0905@gmail.com>
This commit is contained in:
parent
16117eb7cd
commit
b369a855fb
2 changed files with 26 additions and 3 deletions
|
|
@ -66,4 +66,7 @@ var (
|
||||||
// discarded during the snap sync.
|
// discarded during the snap sync.
|
||||||
largeStorageDiscardGauge = metrics.NewRegisteredGauge("eth/protocols/snap/sync/storage/chunk/discard", nil)
|
largeStorageDiscardGauge = metrics.NewRegisteredGauge("eth/protocols/snap/sync/storage/chunk/discard", nil)
|
||||||
largeStorageResumedGauge = metrics.NewRegisteredGauge("eth/protocols/snap/sync/storage/chunk/resume", nil)
|
largeStorageResumedGauge = metrics.NewRegisteredGauge("eth/protocols/snap/sync/storage/chunk/resume", nil)
|
||||||
|
|
||||||
|
stateSyncTimeGauge = metrics.NewRegisteredGauge("eth/protocols/snap/sync/time/statesync", nil)
|
||||||
|
stateHealTimeGauge = metrics.NewRegisteredGauge("eth/protocols/snap/sync/time/stateheal", nil)
|
||||||
)
|
)
|
||||||
|
|
|
||||||
|
|
@ -502,8 +502,10 @@ type Syncer struct {
|
||||||
storageHealed uint64 // Number of storage slots downloaded during the healing stage
|
storageHealed uint64 // Number of storage slots downloaded during the healing stage
|
||||||
storageHealedBytes common.StorageSize // Number of raw storage bytes persisted to disk during the healing stage
|
storageHealedBytes common.StorageSize // Number of raw storage bytes persisted to disk during the healing stage
|
||||||
|
|
||||||
startTime time.Time // Time instance when snapshot sync started
|
startTime time.Time // Time instance when snapshot sync started
|
||||||
logTime time.Time // Time instance when status was last reported
|
healStartTime time.Time // Time instance when the state healing started
|
||||||
|
syncTimeOnce sync.Once // Ensure that the state sync time is uploaded only once
|
||||||
|
logTime time.Time // Time instance when status was last reported
|
||||||
|
|
||||||
pend sync.WaitGroup // Tracks network request goroutines for graceful shutdown
|
pend sync.WaitGroup // Tracks network request goroutines for graceful shutdown
|
||||||
lock sync.RWMutex // Protects fields that can change outside of sync (peers, reqs, root)
|
lock sync.RWMutex // Protects fields that can change outside of sync (peers, reqs, root)
|
||||||
|
|
@ -685,6 +687,14 @@ func (s *Syncer) Sync(root common.Hash, cancel chan struct{}) error {
|
||||||
s.cleanStorageTasks()
|
s.cleanStorageTasks()
|
||||||
s.cleanAccountTasks()
|
s.cleanAccountTasks()
|
||||||
if len(s.tasks) == 0 && s.healer.scheduler.Pending() == 0 {
|
if len(s.tasks) == 0 && s.healer.scheduler.Pending() == 0 {
|
||||||
|
// State healing phase completed, record the elapsed time in metrics.
|
||||||
|
// Note: healing may be rerun in subsequent cycles to fill gaps between
|
||||||
|
// pivot states (e.g., if chain sync takes longer).
|
||||||
|
if !s.healStartTime.IsZero() {
|
||||||
|
stateHealTimeGauge.Inc(int64(time.Since(s.healStartTime)))
|
||||||
|
log.Info("State healing phase is completed", "elapsed", common.PrettyDuration(time.Since(s.healStartTime)))
|
||||||
|
s.healStartTime = time.Time{}
|
||||||
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
// Assign all the data retrieval tasks to any free peers
|
// Assign all the data retrieval tasks to any free peers
|
||||||
|
|
@ -693,7 +703,17 @@ func (s *Syncer) Sync(root common.Hash, cancel chan struct{}) error {
|
||||||
s.assignStorageTasks(storageResps, storageReqFails, cancel)
|
s.assignStorageTasks(storageResps, storageReqFails, cancel)
|
||||||
|
|
||||||
if len(s.tasks) == 0 {
|
if len(s.tasks) == 0 {
|
||||||
// Sync phase done, run heal phase
|
// State sync phase completed, record the elapsed time in metrics.
|
||||||
|
// Note: the initial state sync runs only once, regardless of whether
|
||||||
|
// a new cycle is started later. Any state differences in subsequent
|
||||||
|
// cycles will be handled by the state healer.
|
||||||
|
s.syncTimeOnce.Do(func() {
|
||||||
|
stateSyncTimeGauge.Update(int64(time.Since(s.startTime)))
|
||||||
|
log.Info("State sync phase is completed", "elapsed", common.PrettyDuration(time.Since(s.startTime)))
|
||||||
|
})
|
||||||
|
if s.healStartTime.IsZero() {
|
||||||
|
s.healStartTime = time.Now()
|
||||||
|
}
|
||||||
s.assignTrienodeHealTasks(trienodeHealResps, trienodeHealReqFails, cancel)
|
s.assignTrienodeHealTasks(trienodeHealResps, trienodeHealReqFails, cancel)
|
||||||
s.assignBytecodeHealTasks(bytecodeHealResps, bytecodeHealReqFails, cancel)
|
s.assignBytecodeHealTasks(bytecodeHealResps, bytecodeHealReqFails, cancel)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue