Like Prometheus, but for logs.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 
loki/pkg/ingester/wal/recordpool.go

46 lines
792 B

package wal
import (
"sync"
)
type ResettingPool struct {
rPool *sync.Pool // records
bPool *sync.Pool // bytes
}
func NewRecordPool() *ResettingPool {
return &ResettingPool{
rPool: &sync.Pool{
New: func() interface{} {
return &Record{}
},
},
bPool: &sync.Pool{
New: func() interface{} {
buf := new([]byte) // Attempt to force allocation on heap.
*buf = make([]byte, 0, 1<<10) // 1kb
return buf
},
},
}
}
func (p *ResettingPool) GetRecord() *Record {
rec := p.rPool.Get().(*Record)
rec.Reset()
return rec
}
func (p *ResettingPool) PutRecord(r *Record) {
p.rPool.Put(r)
}
func (p *ResettingPool) GetBytes() *[]byte {
return p.bPool.Get().(*[]byte)
}
func (p *ResettingPool) PutBytes(b *[]byte) {
*b = (*b)[:0]
p.bPool.Put(b)
}