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

Cache label strings in ingester to improve memory usage. #2926

Merged
merged 3 commits into from
Nov 13, 2020

Conversation

cyriltovena
Copy link
Contributor

This reduces allocations in ingesters, but assume that labels comes in sorted which is now ensured in the distributors.
The distributors will take a performance hit, but that's easier to scale or improve later.(added some todos)

see benchmark:

❯ benchcmp before.txt after.txt
benchmark                     old ns/op     new ns/op     delta
Benchmark_PushInstance-16     43505         4950          -88.62%

benchmark                     old allocs     new allocs     delta
Benchmark_PushInstance-16     240            12             -95.00%

benchmark                     old bytes     new bytes     delta
Benchmark_PushInstance-16     42568         1787          -95.80%

Signed-off-by: Cyril Tovena <cyril.tovena@gmail.com>
This reduce allocations by a lot, but assume that labels comes in sorted which is not ensure in the distributors.
The distributors will take a performance hit, but that's easier to scale or improve later.(added some todos)

see benchmark:

```
❯ benchcmp before.txt after.txt
benchmark                     old ns/op     new ns/op     delta
Benchmark_PushInstance-16     43505         4950          -88.62%

benchmark                     old allocs     new allocs     delta
Benchmark_PushInstance-16     240            12             -95.00%

benchmark                     old bytes     new bytes     delta
Benchmark_PushInstance-16     42568         1787          -95.80%
```

Signed-off-by: Cyril Tovena <cyril.tovena@gmail.com>
@codecov-io
Copy link

Codecov Report

Merging #2926 (29bdda2) into master (f0d4adc) will decrease coverage by 0.04%.
The diff coverage is 90.90%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #2926      +/-   ##
==========================================
- Coverage   61.72%   61.68%   -0.05%     
==========================================
  Files         181      181              
  Lines       14724    14733       +9     
==========================================
- Hits         9089     9088       -1     
- Misses       4801     4813      +12     
+ Partials      834      832       -2     
Impacted Files Coverage Δ
pkg/distributor/validator.go 90.24% <ø> (-0.67%) ⬇️
pkg/distributor/distributor.go 75.91% <83.33%> (-1.37%) ⬇️
pkg/ingester/instance.go 56.80% <91.66%> (+1.06%) ⬆️
pkg/ingester/flush.go 83.21% <100.00%> (+0.12%) ⬆️
pkg/promtail/positions/positions.go 46.80% <0.00%> (-11.71%) ⬇️
pkg/logql/evaluator.go 91.64% <0.00%> (+0.40%) ⬆️
pkg/querier/queryrange/downstreamer.go 97.64% <0.00%> (+2.35%) ⬆️

cyriltovena added a commit to cyriltovena/loki that referenced this pull request Nov 13, 2020
Also moving labels parsing into logql package, and I'm not shy to say that promql is faster for this.
So we're using promql for parser, it's faster because their lexer is more sophisticated than ours.

Result are impressive.

```
❯ benchcmp before.txt after.txt
benchmark                    old ns/op     new ns/op     delta
Benchmark_ParseLabels-16     24394         8745          -64.15%

benchmark                    old allocs     new allocs     delta
Benchmark_ParseLabels-16     156            20             -87.18%

benchmark                    old bytes     new bytes     delta
Benchmark_ParseLabels-16     24976         2099          -91.60%
```

Combined with grafana#2926, I think we should be able to get rid of `util.ToClientLabels`. But that's for another PR.

Signed-off-by: Cyril Tovena <cyril.tovena@gmail.com>
@cyriltovena cyriltovena added this to the 2.1 milestone Nov 13, 2020
Signed-off-by: Cyril Tovena <cyril.tovena@gmail.com>
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.

I left some comments, otherwise it LGTM.

pkg/ingester/instance.go Show resolved Hide resolved
pkg/ingester/instance.go Outdated Show resolved Hide resolved
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 2303f1b into grafana:master Nov 13, 2020
cyriltovena added a commit that referenced this pull request Nov 13, 2020
* Improve logql parser allocations.

Also moving labels parsing into logql package, and I'm not shy to say that promql is faster for this.
So we're using promql for parser, it's faster because their lexer is more sophisticated than ours.

Result are impressive.

```
❯ benchcmp before.txt after.txt
benchmark                    old ns/op     new ns/op     delta
Benchmark_ParseLabels-16     24394         8745          -64.15%

benchmark                    old allocs     new allocs     delta
Benchmark_ParseLabels-16     156            20             -87.18%

benchmark                    old bytes     new bytes     delta
Benchmark_ParseLabels-16     24976         2099          -91.60%
```

Combined with #2926, I think we should be able to get rid of `util.ToClientLabels`. But that's for another PR.

Signed-off-by: Cyril Tovena <cyril.tovena@gmail.com>

* Fixes a test.

Signed-off-by: Cyril Tovena <cyril.tovena@gmail.com>
cyriltovena pushed a commit to cyriltovena/loki that referenced this pull request Jun 11, 2021
* retry processing of failed delete requests

Signed-off-by: Sandeep Sukhani <sandeep.d.sukhani@gmail.com>

* fix tests by adding a mode to mockstorage

Signed-off-by: Sandeep Sukhani <sandeep.d.sukhani@gmail.com>

* add changelog entry

Signed-off-by: Sandeep Sukhani <sandeep.d.sukhani@gmail.com>

* changes suggested from PR review

Signed-off-by: Sandeep Sukhani <sandeep.d.sukhani@gmail.com>
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

3 participants