Skip to content
This repository has been archived by the owner on May 21, 2024. It is now read-only.

Commit

Permalink
trie: track dirty cache metrics, track clean writes on commit
Browse files Browse the repository at this point in the history
  • Loading branch information
karalabe authored and elizabethengelman committed Dec 20, 2019
1 parent d05cf37 commit f08a025
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions trie/database.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,11 @@ var (
memcacheCleanReadMeter = metrics.NewRegisteredMeter("trie/memcache/clean/read", nil)
memcacheCleanWriteMeter = metrics.NewRegisteredMeter("trie/memcache/clean/write", nil)

memcacheDirtyHitMeter = metrics.NewRegisteredMeter("trie/memcache/dirty/hit", nil)
memcacheDirtyMissMeter = metrics.NewRegisteredMeter("trie/memcache/dirty/miss", nil)
memcacheDirtyReadMeter = metrics.NewRegisteredMeter("trie/memcache/dirty/read", nil)
memcacheDirtyWriteMeter = metrics.NewRegisteredMeter("trie/memcache/dirty/write", nil)

memcacheFlushTimeTimer = metrics.NewRegisteredResettingTimer("trie/memcache/flush/time", nil)
memcacheFlushNodesMeter = metrics.NewRegisteredMeter("trie/memcache/flush/nodes", nil)
memcacheFlushSizeMeter = metrics.NewRegisteredMeter("trie/memcache/flush/size", nil)
Expand Down Expand Up @@ -321,6 +326,8 @@ func (db *Database) insert(hash common.Hash, blob []byte, node node) {
if _, ok := db.dirties[hash]; ok {
return
}
memcacheDirtyWriteMeter.Mark(int64(len(blob)))

// Create the cached entry for this node
entry := &cachedNode{
node: simplifyNode(node),
Expand Down Expand Up @@ -372,8 +379,12 @@ func (db *Database) node(hash common.Hash) node {
db.lock.RUnlock()

if dirty != nil {
memcacheDirtyHitMeter.Mark(1)
memcacheDirtyReadMeter.Mark(int64(dirty.size))
return dirty.obj(hash)
}
memcacheDirtyMissMeter.Mark(1)

// Content unavailable in memory, attempt to retrieve from disk
enc, err := db.diskdb.Get(hash[:])
if err != nil || enc == nil {
Expand Down Expand Up @@ -408,8 +419,12 @@ func (db *Database) Node(hash common.Hash) ([]byte, error) {
db.lock.RUnlock()

if dirty != nil {
memcacheDirtyHitMeter.Mark(1)
memcacheDirtyReadMeter.Mark(int64(dirty.size))
return dirty.rlp(), nil
}
memcacheDirtyMissMeter.Mark(1)

// Content unavailable in memory, attempt to retrieve from disk
enc, err := db.diskdb.Get(hash[:])
if err == nil && enc != nil {
Expand Down Expand Up @@ -812,6 +827,7 @@ func (c *cleaner) Put(key []byte, rlp []byte) error {
// Move the flushed node into the clean cache to prevent insta-reloads
if c.db.cleans != nil {
c.db.cleans.Set(hash[:], rlp)
memcacheCleanWriteMeter.Mark(int64(len(rlp)))
}
return nil
}
Expand Down

0 comments on commit f08a025

Please sign in to comment.