Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Metrics (Batch writes performance): Bytes written per bulk + duration #937

Open
wants to merge 4 commits into
base: release/maindbv4
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 14 additions & 6 deletions muxdb/engine/leveldb.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@ package engine
import (
"context"
"sync"
"time"

"github.com/ethereum/go-ethereum/common/mclock"
"github.com/syndtr/goleveldb/leveldb"
"github.com/syndtr/goleveldb/leveldb/opt"
"github.com/syndtr/goleveldb/leveldb/util"
Expand Down Expand Up @@ -112,14 +114,20 @@ func (ldb *levelEngine) Bulk() kv.Bulk {
return batch
}
flush := func(minSize int) error {
if batch != nil && len(batch.Dump()) >= minSize {
if batch.Len() > 0 {
if err := ldb.db.Write(batch, &writeOpt); err != nil {
return err
if batch != nil {
if batchBytesNo := len(batch.Dump()); batchBytesNo >= minSize {
if batch.Len() > 0 {
startTime := mclock.Now()
if err := ldb.db.Write(batch, &writeOpt); err != nil {
return err
}
metricBatchWriteBytes().Set(int64(batchBytesNo))
batchWriteElapsed := mclock.Now() - startTime
metricBatchWriteDuration().Observe(time.Duration(batchWriteElapsed).Milliseconds())
}
ldb.batchPool.Put(batch)
batch = nil
}
ldb.batchPool.Put(batch)
batch = nil
}
return nil
}
Expand Down
17 changes: 17 additions & 0 deletions muxdb/engine/metrics.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
// Copyright (c) 2024 The VeChainThor developers

// Distributed under the GNU Lesser General Public License v3.0 software license, see the accompanying
// file LICENSE or <https://www.gnu.org/licenses/lgpl-3.0.html>

// Package muxdb implements the storage layer for block-chain.
// It manages instance of merkle-patricia-trie, and general purpose named kv-store.
package engine

import (
"github.com/vechain/thor/v2/metrics"
)

var (
metricBatchWriteBytes = metrics.LazyLoadGauge("batch_write_bytes")
metricBatchWriteDuration = metrics.LazyLoadHistogram("batch_write_duration_ms", metrics.Bucket10s)
)
Loading