From 2e3b06a9b5ded06e7c33b01f300bd910f795872d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Giedrius=20Statkevi=C4=8Dius?= Date: Thu, 9 Jun 2022 14:34:04 +0300 Subject: [PATCH 1/3] query: Close() after using query MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This should reduce memory usage because Close() returns points back to a sync.Pool. Signed-off-by: Giedrius Statkevičius --- pkg/api/query/v1.go | 2 ++ 1 file changed, 2 insertions(+) diff --git a/pkg/api/query/v1.go b/pkg/api/query/v1.go index 5da44c7a2d..85473015d8 100644 --- a/pkg/api/query/v1.go +++ b/pkg/api/query/v1.go @@ -348,6 +348,7 @@ func (qapi *QueryAPI) query(r *http.Request) (interface{}, []error, *api.ApiErro if err != nil { return nil, nil, &api.ApiError{Typ: api.ErrorBadData, Err: err} } + defer qry.Close() tracing.DoInSpan(ctx, "query_gate_ismyturn", func(ctx context.Context) { err = qapi.gate.Start(ctx) @@ -470,6 +471,7 @@ func (qapi *QueryAPI) queryRange(r *http.Request) (interface{}, []error, *api.Ap if err != nil { return nil, nil, &api.ApiError{Typ: api.ErrorBadData, Err: err} } + defer qry.Close() tracing.DoInSpan(ctx, "query_gate_ismyturn", func(ctx context.Context) { err = qapi.gate.Start(ctx) From 6d39d25ceae82adc97cb607e8061af80f6d824a5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Giedrius=20Statkevi=C4=8Dius?= Date: Thu, 9 Jun 2022 14:37:01 +0300 Subject: [PATCH 2/3] CHANGELOG: add item MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Giedrius Statkevičius --- CHANGELOG.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 70e335f1f7..199dfec426 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -21,6 +21,8 @@ We use *breaking :warning:* to mark changes that are not backward compatible (re ### Changed +- [#5410](https://github.com/thanos-io/thanos/pull/5410) Query: Close() after using query. This should reduce bumps in memory allocations. + ### Removed ## [v0.26.0](https://github.com/thanos-io/thanos/tree/release-0.26) - 2022.05.05 From ff430ef043bf057a6dbca60f56984234dce044f3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Giedrius=20Statkevi=C4=8Dius?= Date: Thu, 9 Jun 2022 14:52:39 +0300 Subject: [PATCH 3/3] query: call Close() in gRPC API too MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Giedrius Statkevičius --- pkg/api/query/grpc.go | 2 ++ 1 file changed, 2 insertions(+) diff --git a/pkg/api/query/grpc.go b/pkg/api/query/grpc.go index db27b24edf..a5fe1f84d1 100644 --- a/pkg/api/query/grpc.go +++ b/pkg/api/query/grpc.go @@ -83,6 +83,7 @@ func (g *GRPCAPI) Query(request *querypb.QueryRequest, server querypb.Query_Quer if err != nil { return err } + defer qry.Close() result := qry.Exec(ctx) if err := server.Send(querypb.NewQueryWarningsResponse(result.Warnings)); err != nil { @@ -155,6 +156,7 @@ func (g *GRPCAPI) QueryRange(request *querypb.QueryRangeRequest, srv querypb.Que if err != nil { return err } + defer qry.Close() result := qry.Exec(ctx) if err := srv.Send(querypb.NewQueryRangeWarningsResponse(result.Warnings)); err != nil {