mirror of
https://github.com/prometheus/prometheus.git
synced 2025-03-05 20:59:13 -08:00
Prevent Prometheus from overallocating memory on subquery with large amount of steps. (#12734)
* change initial points slice size Signed-off-by: Alan Protasio <alanprot@gmail.com> * refactor on the steps calculation and moving the getXPoint/putXPoint method to the evaluator Signed-off-by: Alan Protasio <alanprot@gmail.com> * prevent potential panic Signed-off-by: Alan Protasio <alanprot@gmail.com> * Update promql/engine.go Co-authored-by: Bartlomiej Plotka <bwplotka@gmail.com> Signed-off-by: Alan Protasio <alanprot@gmail.com> * Update promql/engine.go Co-authored-by: Bartlomiej Plotka <bwplotka@gmail.com> Signed-off-by: Alan Protasio <alanprot@gmail.com> * Update promql/engine.go Co-authored-by: Bartlomiej Plotka <bwplotka@gmail.com> Signed-off-by: Alan Protasio <alanprot@gmail.com> * Update promql/engine.go Co-authored-by: Bartlomiej Plotka <bwplotka@gmail.com> Signed-off-by: Alan Protasio <alanprot@gmail.com> * Allocating slice with maximum size of 5k Signed-off-by: Alan Protasio <alanprot@gmail.com> * adding comments Signed-off-by: Alan Protasio <alanprot@gmail.com> --------- Signed-off-by: Alan Protasio <alanprot@gmail.com> Co-authored-by: Bartlomiej Plotka <bwplotka@gmail.com>
This commit is contained in:
parent
5d233df7ef
commit
a15e884e7a
|
@ -60,6 +60,11 @@ const (
|
||||||
maxInt64 = 9223372036854774784
|
maxInt64 = 9223372036854774784
|
||||||
// The smallest SampleValue that can be converted to an int64 without underflow.
|
// The smallest SampleValue that can be converted to an int64 without underflow.
|
||||||
minInt64 = -9223372036854775808
|
minInt64 = -9223372036854775808
|
||||||
|
|
||||||
|
// Max initial size for the pooled points slices.
|
||||||
|
// The getHPointSlice and getFPointSlice functions are called with an estimated size which often can be
|
||||||
|
// over-estimated.
|
||||||
|
maxPointsSliceSize = 5000
|
||||||
)
|
)
|
||||||
|
|
||||||
type engineMetrics struct {
|
type engineMetrics struct {
|
||||||
|
@ -1910,19 +1915,33 @@ func getFPointSlice(sz int) []FPoint {
|
||||||
if p := fPointPool.Get(); p != nil {
|
if p := fPointPool.Get(); p != nil {
|
||||||
return p
|
return p
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if sz > maxPointsSliceSize {
|
||||||
|
sz = maxPointsSliceSize
|
||||||
|
}
|
||||||
|
|
||||||
return make([]FPoint, 0, sz)
|
return make([]FPoint, 0, sz)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// putFPointSlice will return a FPoint slice of size max(maxPointsSliceSize, sz).
|
||||||
|
// This function is called with an estimated size which often can be over-estimated.
|
||||||
func putFPointSlice(p []FPoint) {
|
func putFPointSlice(p []FPoint) {
|
||||||
if p != nil {
|
if p != nil {
|
||||||
fPointPool.Put(p[:0])
|
fPointPool.Put(p[:0])
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// getHPointSlice will return a HPoint slice of size max(maxPointsSliceSize, sz).
|
||||||
|
// This function is called with an estimated size which often can be over-estimated.
|
||||||
func getHPointSlice(sz int) []HPoint {
|
func getHPointSlice(sz int) []HPoint {
|
||||||
if p := hPointPool.Get(); p != nil {
|
if p := hPointPool.Get(); p != nil {
|
||||||
return p
|
return p
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if sz > maxPointsSliceSize {
|
||||||
|
sz = maxPointsSliceSize
|
||||||
|
}
|
||||||
|
|
||||||
return make([]HPoint, 0, sz)
|
return make([]HPoint, 0, sz)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue