From 3eeae7c1c39059f0fff6f9a9df226dc29fd99c4f Mon Sep 17 00:00:00 2001 From: Monkey Date: Fri, 2 May 2025 01:53:45 +0800 Subject: [PATCH 1/3] add a chain/mgasps metric to indicate the per second used gas --- core/blockchain.go | 3 ++- core/blockchain_insert.go | 6 +++++- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/core/blockchain.go b/core/blockchain.go index 6667f649110c..60581047150e 100644 --- a/core/blockchain.go +++ b/core/blockchain.go @@ -65,7 +65,8 @@ var ( headFinalizedBlockGauge = metrics.NewRegisteredGauge("chain/head/finalized", nil) headSafeBlockGauge = metrics.NewRegisteredGauge("chain/head/safe", nil) - chainInfoGauge = metrics.NewRegisteredGaugeInfo("chain/info", nil) + chainInfoGauge = metrics.NewRegisteredGaugeInfo("chain/info", nil) + chainMgaspsGauge = metrics.NewRegisteredGauge("chain/mgasps", nil) accountReadTimer = metrics.NewRegisteredResettingTimer("chain/account/reads", nil) accountHashTimer = metrics.NewRegisteredResettingTimer("chain/account/hashes", nil) diff --git a/core/blockchain_insert.go b/core/blockchain_insert.go index ec3f771818fa..72268ef9fd31 100644 --- a/core/blockchain_insert.go +++ b/core/blockchain_insert.go @@ -44,7 +44,11 @@ func (st *insertStats) report(chain []*types.Block, index int, snapDiffItems, sn var ( now = mclock.Now() elapsed = now.Sub(st.startTime) + mgasps = float64(st.usedGas) * 1000 / float64(elapsed) ) + // Update the Mgas per second gauge + chainMgaspsGauge.Update(int64(mgasps)) + // If we're at the last block of the batch or report period reached, log if index == len(chain)-1 || elapsed >= statsReportLimit { // Count the number of transactions in this segment @@ -58,7 +62,7 @@ func (st *insertStats) report(chain []*types.Block, index int, snapDiffItems, sn context := []interface{}{ "number", end.Number(), "hash", end.Hash(), "blocks", st.processed, "txs", txs, "mgas", float64(st.usedGas) / 1000000, - "elapsed", common.PrettyDuration(elapsed), "mgasps", float64(st.usedGas) * 1000 / float64(elapsed), + "elapsed", common.PrettyDuration(elapsed), "mgasps", mgasps, } if timestamp := time.Unix(int64(end.Time()), 0); time.Since(timestamp) > time.Minute { context = append(context, []interface{}{"age", common.PrettyAge(timestamp)}...) From c698290536dd5bc05b865392aab1215f149b726a Mon Sep 17 00:00:00 2001 From: Marcel <153717436+MonkeyMarcel@users.noreply.github.com> Date: Wed, 7 May 2025 01:11:04 +0800 Subject: [PATCH 2/3] zero division fix --- core/blockchain_insert.go | 3 +++ 1 file changed, 3 insertions(+) diff --git a/core/blockchain_insert.go b/core/blockchain_insert.go index 72268ef9fd31..6873afdbf432 100644 --- a/core/blockchain_insert.go +++ b/core/blockchain_insert.go @@ -44,6 +44,9 @@ func (st *insertStats) report(chain []*types.Block, index int, snapDiffItems, sn var ( now = mclock.Now() elapsed = now.Sub(st.startTime) + if elapsed == 0 { // prevent zero division + elapsed = 1 + } mgasps = float64(st.usedGas) * 1000 / float64(elapsed) ) // Update the Mgas per second gauge From 3a2b049e80572e9ccd4f83730f397fd5712fd2d7 Mon Sep 17 00:00:00 2001 From: Gary Rong Date: Fri, 9 May 2025 18:44:27 +0800 Subject: [PATCH 3/3] core: fix compile --- core/blockchain_insert.go | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/core/blockchain_insert.go b/core/blockchain_insert.go index 6873afdbf432..43c9813a2127 100644 --- a/core/blockchain_insert.go +++ b/core/blockchain_insert.go @@ -43,10 +43,7 @@ func (st *insertStats) report(chain []*types.Block, index int, snapDiffItems, sn // Fetch the timings for the batch var ( now = mclock.Now() - elapsed = now.Sub(st.startTime) - if elapsed == 0 { // prevent zero division - elapsed = 1 - } + elapsed = now.Sub(st.startTime) + 1 // prevent zero division mgasps = float64(st.usedGas) * 1000 / float64(elapsed) ) // Update the Mgas per second gauge