forked from TrueCloudLab/frostfs-node
[#1464] frostfsid: Add cache metrics
Signed-off-by: Dmitrii Stepanov <d.stepanov@yadro.com>
This commit is contained in:
parent
48862e0e63
commit
e74d05c03f
2 changed files with 21 additions and 6 deletions
|
@ -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…
Add table
Add a link
Reference in a new issue