Skip to content

Commit 1b658c0

Browse files
authored
optimize memory usage by recycling v2 requests (#7131)
* optimize memory usage by recycling v2 requests Signed-off-by: SungJin1212 <[email protected]> * fix benchmark Signed-off-by: SungJin1212 <[email protected]> --------- Signed-off-by: SungJin1212 <[email protected]>
1 parent 5140eed commit 1b658c0

File tree

3 files changed

+8
-1
lines changed

3 files changed

+8
-1
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
* [ENHANCEMENT] Alertmanager/Ruler: Introduce a user scanner to reduce the number of list calls to object storage. #6999
1212
* [ENHANCEMENT] Ruler: Add DecodingConcurrency config flag for Thanos Engine. #7118
1313
* [ENHANCEMENT] Compactor: Avoid double compaction by cleaning partition files in 2 cycles. #7129
14+
* [ENHANCEMENT] Distributor: Optimize memory usage by recycling v2 requests. #7131
1415
* [BUGFIX] Ring: Change DynamoDB KV to retry indefinitely for WatchKey. #7088
1516
* [BUGFIX] Ruler: Add XFunctions validation support. #7111
1617
* [BUGFIX] Distributor: Fix panic on health check failure when using stream push. #7116

pkg/util/push/push.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,12 @@ func Handler(remoteWrite2Enabled bool, maxRecvMsgSize int, sourceIPs *middleware
7979

8080
handlePRW2 := func() {
8181
var req cortexpb.PreallocWriteRequestV2
82+
// v1 request is put back into the pool by the Distributor.
83+
defer func() {
84+
cortexpb.ReuseWriteRequestV2(&req)
85+
req.Free()
86+
}()
87+
8288
err := util.ParseProtoReader(ctx, r.Body, int(r.ContentLength), maxRecvMsgSize, &req, util.RawSnappy)
8389
if err != nil {
8490
level.Error(logger).Log("err", err.Error())

pkg/util/push/push_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ func Benchmark_Handler(b *testing.B) {
141141
for b.Loop() {
142142
resp := httptest.NewRecorder()
143143
handler.ServeHTTP(resp, req)
144-
assert.Equal(b, http.StatusOK, resp.Code)
144+
assert.Equal(b, http.StatusNoContent, resp.Code)
145145
req.Body.(*resetReader).Reset()
146146
}
147147
})

0 commit comments

Comments
 (0)