From af6167df58c206daddccdeba3e9d9860f4ff611b Mon Sep 17 00:00:00 2001 From: Bryan Boreham Date: Tue, 20 Sep 2022 15:13:30 +0100 Subject: [PATCH] WAL loading: don't send empty buffers over chan (#11319) If some shards did not get any samples mapped, the buffer will be empty so sending it over the chan to `processWALSamples()` is a waste of time. This is especially likely now we are checking `minValidTime` before sending. Signed-off-by: Bryan Boreham Signed-off-by: Bryan Boreham --- tsdb/head_wal.go | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/tsdb/head_wal.go b/tsdb/head_wal.go index 5ef1fa311..6ea58bcd4 100644 --- a/tsdb/head_wal.go +++ b/tsdb/head_wal.go @@ -247,7 +247,9 @@ Outer: m = len(samples) } for i := 0; i < n; i++ { - shards[i] = processors[i].reuseBuf() + if shards[i] == nil { + shards[i] = processors[i].reuseBuf() + } } for _, sam := range samples[:m] { if sam.T < minValidTime { @@ -260,7 +262,10 @@ Outer: shards[mod] = append(shards[mod], sam) } for i := 0; i < n; i++ { - processors[i].input <- walSubsetProcessorInputItem{samples: shards[i]} + if len(shards[i]) > 0 { + processors[i].input <- walSubsetProcessorInputItem{samples: shards[i]} + shards[i] = nil + } } samples = samples[m:] }