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

Add metrics to the roundstate_db #2040

Closed
wants to merge 3 commits into from
Closed
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
23 changes: 19 additions & 4 deletions consensus/istanbul/core/roundstate_db.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import (
"github.com/celo-org/celo-blockchain/common/task"
"github.com/celo-org/celo-blockchain/consensus/istanbul"
"github.com/celo-org/celo-blockchain/log"
"github.com/celo-org/celo-blockchain/metrics"
"github.com/celo-org/celo-blockchain/rlp"
"github.com/syndtr/goleveldb/leveldb"
lvlerrors "github.com/syndtr/goleveldb/leveldb/errors"
Expand Down Expand Up @@ -66,7 +67,11 @@ type roundStateDBImpl struct {
db *leveldb.DB
stopGarbageCollector task.StopFn
opts RoundStateDBOptions
logger log.Logger

roundStateRLPMeter metrics.Meter
rlpTimer metrics.Timer
dbSaveTimer metrics.Timer
logger log.Logger
}

var defaultRoundStateDBOptions = RoundStateDBOptions{
Expand Down Expand Up @@ -108,9 +113,12 @@ func newRoundStateDB(path string, opts *RoundStateDBOptions) (RoundStateDB, erro
}

rsdb := &roundStateDBImpl{
db: db,
opts: coerceOptions(opts),
logger: logger,
db: db,
opts: coerceOptions(opts),
roundStateRLPMeter: metrics.NewRegisteredMeter("consensus/istanbul/core/roundstate/rlp/size", nil),
rlpTimer: metrics.NewRegisteredTimer("consensus/istanbul/core/roundstate/rlp/time", nil),
dbSaveTimer: metrics.NewRegisteredTimer("consensus/istanbul/core/roundstate/db/save/time", nil),
logger: logger,
}

if rsdb.opts.withGarbageCollector {
Expand Down Expand Up @@ -283,12 +291,18 @@ func (rsdb *roundStateDBImpl) UpdateLastRoundState(rs RoundState) error {
logger := rsdb.logger.New("func", "UpdateLastRoundState")
viewKey := view2Key(rs.View())

// Encode and measure time
before := time.Now()
entryBytes, err := rlp.EncodeToBytes(rs)
rsdb.rlpTimer.UpdateSince(before)

if err != nil {
logger.Error("Failed to save roundState", "reason", "rlp encoding", "err", err)
return err
}
rsdb.roundStateRLPMeter.Mark(int64(len(entryBytes)))

before = time.Now()
batch := new(leveldb.Batch)
batch.Put([]byte(lastViewKey), viewKey)
batch.Put(viewKey, entryBytes)
Expand All @@ -297,6 +311,7 @@ func (rsdb *roundStateDBImpl) UpdateLastRoundState(rs RoundState) error {
if err != nil {
logger.Error("Failed to save roundState", "reason", "levelDB write", "err", err, "func")
}
rsdb.dbSaveTimer.UpdateSince(before)

return err
}
Expand Down
Loading