mirror of
https://github.com/prometheus/prometheus.git
synced 2024-09-19 23:37:31 -07:00
Use buffer pool for head appenders
This commit is contained in:
parent
a317f252b9
commit
fde69dab49
|
@ -150,7 +150,7 @@ func (b *writeBenchmark) ingestScrapes(metrics []model.Metric, scrapeCount int)
|
|||
lbls = append(lbls, lset)
|
||||
}
|
||||
|
||||
for i := 0; i < scrapeCount; i += 25 {
|
||||
for i := 0; i < scrapeCount; i += 50 {
|
||||
lbls := lbls
|
||||
for len(lbls) > 0 {
|
||||
l := 1000
|
||||
|
@ -162,7 +162,7 @@ func (b *writeBenchmark) ingestScrapes(metrics []model.Metric, scrapeCount int)
|
|||
|
||||
wg.Add(1)
|
||||
go func() {
|
||||
n, err := b.ingestScrapesShard(batch, 25, int64(30000*i))
|
||||
n, err := b.ingestScrapesShard(batch, 50, int64(30000*i))
|
||||
if err != nil {
|
||||
// exitWithError(err)
|
||||
fmt.Println(" err", err)
|
||||
|
|
17
head.go
17
head.go
|
@ -107,7 +107,21 @@ func (h *headBlock) Stats() BlockStats {
|
|||
|
||||
func (h *headBlock) Appender() Appender {
|
||||
h.mtx.RLock()
|
||||
return &headAppender{headBlock: h}
|
||||
return &headAppender{headBlock: h, samples: getHeadAppendBuffer()}
|
||||
}
|
||||
|
||||
var headPool = sync.Pool{}
|
||||
|
||||
func getHeadAppendBuffer() []hashedSample {
|
||||
b := headPool.Get()
|
||||
if b == nil {
|
||||
return make([]hashedSample, 0, 512)
|
||||
}
|
||||
return b.([]hashedSample)
|
||||
}
|
||||
|
||||
func putHeadAppendBuffer(b []hashedSample) {
|
||||
headPool.Put(b[:0])
|
||||
}
|
||||
|
||||
type headAppender struct {
|
||||
|
@ -213,6 +227,7 @@ func (a *headAppender) createSeries() {
|
|||
}
|
||||
|
||||
func (a *headAppender) Commit() error {
|
||||
defer putHeadAppendBuffer(a.samples)
|
||||
defer a.mtx.RUnlock()
|
||||
|
||||
// Write all new series and samples to the WAL and add it to the
|
||||
|
|
Loading…
Reference in a new issue