Files
VictoriaMetrics/lib/slicesutil/buffer.go
Nikolay 11f488d8ff lib/streamaggr: concurrently push timeseries to aggregators
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
2025-10-24 10:29:48 +02:00

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)
}