Skip to content

Commit 5540ed3

Browse files
authored
More repressentitive logging of actual performance. (erigontech#18393)
We return to the engine API early and defer work like extra indexing to the second half of the forkchoice routine. this new logging better reflects that
1 parent 6ea4525 commit 5540ed3

1 file changed

Lines changed: 54 additions & 27 deletions

File tree

execution/execmodule/forkchoice.go

Lines changed: 54 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import (
2020
"context"
2121
"errors"
2222
"fmt"
23+
"math"
2324
"runtime"
2425
"strconv"
2526
"time"
@@ -39,6 +40,7 @@ import (
3940
"github.com/erigontech/erigon/execution/protocol/rules"
4041
"github.com/erigontech/erigon/execution/stagedsync"
4142
"github.com/erigontech/erigon/execution/stagedsync/stages"
43+
"github.com/erigontech/erigon/execution/types"
4244
"github.com/erigontech/erigon/node/gointerfaces"
4345
"github.com/erigontech/erigon/node/gointerfaces/executionproto"
4446
)
@@ -448,6 +450,7 @@ func (e *EthereumExecutionModule) updateForkChoice(ctx context.Context, original
448450
Status: executionproto.ExecutionStatus_Success,
449451
ValidationError: validationError,
450452
}, false)
453+
e.logHeadUpdated(blockHash, fcuHeader, 0, time.Duration(0), "head validated", false)
451454
}
452455
if err := e.forkValidator.FlushExtendingFork(tx, e.accumulator, e.recentReceipts); err != nil {
453456
sendForkchoiceErrorWithoutWaiting(e.logger, outcomeCh, err, stateFlushingInParallel)
@@ -591,34 +594,8 @@ func (e *EthereumExecutionModule) updateForkChoice(ctx context.Context, original
591594
return
592595
}
593596

594-
var m runtime.MemStats
595-
dbg.ReadMemStats(&m)
596-
blockTimings := e.forkValidator.GetTimings(blockHash)
597-
logArgs := []interface{}{"hash", blockHash, "number", fcuHeader.Number.Uint64(), "txnum", txnum, "age", common.PrettyAge(time.Unix(int64(fcuHeader.Time), 0))}
598-
if mergeExtendingFork {
599-
totalTime := blockTimings[engine_helpers.BlockTimingsValidationIndex]
600-
if !e.syncCfg.ParallelStateFlushing {
601-
totalTime += blockTimings[engine_helpers.BlockTimingsFlushExtendingFork]
602-
}
603-
gasUsedMgas := float64(fcuHeader.GasUsed) / 1e6
604-
mgasPerSec := gasUsedMgas / totalTime.Seconds()
605-
metrics.ChainTipMgasPerSec.Add(mgasPerSec)
606-
607-
const blockRange = 300 // ~1 hour
608-
const alpha = 2.0 / (blockRange + 1)
609-
610-
if e.avgMgasSec == 0 {
611-
e.avgMgasSec = mgasPerSec
612-
}
613-
e.avgMgasSec = alpha*mgasPerSec + (1-alpha)*e.avgMgasSec
614-
logArgs = append(logArgs, "execution", blockTimings[engine_helpers.BlockTimingsValidationIndex], "mgas/s", fmt.Sprintf("%.2f", mgasPerSec), "average mgas/s", fmt.Sprintf("%.2f", e.avgMgasSec))
615-
if !e.syncCfg.ParallelStateFlushing {
616-
logArgs = append(logArgs, "flushing", blockTimings[engine_helpers.BlockTimingsFlushExtendingFork])
617-
}
618-
}
619-
logArgs = append(logArgs, "commit", commitTime, "alloc", common.ByteCount(m.Alloc), "sys", common.ByteCount(m.Sys))
620597
if log {
621-
e.logger.Info("head updated", logArgs...)
598+
e.logHeadUpdated(blockHash, fcuHeader, txnum, commitTime, "head updated", stateFlushingInParallel)
622599
}
623600
}
624601
if *headNumber >= startPruneFrom {
@@ -646,6 +623,7 @@ func (e *EthereumExecutionModule) runPostForkchoiceInBackground(initialCycle boo
646623
defer e.semaphore.Release(1)
647624
pruneStart := time.Now()
648625
defer UpdateForkChoicePruneDuration(pruneStart)
626+
649627
if err := e.db.Update(e.bacgroundCtx, func(tx kv.RwTx) error {
650628
if err := e.executionPipeline.RunPrune(e.db, tx, initialCycle); err != nil {
651629
return err
@@ -666,3 +644,52 @@ func (e *EthereumExecutionModule) runPostForkchoiceInBackground(initialCycle boo
666644
}
667645
}()
668646
}
647+
648+
func (e *EthereumExecutionModule) logHeadUpdated(blockHash common.Hash, fcuHeader *types.Header, txnum uint64, commitTime time.Duration, msg string, debug bool) {
649+
var m runtime.MemStats
650+
dbg.ReadMemStats(&m)
651+
blockTimings := e.forkValidator.GetTimings(blockHash)
652+
653+
logArgs := []interface{}{"hash", blockHash, "number", fcuHeader.Number.Uint64()}
654+
if txnum != 0 {
655+
logArgs = append(logArgs, "txnum", txnum)
656+
}
657+
logArgs = append(logArgs, "age", common.PrettyAge(time.Unix(int64(fcuHeader.Time), 0)),
658+
"execution", blockTimings[engine_helpers.BlockTimingsValidationIndex])
659+
660+
if !debug {
661+
totalTime := blockTimings[engine_helpers.BlockTimingsValidationIndex]
662+
if !e.syncCfg.ParallelStateFlushing {
663+
totalTime += blockTimings[engine_helpers.BlockTimingsFlushExtendingFork]
664+
}
665+
gasUsedMgas := float64(fcuHeader.GasUsed) / 1e6
666+
mgasPerSec := gasUsedMgas / totalTime.Seconds()
667+
metrics.ChainTipMgasPerSec.Add(mgasPerSec)
668+
669+
const blockRange = 30 // ~1 hour
670+
const alpha = 2.0 / (blockRange + 1)
671+
672+
if e.avgMgasSec == 0 || e.avgMgasSec == math.Inf(1) {
673+
e.avgMgasSec = mgasPerSec
674+
}
675+
e.avgMgasSec = alpha*mgasPerSec + (1-alpha)*e.avgMgasSec
676+
// if mgasPerSec or avgMgasPerSec are 0, Inf or -Inf, do not log it but dont return either
677+
if mgasPerSec > 0 && mgasPerSec != math.Inf(1) && e.avgMgasSec > 0 && e.avgMgasSec != math.Inf(1) {
678+
logArgs = append(logArgs, "mgas/s", fmt.Sprintf("%.2f", mgasPerSec), "avg mgas/s", fmt.Sprintf("%.2f", e.avgMgasSec))
679+
}
680+
}
681+
if commitTime > 0 {
682+
logArgs = append(logArgs, "commit", commitTime)
683+
}
684+
if !e.syncCfg.ParallelStateFlushing {
685+
logArgs = append(logArgs, "flushing", blockTimings[engine_helpers.BlockTimingsFlushExtendingFork])
686+
}
687+
688+
logArgs = append(logArgs, "alloc", common.ByteCount(m.Alloc), "sys", common.ByteCount(m.Sys))
689+
690+
dbgLevel := log.LvlInfo
691+
if debug {
692+
dbgLevel = log.LvlDebug
693+
}
694+
e.logger.Log(dbgLevel, msg, logArgs...)
695+
}

0 commit comments

Comments
 (0)