From 20c3d1dafe377515b61874c200597d1f4bbd9ae0 Mon Sep 17 00:00:00 2001 From: Egor Lysenko Date: Sat, 14 Oct 2023 15:02:25 +0400 Subject: [PATCH 1/2] slow down polling DB size --- cmd/opera/launcher/metrics/metrics.go | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/cmd/opera/launcher/metrics/metrics.go b/cmd/opera/launcher/metrics/metrics.go index edc74a873..7daa7829a 100644 --- a/cmd/opera/launcher/metrics/metrics.go +++ b/cmd/opera/launcher/metrics/metrics.go @@ -26,10 +26,10 @@ func measureDbDir(name, datadir string) { rescan = (len(datadir) > 0 && datadir != "inmemory") ) for { - time.Sleep(time.Second) + time.Sleep(10 * time.Second) if rescan { - size := sizeOfDir(datadir) + size := sizeOfDir(datadir, new(int)) atomic.StoreInt64(&dbSize, size) } @@ -45,8 +45,12 @@ func measureDbDir(name, datadir string) { } } -func sizeOfDir(dir string) (size int64) { +func sizeOfDir(dir string, counter *int) (size int64) { err := filepath.Walk(dir, func(path string, info os.FileInfo, err error) error { + *counter++ + if *counter % 100 == 0 { + time.Sleep(100 * time.Millisecond) + } if err != nil { log.Debug("datadir walk", "path", path, "err", err) return filepath.SkipDir @@ -58,7 +62,7 @@ func sizeOfDir(dir string) (size int64) { dst, err := filepath.EvalSymlinks(path) if err == nil && dst != path { - size += sizeOfDir(dst) + size += sizeOfDir(dst, counter) } else { size += info.Size() } From 406dc202b2c57fa91e991b3d8be1fdc2dde46558 Mon Sep 17 00:00:00 2001 From: Egor Lysenko Date: Sat, 14 Oct 2023 15:30:16 +0400 Subject: [PATCH 2/2] db_size metric is calculation only when metric.Enabled --- cmd/opera/launcher/launcher.go | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/cmd/opera/launcher/launcher.go b/cmd/opera/launcher/launcher.go index c81100659..5cf6d0d4a 100644 --- a/cmd/opera/launcher/launcher.go +++ b/cmd/opera/launcher/launcher.go @@ -14,6 +14,7 @@ import ( "github.com/ethereum/go-ethereum/console/prompt" "github.com/ethereum/go-ethereum/ethclient" "github.com/ethereum/go-ethereum/log" + gmetrics "github.com/ethereum/go-ethereum/metrics" "github.com/ethereum/go-ethereum/node" "github.com/ethereum/go-ethereum/p2p/discover/discfilter" "github.com/ethereum/go-ethereum/params" @@ -299,7 +300,10 @@ func makeNode(ctx *cli.Context, cfg *config, genesisStore *genesisstore.Store) ( if genesisStore != nil { _ = genesisStore.Close() } - metrics.SetDataDir(cfg.Node.DataDir) + + if gmetrics.Enabled { + metrics.SetDataDir(cfg.Node.DataDir) + } memorizeDBPreset(cfg) // substitute default bootnodes if requested