mirror of
https://github.com/VictoriaMetrics/VictoriaMetrics.git
synced 2026-05-17 00:26:36 +03:00
Previously all timeseries pushed into aggregators were added sequentially. It could cause delays on data ingestion and it was not possible to use all available. This commit adds concurrency based on available CPU cores. Also, it adds new generic Buffer and BufferPool into slicesutil. Fixes https://github.com/VictoriaMetrics/VictoriaMetrics/issues/9878
35 lines
563 B
Go
35 lines
563 B
Go
package slicesutil
|
|
|
|
import "sync"
|
|
|
|
// Buffer implements a simple buffer for T.
|
|
type Buffer[T any] struct {
|
|
// B is the underlying T slice.
|
|
B []T
|
|
}
|
|
|
|
// Reset resets b.
|
|
func (b *Buffer[T]) Reset() {
|
|
b.B = b.B[:0]
|
|
}
|
|
|
|
// BufferPool is a pool of T Buffers.
|
|
type BufferPool[T any] struct {
|
|
p sync.Pool
|
|
}
|
|
|
|
// Get obtains a Buffer from bp.
|
|
func (bp *BufferPool[T]) Get() *Buffer[T] {
|
|
bbv := bp.p.Get()
|
|
if bbv == nil {
|
|
return &Buffer[T]{}
|
|
}
|
|
return bbv.(*Buffer[T])
|
|
}
|
|
|
|
// Put puts b into bp.
|
|
func (bp *BufferPool[T]) Put(b *Buffer[T]) {
|
|
b.Reset()
|
|
bp.p.Put(b)
|
|
}
|