satellite/{audit,metrics}: optimize loop methods
What was applied: * avoid extra map lookups * reorganize monikit for less cpu usage Change-Id: I70575f404f717f7905b27d43888cbd7489f0176d
This commit is contained in:
parent
a3c9ca653f
commit
307295977d
@ -11,6 +11,8 @@ import (
|
||||
"storj.io/storj/satellite/metabase/segmentloop"
|
||||
)
|
||||
|
||||
var remoteSegmentFunc = mon.Func()
|
||||
|
||||
var _ segmentloop.Observer = (*Collector)(nil)
|
||||
|
||||
// Collector uses the segment loop to add segments to node reservoirs.
|
||||
@ -35,14 +37,16 @@ func (collector *Collector) LoopStarted(context.Context, segmentloop.LoopInfo) (
|
||||
}
|
||||
|
||||
// RemoteSegment takes a remote segment found in metainfo and creates a reservoir for it if it doesn't exist already.
|
||||
func (collector *Collector) RemoteSegment(ctx context.Context, segment *segmentloop.Segment) (err error) {
|
||||
defer mon.Task()(&ctx)(&err)
|
||||
func (collector *Collector) RemoteSegment(ctx context.Context, segment *segmentloop.Segment) error {
|
||||
defer remoteSegmentFunc.Task(&ctx)(nil) // method always returns nil
|
||||
|
||||
for _, piece := range segment.Pieces {
|
||||
if _, ok := collector.Reservoirs[piece.StorageNode]; !ok {
|
||||
collector.Reservoirs[piece.StorageNode] = NewReservoir(collector.slotCount)
|
||||
res, ok := collector.Reservoirs[piece.StorageNode]
|
||||
if !ok {
|
||||
res = NewReservoir(collector.slotCount)
|
||||
collector.Reservoirs[piece.StorageNode] = res
|
||||
}
|
||||
collector.Reservoirs[piece.StorageNode].Sample(collector.rand, NewSegment(segment))
|
||||
res.Sample(collector.rand, NewSegment(segment))
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
@ -10,6 +10,11 @@ import (
|
||||
"storj.io/storj/satellite/metabase/segmentloop"
|
||||
)
|
||||
|
||||
var (
|
||||
remoteSegmentFunc = mon.Func()
|
||||
inlineSegmentFunc = mon.Func()
|
||||
)
|
||||
|
||||
// Counter implements the segment loop observer interface for data science metrics collection.
|
||||
//
|
||||
// architecture: Observer
|
||||
@ -44,8 +49,8 @@ func (counter *Counter) LoopStarted(context.Context, segmentloop.LoopInfo) (err
|
||||
}
|
||||
|
||||
// RemoteSegment increments the count for objects with remote segments.
|
||||
func (counter *Counter) RemoteSegment(ctx context.Context, segment *segmentloop.Segment) (err error) {
|
||||
defer mon.Task()(&ctx)(&err)
|
||||
func (counter *Counter) RemoteSegment(ctx context.Context, segment *segmentloop.Segment) error {
|
||||
defer remoteSegmentFunc.Task(&ctx)(nil) // method always returns nil
|
||||
|
||||
counter.onlyInline = false
|
||||
|
||||
@ -62,8 +67,8 @@ func (counter *Counter) RemoteSegment(ctx context.Context, segment *segmentloop.
|
||||
}
|
||||
|
||||
// InlineSegment increments the count for inline objects.
|
||||
func (counter *Counter) InlineSegment(ctx context.Context, segment *segmentloop.Segment) (err error) {
|
||||
defer mon.Task()(&ctx)(&err)
|
||||
func (counter *Counter) InlineSegment(ctx context.Context, segment *segmentloop.Segment) error {
|
||||
defer inlineSegmentFunc.Task(&ctx)(nil) // method always returns nil
|
||||
|
||||
counter.TotalInlineBytes += int64(segment.EncryptedSize)
|
||||
counter.TotalInlineSegments++
|
||||
|
Loading…
Reference in New Issue
Block a user