From 54a0deb98237e4474d6d3d0df70ea3d08869e859 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Giedrius=20Statkevi=C4=8Dius?= Date: Thu, 9 Jun 2022 15:12:24 +0300 Subject: [PATCH] query: Close() after using query (#5410) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * query: Close() after using query This should reduce memory usage because Close() returns points back to a sync.Pool. Signed-off-by: Giedrius Statkevičius * CHANGELOG: add item Signed-off-by: Giedrius Statkevičius * query: call Close() in gRPC API too Signed-off-by: Giedrius Statkevičius --- CHANGELOG.md | 2 ++ pkg/api/query/grpc.go | 2 ++ pkg/api/query/v1.go | 2 ++ 3 files changed, 6 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 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 { 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)