From f3c0535628449e3717228f94fbdd36fc95d22760 Mon Sep 17 00:00:00 2001 From: thorfour Date: Wed, 7 Dec 2022 11:37:11 -0600 Subject: [PATCH] querydiff: perform the profile selections concurrently --- go.mod | 2 +- pkg/query/columnquery.go | 30 +++++++++++++++++++++++------- 2 files changed, 24 insertions(+), 8 deletions(-) diff --git a/go.mod b/go.mod index b5a09ca6f35..ee58c4aba03 100644 --- a/go.mod +++ b/go.mod @@ -45,6 +45,7 @@ require ( go.opentelemetry.io/otel/trace v1.11.1 golang.org/x/exp v0.0.0-20221204150635-6dcec336b2bb golang.org/x/net v0.2.0 + golang.org/x/sync v0.1.0 google.golang.org/genproto v0.0.0-20221202195650-67e5cbc046fd google.golang.org/grpc v1.51.0 google.golang.org/protobuf v1.28.1 @@ -226,7 +227,6 @@ require ( golang.org/x/crypto v0.1.0 // indirect golang.org/x/mod v0.6.0 // indirect golang.org/x/oauth2 v0.2.0 // indirect - golang.org/x/sync v0.1.0 // indirect golang.org/x/sys v0.2.0 // indirect golang.org/x/term v0.2.0 // indirect golang.org/x/text v0.4.0 // indirect diff --git a/pkg/query/columnquery.go b/pkg/query/columnquery.go index 004cdcf61cd..2957a8e95eb 100644 --- a/pkg/query/columnquery.go +++ b/pkg/query/columnquery.go @@ -23,6 +23,7 @@ import ( "github.com/go-kit/log" "go.opentelemetry.io/otel/attribute" "go.opentelemetry.io/otel/trace" + "golang.org/x/sync/errgroup" "google.golang.org/grpc/codes" "google.golang.org/grpc/status" @@ -274,14 +275,29 @@ func (q *ColumnQueryAPI) selectDiff(ctx context.Context, d *pb.DiffProfile) (*pr return nil, status.Error(codes.InvalidArgument, "requested diff mode, but did not provide parameters for diff") } - base, err := q.selectProfileForDiff(ctx, d.A) - if err != nil { - return nil, fmt.Errorf("reading base profile: %w", err) - } + g, ctx := errgroup.WithContext(ctx) + var base *profile.Profile + g.Go(func() error { + var err error + base, err = q.selectProfileForDiff(ctx, d.A) + if err != nil { + return fmt.Errorf("reading base profile: %w", err) + } + return nil + }) - compare, err := q.selectProfileForDiff(ctx, d.B) - if err != nil { - return nil, fmt.Errorf("reading compared profile: %w", err) + var compare *profile.Profile + g.Go(func() error { + var err error + compare, err = q.selectProfileForDiff(ctx, d.B) + if err != nil { + return fmt.Errorf("reading compared profile: %w", err) + } + return nil + }) + + if err := g.Wait(); err != nil { + return nil, err } // TODO: This is cheating a bit. This should be done with a sub-query in the columnstore.