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

chore: Improve performance of structured metadata #13404

Merged
merged 4 commits into from
Jul 4, 2024

Conversation

cyriltovena
Copy link
Contributor

What this PR does / why we need it:

I realized queries with structured metadata where a bit slow and turns out we do a lot allocations in fact a slice of labels for each log line.

Improving this pretty impressive result:

❯ benchstat before.txt after.txt
name                        old time/op    new time/op    delta
BackwardIterator/66_kB-16     26.6ms ±11%    20.7ms ±11%  -22.12%  (p=0.008 n=5+5)
BackwardIterator/262_kB-16    21.8ms ±14%    19.3ms ± 8%  -11.75%  (p=0.016 n=5+5)
BackwardIterator/524_kB-16    16.7ms ± 6%    18.5ms ±19%     ~     (p=0.421 n=5+5)

name                        old alloc/op   new alloc/op   delta
BackwardIterator/66_kB-16     8.91MB ± 0%    1.02MB ± 0%  -88.53%  (p=0.008 n=5+5)
BackwardIterator/262_kB-16    7.34MB ± 0%    0.33MB ± 2%  -95.49%  (p=0.008 n=5+5)
BackwardIterator/524_kB-16    5.88MB ± 0%    0.13MB ± 3%  -97.77%  (p=0.008 n=5+5)

name                        old allocs/op  new allocs/op  delta
BackwardIterator/66_kB-16      51.5k ± 0%      2.8k ± 0%  -94.64%  (p=0.000 n=5+4)
BackwardIterator/262_kB-16     44.0k ± 0%      0.6k ± 0%  -98.60%  (p=0.008 n=5+5)
BackwardIterator/524_kB-16     36.0k ± 0%      0.3k ± 0%  -99.29%  (p=0.008 n=5+5)

cc @sandeepsukhani do you see anything wrong ?

Which issue(s) this PR fixes:
Fixes #

Special notes for your reviewer:

Checklist

  • Reviewed the CONTRIBUTING.md guide (required)
  • Documentation added
  • Tests updated
  • Title matches the required conventional commits format, see here
    • Note that Promtail is considered to be feature complete, and future development for logs collection will be in Grafana Alloy. As such, feat PRs are unlikely to be accepted unless a case can be made for the feature actually being a bug fix to existing behavior.
  • Changes that require user attention or interaction to upgrade are documented in docs/sources/setup/upgrade/_index.md
  • For Helm chart changes bump the Helm chart version in production/helm/loki/Chart.yaml and update production/helm/loki/CHANGELOG.md and production/helm/loki/README.md. Example PR
  • If the change is deprecating or removing a configuration option, update the deprecated-config.yaml and deleted-config.yaml files respectively in the tools/deprecated-config-checker directory. Example PR

@cyriltovena cyriltovena requested a review from a team as a code owner July 3, 2024 23:09
_ = hb.forEntries(
ctx,
logproto.FORWARD,
mint,
maxt,
func(statsCtx *stats.Context, ts int64, line string, structuredMetadataSymbols symbols) error {
value, parsedLabels, ok := extractor.ProcessString(ts, line, hb.symbolizer.Lookup(structuredMetadataSymbols)...)
structuredMetadata = hb.symbolizer.Lookup(structuredMetadataSymbols, structuredMetadata)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I wonder if this is fine to reuse the same buffer. cc @sandeepsukhani

Copy link
Contributor

@sandeepsukhani sandeepsukhani left a comment

Choose a reason for hiding this comment

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

LGTM

@cyriltovena cyriltovena merged commit 1e33ae1 into grafana:main Jul 4, 2024
60 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants