forked from cerc-io/plugeth
eth, ethdb: measure database operation latencies too
This commit is contained in:
parent
0609fcf030
commit
803b3c4a82
@ -250,9 +250,9 @@ func New(config *Config) (*Ethereum, error) {
|
|||||||
return nil, fmt.Errorf("blockchain db err: %v", err)
|
return nil, fmt.Errorf("blockchain db err: %v", err)
|
||||||
}
|
}
|
||||||
if db, ok := blockDb.(*ethdb.LDBDatabase); ok {
|
if db, ok := blockDb.(*ethdb.LDBDatabase); ok {
|
||||||
db.GetMeter = metrics.GetOrRegisterMeter("eth/db/block/Gets", metrics.DefaultRegistry)
|
db.GetTimer = metrics.GetOrRegisterTimer("eth/db/block/Gets", metrics.DefaultRegistry)
|
||||||
db.PutMeter = metrics.GetOrRegisterMeter("eth/db/block/Puts", metrics.DefaultRegistry)
|
db.PutTimer = metrics.GetOrRegisterTimer("eth/db/block/Puts", metrics.DefaultRegistry)
|
||||||
db.DelMeter = metrics.GetOrRegisterMeter("eth/db/block/Dels", metrics.DefaultRegistry)
|
db.MissMeter = metrics.GetOrRegisterMeter("eth/db/block/Misses", metrics.DefaultRegistry)
|
||||||
db.ReadMeter = metrics.GetOrRegisterMeter("eth/db/block/Reads", metrics.DefaultRegistry)
|
db.ReadMeter = metrics.GetOrRegisterMeter("eth/db/block/Reads", metrics.DefaultRegistry)
|
||||||
db.WriteMeter = metrics.GetOrRegisterMeter("eth/db/block/Writes", metrics.DefaultRegistry)
|
db.WriteMeter = metrics.GetOrRegisterMeter("eth/db/block/Writes", metrics.DefaultRegistry)
|
||||||
}
|
}
|
||||||
@ -261,9 +261,9 @@ func New(config *Config) (*Ethereum, error) {
|
|||||||
return nil, fmt.Errorf("state db err: %v", err)
|
return nil, fmt.Errorf("state db err: %v", err)
|
||||||
}
|
}
|
||||||
if db, ok := stateDb.(*ethdb.LDBDatabase); ok {
|
if db, ok := stateDb.(*ethdb.LDBDatabase); ok {
|
||||||
db.GetMeter = metrics.GetOrRegisterMeter("eth/db/state/Gets", metrics.DefaultRegistry)
|
db.GetTimer = metrics.GetOrRegisterTimer("eth/db/state/Gets", metrics.DefaultRegistry)
|
||||||
db.PutMeter = metrics.GetOrRegisterMeter("eth/db/state/Puts", metrics.DefaultRegistry)
|
db.PutTimer = metrics.GetOrRegisterTimer("eth/db/state/Puts", metrics.DefaultRegistry)
|
||||||
db.DelMeter = metrics.GetOrRegisterMeter("eth/db/state/Dels", metrics.DefaultRegistry)
|
db.MissMeter = metrics.GetOrRegisterMeter("eth/db/state/Misses", metrics.DefaultRegistry)
|
||||||
db.ReadMeter = metrics.GetOrRegisterMeter("eth/db/state/Reads", metrics.DefaultRegistry)
|
db.ReadMeter = metrics.GetOrRegisterMeter("eth/db/state/Reads", metrics.DefaultRegistry)
|
||||||
db.WriteMeter = metrics.GetOrRegisterMeter("eth/db/state/Writes", metrics.DefaultRegistry)
|
db.WriteMeter = metrics.GetOrRegisterMeter("eth/db/state/Writes", metrics.DefaultRegistry)
|
||||||
}
|
}
|
||||||
@ -272,9 +272,9 @@ func New(config *Config) (*Ethereum, error) {
|
|||||||
return nil, fmt.Errorf("extra db err: %v", err)
|
return nil, fmt.Errorf("extra db err: %v", err)
|
||||||
}
|
}
|
||||||
if db, ok := extraDb.(*ethdb.LDBDatabase); ok {
|
if db, ok := extraDb.(*ethdb.LDBDatabase); ok {
|
||||||
db.GetMeter = metrics.GetOrRegisterMeter("eth/db/extra/Gets", metrics.DefaultRegistry)
|
db.GetTimer = metrics.GetOrRegisterTimer("eth/db/extra/Gets", metrics.DefaultRegistry)
|
||||||
db.PutMeter = metrics.GetOrRegisterMeter("eth/db/extra/Puts", metrics.DefaultRegistry)
|
db.PutTimer = metrics.GetOrRegisterTimer("eth/db/extra/Puts", metrics.DefaultRegistry)
|
||||||
db.DelMeter = metrics.GetOrRegisterMeter("eth/db/extra/Dels", metrics.DefaultRegistry)
|
db.MissMeter = metrics.GetOrRegisterMeter("eth/db/extra/Misses", metrics.DefaultRegistry)
|
||||||
db.ReadMeter = metrics.GetOrRegisterMeter("eth/db/extra/Reads", metrics.DefaultRegistry)
|
db.ReadMeter = metrics.GetOrRegisterMeter("eth/db/extra/Reads", metrics.DefaultRegistry)
|
||||||
db.WriteMeter = metrics.GetOrRegisterMeter("eth/db/extra/Writes", metrics.DefaultRegistry)
|
db.WriteMeter = metrics.GetOrRegisterMeter("eth/db/extra/Writes", metrics.DefaultRegistry)
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,8 @@
|
|||||||
package ethdb
|
package ethdb
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"time"
|
||||||
|
|
||||||
"github.com/ethereum/go-ethereum/compression/rle"
|
"github.com/ethereum/go-ethereum/compression/rle"
|
||||||
"github.com/ethereum/go-ethereum/logger"
|
"github.com/ethereum/go-ethereum/logger"
|
||||||
"github.com/ethereum/go-ethereum/logger/glog"
|
"github.com/ethereum/go-ethereum/logger/glog"
|
||||||
@ -17,9 +19,10 @@ type LDBDatabase struct {
|
|||||||
fn string // filename for reporting
|
fn string // filename for reporting
|
||||||
db *leveldb.DB // LevelDB instance
|
db *leveldb.DB // LevelDB instance
|
||||||
|
|
||||||
GetMeter metrics.Meter // Meter for measuring the database get request counts
|
GetTimer metrics.Timer // Timer for measuring the database get request counts and latencies
|
||||||
PutMeter metrics.Meter // Meter for measuring the database put request counts
|
PutTimer metrics.Timer // Timer for measuring the database put request counts and latencies
|
||||||
DelMeter metrics.Meter // Meter for measuring the database delete request counts
|
DelTimer metrics.Timer // Timer for measuring the database delete request counts and latencies
|
||||||
|
MissMeter metrics.Meter // MEter for measuring the missed database get requests
|
||||||
ReadMeter metrics.Meter // Meter for measuring the database get request data usage
|
ReadMeter metrics.Meter // Meter for measuring the database get request data usage
|
||||||
WriteMeter metrics.Meter // Meter for measuring the database put request data usage
|
WriteMeter metrics.Meter // Meter for measuring the database put request data usage
|
||||||
}
|
}
|
||||||
@ -48,10 +51,14 @@ func NewLDBDatabase(file string) (*LDBDatabase, error) {
|
|||||||
|
|
||||||
// Put puts the given key / value to the queue
|
// Put puts the given key / value to the queue
|
||||||
func (self *LDBDatabase) Put(key []byte, value []byte) error {
|
func (self *LDBDatabase) Put(key []byte, value []byte) error {
|
||||||
dat := rle.Compress(value)
|
// Measure the database put latency, if requested
|
||||||
if self.PutMeter != nil {
|
if self.PutTimer != nil {
|
||||||
self.PutMeter.Mark(1)
|
start := time.Now()
|
||||||
|
defer self.PutTimer.UpdateSince(start)
|
||||||
}
|
}
|
||||||
|
// Generate the data to write to disk, update the meter and write
|
||||||
|
dat := rle.Compress(value)
|
||||||
|
|
||||||
if self.WriteMeter != nil {
|
if self.WriteMeter != nil {
|
||||||
self.WriteMeter.Mark(int64(len(dat)))
|
self.WriteMeter.Mark(int64(len(dat)))
|
||||||
}
|
}
|
||||||
@ -60,13 +67,20 @@ func (self *LDBDatabase) Put(key []byte, value []byte) error {
|
|||||||
|
|
||||||
// Get returns the given key if it's present.
|
// Get returns the given key if it's present.
|
||||||
func (self *LDBDatabase) Get(key []byte) ([]byte, error) {
|
func (self *LDBDatabase) Get(key []byte) ([]byte, error) {
|
||||||
|
// Measure the database get latency, if requested
|
||||||
|
if self.GetTimer != nil {
|
||||||
|
start := time.Now()
|
||||||
|
defer self.GetTimer.UpdateSince(start)
|
||||||
|
}
|
||||||
|
// Retrieve the key and increment the miss counter if not found
|
||||||
dat, err := self.db.Get(key, nil)
|
dat, err := self.db.Get(key, nil)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
if self.MissMeter != nil {
|
||||||
|
self.MissMeter.Mark(1)
|
||||||
|
}
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
if self.GetMeter != nil {
|
// Otherwise update the actually retrieved amount of data
|
||||||
self.GetMeter.Mark(1)
|
|
||||||
}
|
|
||||||
if self.ReadMeter != nil {
|
if self.ReadMeter != nil {
|
||||||
self.ReadMeter.Mark(int64(len(dat)))
|
self.ReadMeter.Mark(int64(len(dat)))
|
||||||
}
|
}
|
||||||
@ -75,9 +89,12 @@ func (self *LDBDatabase) Get(key []byte) ([]byte, error) {
|
|||||||
|
|
||||||
// Delete deletes the key from the queue and database
|
// Delete deletes the key from the queue and database
|
||||||
func (self *LDBDatabase) Delete(key []byte) error {
|
func (self *LDBDatabase) Delete(key []byte) error {
|
||||||
if self.DelMeter != nil {
|
// Measure the database delete latency, if requested
|
||||||
self.DelMeter.Mark(1)
|
if self.DelTimer != nil {
|
||||||
|
start := time.Now()
|
||||||
|
defer self.DelTimer.UpdateSince(start)
|
||||||
}
|
}
|
||||||
|
// Execute the actual operation
|
||||||
return self.db.Delete(key, nil)
|
return self.db.Delete(key, nil)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user