Skip to content

core,triedb: add fastcache metrics #31883

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

Open
wants to merge 5 commits into
base: master
Choose a base branch
from

Conversation

jsvisa
Copy link
Contributor

@jsvisa jsvisa commented May 23, 2025

Add more metrics about the fastcache, so the users have a clear understanding of the use of cache and know how to configure the size of each cache.

I'm running with

geth 
--cache=6144 # 6GB
--cache.database=20 # 20%
--cache.snapshot=20 # 20%
--cache.gc=5        # 5%
--cache.trie=40     # 40%

This is the metrics in grafana dashboard:

image

I can see that the disk layer cache(--cache.snapshot) is not used much, given 6*0.2=1.2GB, but only 30% was in use; and for the trie cache(--cache.trie) is fully used, so in my case, I now know I need to reduce the cache used for snapshot, and increase it for trie.

jsvisa added 4 commits May 23, 2025 11:00
Signed-off-by: jsvisa <delweng@gmail.com>
Signed-off-by: jsvisa <delweng@gmail.com>
Signed-off-by: jsvisa <delweng@gmail.com>
Signed-off-by: jsvisa <delweng@gmail.com>
@jsvisa jsvisa requested a review from rjl493456442 as a code owner May 23, 2025 04:06
Signed-off-by: jsvisa <delweng@gmail.com>
@rjl493456442 rjl493456442 self-assigned this May 25, 2025
@@ -379,6 +388,20 @@ func (t *Tree) Cap(root common.Hash, layers int) error {
if !ok {
return fmt.Errorf("snapshot [%#x] is disk layer", root)
}

// Update the cache stats
if diff.origin != nil && diff.origin.cache != nil {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's very weird to upload the cache stats here.

The associated disk layer will only be modified if the size bottom-most diff layer reaches the threshold, it's not always be updated...

if diff.origin != nil && diff.origin.cache != nil {
var stats fastcache.Stats
diff.origin.cache.UpdateStats(&stats)
snapshotCacheGetGauge.Update(int64(stats.GetCalls))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we already have the similar metrics

	snapshotCleanStorageHitMeter   = metrics.NewRegisteredMeter("state/snapshot/clean/storage/hit", nil)
	snapshotCleanStorageMissMeter  = metrics.NewRegisteredMeter("state/snapshot/clean/storage/miss", nil)
	snapshotCleanStorageInexMeter  = metrics.NewRegisteredMeter("state/snapshot/clean/storage/inex", nil)
	snapshotCleanStorageReadMeter  = metrics.NewRegisteredMeter("state/snapshot/clean/storage/read", nil)
	snapshotCleanStorageWriteMeter = metrics.NewRegisteredMeter("state/snapshot/clean/storage/write", nil)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's probably unnecessary to add more duplicated ones.

@fjl
Copy link
Contributor

fjl commented May 27, 2025

It seems a bit useless to graph the total usage of the cache, since it will always be full by definition. We do not evict items from the cache manually, so the cache will fill up and then stay at the configured limit. The more interesting metric is the hit/miss rate but we already have a metric for that.

@fjl fjl closed this May 27, 2025
@fjl fjl reopened this May 27, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants