Add metrics for morph caches #371

Closed
opened 2023-05-18 10:34:53 +00:00 by fyrchik · 2 comments
Owner

We cache many things that are taken from the blockchain.

  1. Hit/miss metric.
  2. Execution time on misses.
We cache many things that are taken from the blockchain. 1. Hit/miss metric. 2. Execution time on misses.
fyrchik added this to the v0.38.0 milestone 2023-05-18 10:34:53 +00:00
fyrchik added the
frostfs-node
good first issue
observability
labels 2023-05-18 10:34:53 +00:00
aarifullin was assigned by fyrchik 2023-05-24 08:46:12 +00:00
Member

@fyrchik suggested to add metrics for these caches trying to somehow generelize cache metric interface.

I suppose this would look like that:

type CacheMetrics interface {
 AddGetCacheValue(success bool, d time.Duration)
 AddRemoveCacheKey(success bool, d time.Duration)
 AddSetCacheKeyValue(success bool, d time.Duration)
}

and each cache struct must have embedded CacheMetrics implementation, like that:

type ttlNetCache[K comparable, V any] struct {
	/*...*/
 cache *lru.Cache[K, *valueWithTime[V]]
	/*...*/
 metrics *ttlNetCacheMetrics
}

type lruNetmapSource struct {
 netState netmap.State

 cache *lruNetCache
    
 metrics *lruNetmapSourceMetrics
}

This also can be composited within WriteCacheMetrics

But this barely can be used for MorphClientCache, because its cache cannot explicitly implement CacheMetrics - cache is composed from three different caches and without refactoring the implementation will be like this anyway.

So, I suggest to introduce generalized CacheMetrics interface in the next issue and use it for ttlNetCache, lruNetmapSource and writeCacheMetrics and to keep metrics implementation for morphClientCache like in the PR

@fyrchik [suggested](https://git.frostfs.info/TrueCloudLab/frostfs-node/pulls/400#issuecomment-11324) to add metrics for [these](https://git.frostfs.info/TrueCloudLab/frostfs-node/src/branch/master/cmd/frostfs-node/cache.go) caches trying to somehow generelize cache metric interface. I suppose this would look like that: ``` type CacheMetrics interface { AddGetCacheValue(success bool, d time.Duration) AddRemoveCacheKey(success bool, d time.Duration) AddSetCacheKeyValue(success bool, d time.Duration) } ``` and each cache struct must have embedded `CacheMetrics` implementation, like that: ``` type ttlNetCache[K comparable, V any] struct { /*...*/ cache *lru.Cache[K, *valueWithTime[V]] /*...*/ metrics *ttlNetCacheMetrics } type lruNetmapSource struct { netState netmap.State cache *lruNetCache metrics *lruNetmapSourceMetrics } ``` This also can be composited within [WriteCacheMetrics](https://git.frostfs.info/TrueCloudLab/frostfs-node/src/branch/master/pkg/metrics/writecache.go#L24) But this barely can be used for [MorphClientCache](https://git.frostfs.info/TrueCloudLab/frostfs-node/src/branch/master/pkg/morph/client/client.go#L88), because its `cache` cannot explicitly implement `CacheMetrics` - `cache` is composed from three different caches and without refactoring the implementation will be like [this](https://git.frostfs.info/TrueCloudLab/frostfs-node/pulls/400/files) anyway. So, I suggest to introduce generalized `CacheMetrics` interface in the next issue and use it for `ttlNetCache`, `lruNetmapSource` and `writeCacheMetrics` and to keep metrics implementation for `morphClientCache` like in the PR
Member

The issue #451 for frostfs-node caches

[The issue #451](https://git.frostfs.info/TrueCloudLab/frostfs-node/issues/451) for frostfs-node caches
Sign in to join this conversation.
No milestone
No project
No assignees
2 participants
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference: TrueCloudLab/frostfs-node#371
No description provided.