Skip to content

Commit 976bc35

Browse files
authored
Reuse grpc buffer in querier's store-gateway stream (#7519)
* reuse grpc buffer in querier's store-gate way stream Signed-off-by: Essam Eldaly <eeldaly@amazon.com> * lint Signed-off-by: Essam Eldaly <eeldaly@amazon.com> * Scope down pr to just detach Signed-off-by: Essam Eldaly <eeldaly@amazon.com> * update changelog Signed-off-by: Essam Eldaly <eeldaly@amazon.com> * Disable intern Signed-off-by: Essam Eldaly <eeldaly@amazon.com> * Use series copy Signed-off-by: Essam Eldaly <eeldaly@amazon.com> * Copy labels Signed-off-by: Essam Eldaly <eeldaly@amazon.com> --------- Signed-off-by: Essam Eldaly <eeldaly@amazon.com>
1 parent cc88aa0 commit 976bc35

2 files changed

Lines changed: 18 additions & 1 deletion

File tree

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
* [ENHANCEMENT] Distributor: Add HMAC-SHA256 stream authentication for `PushStream` via `-distributor.sign-write-requests-keys`. #7475
2828
* [ENHANCEMENT] Instrument Ingester CPU profile with source for read APIs. #7494
2929
* [ENHANCEMENT] Ingester: Convert expanded postings cache from FIFO to LRU eviction to retain frequently-queried entries under memory pressure. #7510
30+
* [ENHANCEMENT] Querier: Detach series label and chunk data from gRPC unmarshal buffers in store-gateway streaming path, allowing the Go GC to reclaim receive buffers. #7519
3031
* [BUGFIX] Querier: Fix queryWithRetry and labelsWithRetry returning (nil, nil) on cancelled context by propagating ctx.Err(). #7370
3132
* [BUGFIX] Metrics Helper: Fix non-deterministic bucket order in merged histograms by sorting buckets after map iteration, matching Prometheus client library behavior. #7380
3233
* [BUGFIX] Distributor: Return HTTP 401 Unauthorized when tenant ID resolution fails in the Prometheus Remote Write 2.0 path. #7389

pkg/querier/blocks_store_queryable.go

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ import (
2929
"github.com/thanos-io/thanos/pkg/pool"
3030
thanosquery "github.com/thanos-io/thanos/pkg/query"
3131
"github.com/thanos-io/thanos/pkg/store/hintspb"
32+
"github.com/thanos-io/thanos/pkg/store/labelpb"
3233
"github.com/thanos-io/thanos/pkg/store/storepb"
3334
"github.com/thanos-io/thanos/pkg/strutil"
3435
"go.uber.org/atomic"
@@ -675,7 +676,11 @@ func (q *blocksStoreQuerier) fetchSeriesFromStores(
675676
myQueriedBlocks := []ulid.ULID(nil)
676677

677678
processSeries := func(s *storepb.Series) error {
678-
mySeries = append(mySeries, s)
679+
// Detach series data from the gRPC unmarshal buffer so that it can be freed.
680+
sCopy := *s
681+
sCopy.Labels = append([]labelpb.ZLabel(nil), s.Labels...)
682+
detachSeriesFromBuffer(&sCopy)
683+
mySeries = append(mySeries, &sCopy)
679684

680685
// Add series fingerprint to query limiter; will return error if we are over the limit
681686
limitErr := queryLimiter.AddSeries(cortexpb.FromLabelsToLabelAdapters(s.PromLabels()))
@@ -1189,6 +1194,17 @@ func convertBlockHintsToULIDs(hints []hintspb.Block) ([]ulid.ULID, error) {
11891194
return res, nil
11901195
}
11911196

1197+
// detachSeriesFromBuffer re-allocates label strings and chunk data byte slices
1198+
// so that the series no longer references the gRPC unmarshal buffer.
1199+
func detachSeriesFromBuffer(s *storepb.Series) {
1200+
labelpb.ReAllocZLabelsStrings(&s.Labels, false)
1201+
for i := range s.Chunks {
1202+
if s.Chunks[i].Raw != nil && len(s.Chunks[i].Raw.Data) > 0 {
1203+
s.Chunks[i].Raw.Data = append([]byte(nil), s.Chunks[i].Raw.Data...)
1204+
}
1205+
}
1206+
}
1207+
11921208
// countChunkBytes returns the size of the chunks making up the provided series in bytes
11931209
func countChunkBytes(series ...*storepb.Series) (count int) {
11941210
for _, s := range series {

0 commit comments

Comments
 (0)