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

Improve Structural Operators Perf #3029

Merged
merged 19 commits into from
Oct 26, 2023

Conversation

joe-elliott
Copy link
Member

@joe-elliott joe-elliott commented Oct 17, 2023

What this PR does:
The PR improves performance by using a standard sort/search procedure but that requires having both the LHS and RHS of the operator at the fetch layer (where it is aware of nested set implementation details). The cost is a very ungainly change to the span interface:

	SiblingOf([]Span, []Span, bool, bool, []Span) []Span
	DescendantOf([]Span, []Span, bool, bool, []Span) []Span
	ChildOf([]Span, []Span, bool, bool, []Span) []Span

These methods no longer operate on the span itself which is strange. However, there is no other clean places to place it that can be easily accessed deep in the engine where the evaluations occur.

Other fixes:

  • Fixed an issue where {} !~ {} would not find the root span. The way the fix is implemented multiple root spans will be considered siblings using a query like {} ~ {}
  • Fixed the bridge iterator sort to use the correct definition level

Benchmarks to follow.

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>
@joe-elliott
Copy link
Member Author

Benchmarks show significant improvements on the worst case and even performance in the normal case.

Queries

{"sibling", "{ resource.service.name = `loki-querier` } ~ { resource.service.name = `loki-querier` }"},
{"desc", "{ resource.service.name = `loki-querier` } >> { resource.service.name = `loki-querier` }"},
{"child", "{ resource.service.name = `loki-querier` } > { resource.service.name = `loki-querier` }"},
name                           old time/op    new time/op    delta
BackendBlockTraceQL/sibling-8     956ms ± 6%     841ms ± 2%  -12.05%  (p=0.008 n=5+5)
BackendBlockTraceQL/desc-8        1.04s ± 7%     1.08s ±12%     ~     (p=0.548 n=5+5)
BackendBlockTraceQL/child-8       1.06s ± 8%     1.12s ±10%     ~     (p=0.222 n=5+5)

name                           old speed      new speed      delta
BackendBlockTraceQL/sibling-8  14.9MB/s ± 6%  16.9MB/s ± 2%  +13.56%  (p=0.008 n=5+5)
BackendBlockTraceQL/desc-8     15.1MB/s ± 6%  14.6MB/s ±11%     ~     (p=0.548 n=5+5)
BackendBlockTraceQL/child-8    14.9MB/s ± 7%  14.1MB/s ±10%     ~     (p=0.222 n=5+5)

name                           old MB_io/op   new MB_io/op   delta
BackendBlockTraceQL/sibling-8      14.2 ± 0%      14.2 ± 0%     ~     (all equal)
BackendBlockTraceQL/desc-8         15.7 ± 0%      15.7 ± 0%     ~     (all equal)
BackendBlockTraceQL/child-8        15.7 ± 0%      15.7 ± 0%     ~     (all equal)

name                           old alloc/op   new alloc/op   delta
BackendBlockTraceQL/sibling-8    50.4MB ± 3%    48.0MB ±14%     ~     (p=0.286 n=4+5)
BackendBlockTraceQL/desc-8       44.5MB ± 5%    50.8MB ±18%  +14.18%  (p=0.016 n=5+5)
BackendBlockTraceQL/child-8      46.3MB ± 8%    43.8MB ± 0%     ~     (p=0.690 n=5+5)

name                           old allocs/op  new allocs/op  delta
BackendBlockTraceQL/sibling-8      109k ± 3%      109k ± 4%     ~     (p=0.905 n=4+5)
BackendBlockTraceQL/desc-8         107k ± 0%      111k ± 6%   +3.95%  (p=0.008 n=5+5)
BackendBlockTraceQL/child-8        106k ± 0%      107k ± 0%   +0.83%  (p=0.008 n=5+5)

Queries

{"sibling", "{ resource.service.name = `loki-querier` } ~ { name != `` }"},
{"desc", "{ resource.service.name = `loki-querier` } >> { name != `` }"},
{"child", "{ resource.service.name = `loki-querier` } > { name != `` }"},
name                           old time/op    new time/op     delta
BackendBlockTraceQL/sibling-8     1.82s ± 7%      1.48s ±16%  -18.61%  (p=0.016 n=5+5)
BackendBlockTraceQL/desc-8        1.84s ± 3%      1.68s ± 6%   -9.08%  (p=0.008 n=5+5)
BackendBlockTraceQL/child-8       1.88s ± 4%      1.58s ± 5%  -15.88%  (p=0.008 n=5+5)

name                           old speed      new speed       delta
BackendBlockTraceQL/sibling-8  8.47MB/s ± 7%  10.45MB/s ±15%  +23.35%  (p=0.016 n=5+5)
BackendBlockTraceQL/desc-8     12.2MB/s ± 3%   13.4MB/s ± 6%  +10.06%  (p=0.008 n=5+5)
BackendBlockTraceQL/child-8    11.9MB/s ± 4%   14.2MB/s ± 4%  +18.86%  (p=0.008 n=5+5)

name                           old MB_io/op   new MB_io/op    delta
BackendBlockTraceQL/sibling-8      15.4 ± 0%       15.4 ± 0%     ~     (all equal)
BackendBlockTraceQL/desc-8         22.4 ± 0%       22.4 ± 0%     ~     (all equal)
BackendBlockTraceQL/child-8        22.5 ± 0%       22.5 ± 0%     ~     (all equal)

name                           old alloc/op   new alloc/op    delta
BackendBlockTraceQL/sibling-8     267MB ±43%      218MB ±73%     ~     (p=0.381 n=5+5)
BackendBlockTraceQL/desc-8        153MB ± 1%      153MB ± 9%     ~     (p=0.730 n=4+5)
BackendBlockTraceQL/child-8       152MB ± 3%      150MB ± 3%     ~     (p=0.968 n=5+5)

name                           old allocs/op  new allocs/op   delta
BackendBlockTraceQL/sibling-8     3.41M ± 8%      3.30M ±10%     ~     (p=0.952 n=5+5)
BackendBlockTraceQL/desc-8        3.15M ± 0%      3.15M ± 0%   +0.03%  (p=0.008 n=5+5)
BackendBlockTraceQL/child-8       3.15M ± 0%      3.15M ± 0%   +0.03%  (p=0.008 n=5+5)

Queries
These queries don't even return on main. A single pass takes ~5 minutes. Results are for this branch only.

{"sibling", "{ name != `` } ~ { name != `` }"},
{"desc", "{ name != `` } >> { name != `` }"},
{"child", "{ name != `` } > { name != `` }"},
name                           time/op
BackendBlockTraceQL/sibling-8     1.86s ± 6%
BackendBlockTraceQL/desc-8        3.35s ± 4%
BackendBlockTraceQL/child-8       2.06s ± 3%

name                           speed
BackendBlockTraceQL/sibling-8  10.2MB/s ± 6%
BackendBlockTraceQL/desc-8     6.11MB/s ± 4%
BackendBlockTraceQL/child-8    10.0MB/s ± 3%

name                           MB_io/op
BackendBlockTraceQL/sibling-8      19.0 ± 0%
BackendBlockTraceQL/desc-8         20.5 ± 0%
BackendBlockTraceQL/child-8        20.5 ± 0%

name                           alloc/op
BackendBlockTraceQL/sibling-8    1.36GB ± 1%
BackendBlockTraceQL/desc-8       1.42GB ± 0%
BackendBlockTraceQL/child-8      1.43GB ± 1%

name                           allocs/op
BackendBlockTraceQL/sibling-8     6.13M ± 0%
BackendBlockTraceQL/desc-8        6.22M ± 0%
BackendBlockTraceQL/child-8       6.22M ± 0%

@mdisibio
Copy link
Contributor

These queries don't even return on main

Does that mean the changelog entry should be new FEATURE? 😄

pkg/traceql/storage.go Outdated Show resolved Hide resolved
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>
@joe-elliott joe-elliott marked this pull request as ready for review October 23, 2023 14:16
@joe-elliott joe-elliott changed the title WIP: Improve Structural Operators Perf Improve Structural Operators Perf Oct 23, 2023
pkg/traceql/storage.go Outdated Show resolved Hide resolved
Signed-off-by: Joe Elliott <number101010@gmail.com>
Signed-off-by: Joe Elliott <number101010@gmail.com>
@mdisibio mdisibio self-assigned this Oct 26, 2023
Signed-off-by: Joe Elliott <number101010@gmail.com>
Signed-off-by: Joe Elliott <number101010@gmail.com>
Copy link
Contributor

@mdisibio mdisibio left a comment

Choose a reason for hiding this comment

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

Great performance improvement 👍

@joe-elliott joe-elliott merged commit 3322d28 into grafana:main Oct 26, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

3 participants