mirror of
https://github.com/prometheus/prometheus
synced 2025-02-03 13:43:24 +00:00
Minor optimization for BufferedSeriesIterator: actually drop the samples falling outside of the new delta from the underlying sampleRing, when ReduceDelta is called. (#4849)
Signed-off-by: Alin Sinpalean <alin.sinpalean@gmail.com>
This commit is contained in:
parent
d6adfe2ae2
commit
44bec482fb
@ -59,11 +59,7 @@ func (b *BufferedSeriesIterator) Reset(it SeriesIterator) {
|
|||||||
|
|
||||||
// ReduceDelta lowers the buffered time delta, for the current SeriesIterator only.
|
// ReduceDelta lowers the buffered time delta, for the current SeriesIterator only.
|
||||||
func (b *BufferedSeriesIterator) ReduceDelta(delta int64) bool {
|
func (b *BufferedSeriesIterator) ReduceDelta(delta int64) bool {
|
||||||
if delta > b.buf.delta {
|
return b.buf.reduceDelta(delta)
|
||||||
return false
|
|
||||||
}
|
|
||||||
b.buf.delta = delta
|
|
||||||
return true
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// PeekBack returns the nth previous element of the iterator. If there is none buffered,
|
// PeekBack returns the nth previous element of the iterator. If there is none buffered,
|
||||||
@ -222,7 +218,8 @@ func (r *sampleRing) add(t int64, v float64) {
|
|||||||
r.l++
|
r.l++
|
||||||
|
|
||||||
// Free head of the buffer of samples that just fell out of the range.
|
// Free head of the buffer of samples that just fell out of the range.
|
||||||
for r.buf[r.f].t < t-r.delta {
|
tmin := t - r.delta
|
||||||
|
for r.buf[r.f].t < tmin {
|
||||||
r.f++
|
r.f++
|
||||||
if r.f >= l {
|
if r.f >= l {
|
||||||
r.f -= l
|
r.f -= l
|
||||||
@ -231,6 +228,31 @@ func (r *sampleRing) add(t int64, v float64) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// reduceDelta lowers the buffered time delta, dropping any samples that are
|
||||||
|
// out of the new delta range.
|
||||||
|
func (r *sampleRing) reduceDelta(delta int64) bool {
|
||||||
|
if delta > r.delta {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
r.delta = delta
|
||||||
|
|
||||||
|
if r.l == 0 {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
|
// Free head of the buffer of samples that just fell out of the range.
|
||||||
|
l := len(r.buf)
|
||||||
|
tmin := r.buf[r.i].t - delta
|
||||||
|
for r.buf[r.f].t < tmin {
|
||||||
|
r.f++
|
||||||
|
if r.f >= l {
|
||||||
|
r.f -= l
|
||||||
|
}
|
||||||
|
r.l--
|
||||||
|
}
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
// nthLast returns the nth most recent element added to the ring.
|
// nthLast returns the nth most recent element added to the ring.
|
||||||
func (r *sampleRing) nthLast(n int) (int64, float64, bool) {
|
func (r *sampleRing) nthLast(n int) (int64, float64, bool) {
|
||||||
if n > r.l {
|
if n > r.l {
|
||||||
|
Loading…
Reference in New Issue
Block a user