-
Notifications
You must be signed in to change notification settings - Fork 83
storage,logicalplan: lazy iterator allocation with batching for range… #721
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -34,6 +34,7 @@ type matrixScanner struct { | |
|
|
||
| buffer ringbuffer.Buffer | ||
| iterator chunkenc.Iterator | ||
| rawSeries SignedSeries | ||
| lastSample ringbuffer.Sample | ||
| } | ||
|
|
||
|
|
@@ -171,6 +172,17 @@ func (o *matrixSelector) Next(ctx context.Context, buf []model.StepVector) (int, | |
| ts = o.currentStep | ||
| firstSeries := o.currentSeries | ||
| batchSamplesDelta := 0 | ||
|
|
||
| lastInBatch := min(firstSeries+o.seriesBatchSize, int64(len(o.scanners))) | ||
| // Initialize iterators lazily per-batch. | ||
| // TODO: reuse the iterator created for the previous scanner. | ||
| for i := firstSeries; i < lastInBatch; i++ { | ||
| if o.scanners[i].iterator == nil { | ||
| o.scanners[i].iterator = o.scanners[i].rawSeries.Iterator(nil) | ||
| o.scanners[i].buffer = o.newBuffer(ctx) | ||
| } | ||
| } | ||
|
|
||
| for ; o.currentSeries-firstSeries < o.seriesBatchSize && o.currentSeries < int64(len(o.scanners)); o.currentSeries++ { | ||
| var ( | ||
| scanner = &o.scanners[o.currentSeries] | ||
|
|
@@ -217,6 +229,7 @@ func (o *matrixSelector) Next(ctx context.Context, buf []model.StepVector) (int, | |
|
|
||
| if o.opts.IsInstantQuery() { | ||
| scanner.buffer.Reset(math.MaxInt64, 0) | ||
| scanner.iterator = nil | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. One further improvement. If we want to reduce allocation further, we don't have to eagerly allocate the iterator upfront. Can reuse the iterator created for the previous scanner. Need to be careful if it works for us.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks. Added the TODO. |
||
| batchSamplesDelta -= sampleCountAfter | ||
| } | ||
|
|
||
|
|
@@ -268,9 +281,8 @@ func (o *matrixSelector) loadSeries(ctx context.Context) error { | |
| labels: lbls, | ||
| metricName: origLbls.Get(labels.MetricName), | ||
| signature: s.Signature, | ||
| iterator: s.Iterator(nil), | ||
| rawSeries: s, | ||
| lastSample: ringbuffer.Sample{T: math.MinInt64}, | ||
| buffer: o.newBuffer(ctx), | ||
| } | ||
| o.series[i] = lbls | ||
| } | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.