Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Query-frontend: Performance Improvements and Refactor #3888

Merged
merged 11 commits into from
Jul 23, 2024

Conversation

joe-elliott
Copy link
Member

What this PR does:
Refactors the frontend to pass a Request interface instead of an *http.Request. This is progress toward supporting deterministic search. Also added a search pipeline benchmark and found a perf improvement in prepareRequestForQueriers.

> benchstat before.txt after.txt
goos: darwin
goarch: arm64
pkg: github.com/grafana/tempo/modules/frontend
                  │  before.txt  │             after.txt              │
                  │    sec/op    │    sec/op     vs base              │
SearchPipeline-11   609.4m ± ∞ ¹   604.0m ± ∞ ¹  -0.87% (p=0.008 n=5)
¹ need >= 6 samples for confidence interval at level 0.95

                  │   before.txt   │              after.txt               │
                  │      B/op      │     B/op       vs base               │
SearchPipeline-11   10.642Mi ± ∞ ¹   8.659Mi ± ∞ ¹  -18.63% (p=0.008 n=5)
¹ need >= 6 samples for confidence interval at level 0.95

                  │  before.txt  │             after.txt              │
                  │  allocs/op   │  allocs/op    vs base              │
SearchPipeline-11   163.0k ± ∞ ¹   148.3k ± ∞ ¹  -9.02% (p=0.008 n=5)
¹ need >= 6 samples for confidence interval at level 0.95

Checklist

  • Tests updated
  • Documentation added
  • CHANGELOG.md updated - the order of entries should be [CHANGE], [FEATURE], [ENHANCEMENT], [BUGFIX]

Signed-off-by: Joe Elliott <number101010@gmail.com>
Signed-off-by: Joe Elliott <number101010@gmail.com>
Signed-off-by: Joe Elliott <number101010@gmail.com>
Signed-off-by: Joe Elliott <number101010@gmail.com>
Signed-off-by: Joe Elliott <number101010@gmail.com>
Signed-off-by: Joe Elliott <number101010@gmail.com>
Signed-off-by: Joe Elliott <number101010@gmail.com>
Signed-off-by: Joe Elliott <number101010@gmail.com>
Signed-off-by: Joe Elliott <number101010@gmail.com>
Signed-off-by: Joe Elliott <number101010@gmail.com>
Signed-off-by: Joe Elliott <number101010@gmail.com>
Copy link
Member

@mapno mapno left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Refactor looks OK. Any idea why this is faster or uses less memory?

@@ -239,20 +245,19 @@ func newMetricsSummaryHandler(next pipeline.AsyncRoundTripper[combiner.PipelineR
// prepareRequestForQueriers modifies the request so they will be farmed correctly to the queriers
// - adds the tenant header
// - sets the requesturi (see below for details)
func prepareRequestForQueriers(req *http.Request, tenant string, originalURI string, params url.Values) {
func prepareRequestForQueriers(req *http.Request, tenant string) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I find this function pretty obscure. Why don't we return a new http.Request based on the original one?

func getQuerierHTTPRequest(origin_req *http.Request, tenant string) *http.Request{
}

That way we will reduce the cognitive overload reading the code

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would prefer modifying in place to reduce allocs

@joe-elliott
Copy link
Member Author

joe-elliott commented Jul 23, 2024

Refactor looks OK. Any idea why this is faster or uses less memory?

I removed these calls to .Query() which allocs a map by changing the way prepareRequestForQueriers works:

https://github.com/grafana/tempo/pull/3888/files#diff-85974350e62b77bee6b5d88d537e3946839ccb1bba5f6dc89450a1c5489b5d4fL443

I have a follow up PR coming that will remove millions of these calls from the search path.

@joe-elliott joe-elliott merged commit 2fbc1f4 into grafana:main Jul 23, 2024
14 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants