From 64dc65b6661d221b01b22d427b74d2eff49164b8 Mon Sep 17 00:00:00 2001 From: Marina Biryukova Date: Wed, 31 Jul 2024 14:55:03 +0300 Subject: [PATCH] Add intermediate metrics Signed-off-by: Marina Biryukova --- pool/pool.go | 1 + pool/statistic.go | 100 ++++++++++++++++++++++++++++++++++++++--- pool/tree/pool.go | 1 + pool/tree/statistic.go | 32 +++++++++++++ 4 files changed, 128 insertions(+), 6 deletions(-) diff --git a/pool/pool.go b/pool/pool.go index 8cfda26..9ebc7b8 100644 --- a/pool/pool.go +++ b/pool/pool.go @@ -1155,6 +1155,7 @@ func (c *clientStatusMonitor) methodsStatus() []StatusSnapshot { result := make([]StatusSnapshot, len(c.methods)) for i, val := range c.methods { result[i] = val.Snapshot() + val.ClearInterData() } return result diff --git a/pool/statistic.go b/pool/statistic.go index 6606206..6d7c28b 100644 --- a/pool/statistic.go +++ b/pool/statistic.go @@ -152,6 +152,66 @@ func (n NodeStatistic) AverageCreateSession() time.Duration { return n.averageTime(methodSessionCreate) } +func (n NodeStatistic) InterAverageGetBalance() time.Duration { + return n.interAverageTime(methodBalanceGet) +} + +func (n NodeStatistic) InterAveragePutContainer() time.Duration { + return n.interAverageTime(methodContainerPut) +} + +func (n NodeStatistic) InterAverageGetContainer() time.Duration { + return n.interAverageTime(methodContainerGet) +} + +func (n NodeStatistic) InterAverageListContainer() time.Duration { + return n.interAverageTime(methodContainerList) +} + +func (n NodeStatistic) InterAverageDeleteContainer() time.Duration { + return n.interAverageTime(methodContainerDelete) +} + +func (n NodeStatistic) InterAverageGetContainerEACL() time.Duration { + return n.interAverageTime(methodContainerEACL) +} + +func (n NodeStatistic) InterAverageSetContainerEACL() time.Duration { + return n.interAverageTime(methodContainerSetEACL) +} + +func (n NodeStatistic) InterAverageEndpointInfo() time.Duration { + return n.interAverageTime(methodEndpointInfo) +} + +func (n NodeStatistic) InterAverageNetworkInfo() time.Duration { + return n.interAverageTime(methodNetworkInfo) +} + +func (n NodeStatistic) InterAveragePutObject() time.Duration { + return n.interAverageTime(methodObjectPut) +} + +func (n NodeStatistic) InterAverageDeleteObject() time.Duration { + return n.interAverageTime(methodObjectDelete) +} + +func (n NodeStatistic) InterAverageGetObject() time.Duration { + return n.interAverageTime(methodObjectGet) +} + +func (n NodeStatistic) InterAverageHeadObject() time.Duration { + return n.interAverageTime(methodObjectHead) +} + +func (n NodeStatistic) InterAverageRangeObject() time.Duration { + return n.interAverageTime(methodObjectRange) +} + +func (n NodeStatistic) InterAverageCreateSession() time.Duration { + return n.interAverageTime(methodSessionCreate) +} + func (n NodeStatistic) averageTime(method MethodIndex) time.Duration { stat := n.methods[method] if stat.allRequests == 0 { @@ -160,11 +220,19 @@ func (n NodeStatistic) averageTime(method MethodIndex) time.Duration { return time.Duration(stat.allTime / stat.allRequests) } +func (n NodeStatistic) interAverageTime(method MethodIndex) time.Duration { + stat := n.methods[method] + if stat.interRequests == 0 { + return 0 + } + return time.Duration(stat.interTime / stat.interRequests) +} + // MethodStatus provide statistic for specific method. type MethodStatus struct { - name string - mu sync.RWMutex // protect counters - StatusSnapshot + name string + mu sync.RWMutex // protect counters + snapshot StatusSnapshot } func NewMethodStatus(name string) *MethodStatus { @@ -174,20 +242,32 @@ func NewMethodStatus(name string) *MethodStatus { func (m *MethodStatus) Snapshot() StatusSnapshot { m.mu.RLock() defer m.mu.RUnlock() - return m.StatusSnapshot + return m.snapshot +} + +func (m *MethodStatus) ClearInterData() { + m.mu.Lock() + defer m.mu.Unlock() + m.snapshot.interTime = 0 + m.snapshot.interRequests = 0 } func (m *MethodStatus) IncRequests(elapsed time.Duration) { m.mu.Lock() defer m.mu.Unlock() - m.allTime += uint64(elapsed) - m.allRequests++ + m.snapshot.allTime += uint64(elapsed) + m.snapshot.interTime += uint64(elapsed) + m.snapshot.allRequests++ + m.snapshot.interRequests++ } // StatusSnapshot is statistic for specific method. type StatusSnapshot struct { allTime uint64 allRequests uint64 + + interTime uint64 + interRequests uint64 } func (s StatusSnapshot) AllRequests() uint64 { @@ -197,3 +277,11 @@ func (s StatusSnapshot) AllRequests() uint64 { func (s StatusSnapshot) AllTime() uint64 { return s.allTime } + +func (s StatusSnapshot) InterRequests() uint64 { + return s.interRequests +} + +func (s StatusSnapshot) InterTime() uint64 { + return s.interTime +} diff --git a/pool/tree/pool.go b/pool/tree/pool.go index 8b3640d..131357f 100644 --- a/pool/tree/pool.go +++ b/pool/tree/pool.go @@ -631,6 +631,7 @@ func (p *Pool) Statistic() Statistic { for i, method := range p.methods { stat.methods[i] = method.Snapshot() + method.ClearInterData() } return stat diff --git a/pool/tree/statistic.go b/pool/tree/statistic.go index 9f565fa..37cc4d5 100644 --- a/pool/tree/statistic.go +++ b/pool/tree/statistic.go @@ -42,6 +42,30 @@ func (s *Statistic) AverageRemoveNode() time.Duration { return s.averageTime(methodRemoveNode) } +func (s *Statistic) InterAverageGetNodes() time.Duration { + return s.interAverageTime(methodGetNodes) +} + +func (s *Statistic) InterAverageGetSubTree() time.Duration { + return s.interAverageTime(methodGetSubTree) +} + +func (s *Statistic) InterAverageAddNode() time.Duration { + return s.interAverageTime(methodAddNode) +} + +func (s *Statistic) InterAverageAddNodeByPath() time.Duration { + return s.interAverageTime(methodAddNodeByPath) +} + +func (s *Statistic) InterAverageMoveNode() time.Duration { + return s.interAverageTime(methodMoveNode) +} + +func (s *Statistic) InterAverageRemoveNode() time.Duration { + return s.interAverageTime(methodRemoveNode) +} + func (s *Statistic) averageTime(method MethodIndex) time.Duration { stat := s.methods[method] if stat.AllRequests() == 0 { @@ -49,3 +73,11 @@ func (s *Statistic) averageTime(method MethodIndex) time.Duration { } return time.Duration(stat.AllTime() / stat.AllRequests()) } + +func (s *Statistic) interAverageTime(method MethodIndex) time.Duration { + stat := s.methods[method] + if stat.InterRequests() == 0 { + return 0 + } + return time.Duration(stat.InterTime() / stat.InterRequests()) +}