[#9999] frostfsid: Add cache metrics
Signed-off-by: Dmitrii Stepanov <d.stepanov@yadro.com>
This commit is contained in:
parent
87ac3c5279
commit
dd3b4a9b64
2 changed files with 21 additions and 6 deletions
|
@ -8,6 +8,7 @@ import (
|
|||
containerGRPC "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/container/grpc"
|
||||
morphconfig "git.frostfs.info/TrueCloudLab/frostfs-node/cmd/frostfs-node/config/morph"
|
||||
"git.frostfs.info/TrueCloudLab/frostfs-node/internal/logs"
|
||||
"git.frostfs.info/TrueCloudLab/frostfs-node/internal/metrics"
|
||||
containerCore "git.frostfs.info/TrueCloudLab/frostfs-node/pkg/core/container"
|
||||
frostfsidcore "git.frostfs.info/TrueCloudLab/frostfs-node/pkg/core/frostfsid"
|
||||
cntClient "git.frostfs.info/TrueCloudLab/frostfs-node/pkg/morph/client/container"
|
||||
|
@ -42,7 +43,7 @@ func initContainerService(_ context.Context, c *cfg) {
|
|||
|
||||
cacheSize := morphconfig.FrostfsIDCacheSize(c.appCfg)
|
||||
if cacheSize > 0 {
|
||||
frostfsIDSubjectProvider = newMorphFrostfsIDCache(frostfsIDSubjectProvider, int(cacheSize), c.cfgMorph.cacheTTL)
|
||||
frostfsIDSubjectProvider = newMorphFrostfsIDCache(frostfsIDSubjectProvider, int(cacheSize), c.cfgMorph.cacheTTL, metrics.NewCacheMetrics("frostfs_id"))
|
||||
}
|
||||
|
||||
c.shared.frostfsidClient = frostfsIDSubjectProvider
|
||||
|
|
|
@ -14,22 +14,29 @@ type morphFrostfsIDCache struct {
|
|||
|
||||
subjCache *expirable.LRU[util.Uint160, *client.Subject]
|
||||
|
||||
subjExtCache *expirable.LRU[util.Uint160, *client.SubjectExtended]
|
||||
metrics cacheMetrics
|
||||
}
|
||||
|
||||
func newMorphFrostfsIDCache(subjProvider frostfsidcore.SubjectProvider, size int, ttl time.Duration) frostfsidcore.SubjectProvider {
|
||||
func newMorphFrostfsIDCache(subjProvider frostfsidcore.SubjectProvider, size int, ttl time.Duration, metrics cacheMetrics) frostfsidcore.SubjectProvider {
|
||||
return &morphFrostfsIDCache{
|
||||
subjProvider: subjProvider,
|
||||
|
||||
subjCache: expirable.NewLRU(size, func(util.Uint160, *client.Subject) {}, ttl),
|
||||
|
||||
subjExtCache: expirable.NewLRU(size, func(util.Uint160, *client.SubjectExtended) {}, ttl),
|
||||
metrics: metrics,
|
||||
}
|
||||
}
|
||||
|
||||
func (m *morphFrostfsIDCache) GetSubject(addr util.Uint160) (*client.Subject, error) {
|
||||
hit := false
|
||||
startedAt := time.Now()
|
||||
defer func() {
|
||||
m.metrics.AddMethodDuration("GetSubject", time.Since(startedAt), hit)
|
||||
}()
|
||||
|
||||
result, found := m.subjCache.Get(addr)
|
||||
if found {
|
||||
hit = true
|
||||
return result, nil
|
||||
}
|
||||
|
||||
|
@ -43,9 +50,16 @@ func (m *morphFrostfsIDCache) GetSubject(addr util.Uint160) (*client.Subject, er
|
|||
}
|
||||
|
||||
func (m *morphFrostfsIDCache) GetSubjectExtended(addr util.Uint160) (*client.SubjectExtended, error) {
|
||||
subjExt, found := m.subjExtCache.Get(addr)
|
||||
hit := false
|
||||
startedAt := time.Now()
|
||||
defer func() {
|
||||
m.metrics.AddMethodDuration("GetSubjectExtended", time.Since(startedAt), hit)
|
||||
}()
|
||||
|
||||
result, found := m.subjExtCache.Get(addr)
|
||||
if found {
|
||||
return subjExt, nil
|
||||
hit = true
|
||||
return result, nil
|
||||
}
|
||||
|
||||
var err error
|
||||
|
|
Loading…
Reference in a new issue