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

perf: Introduce fixed size memory pool for bloom querier #13039

Merged
merged 18 commits into from
Jun 6, 2024

Conversation

chaudum
Copy link
Contributor

@chaudum chaudum commented May 27, 2024

What this PR does / why we need it:

This PR introduces a fixed size memory pool for bloom pages that are loaded in the block querier.

The aim of a fixed size pool of []byte buffers is to reduce the amount of allocations, as well as to control the maximum heap size to prevent OOMing of the bloom gateways.

Also, with the current usage of a sync.Pool, the query parallelism (bloom-gateway.worker-concurrency and bloom-gateway.block-query-concurrency) was defined by the bloom.max-query-page-size (and vice versa), because the max page size could be loaded workers * concurrency times at the same time. Most of the time, though, smaller pages are loaded, and therefore concurrency is not optimized.

With the new fixed size memory pool, this problem should be solved. The pool is divided into slabs of different sizes holding different amounts of buffers; a larger amount of small sized buffers and a smaller amount of large sized buffers.

TODO

  • Make slab sizes and their capacity configurable
  • Expose metrics for mempool usage

Notes for the reviewer

I'm up for suggestions for naming the configuration options, as well as for the interface name. I don't really like the term Allocator in this context.

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

@chaudum chaudum force-pushed the chaudum/allocator branch 2 times, most recently from 1afec2b to e49f84b Compare May 27, 2024 13:56
@github-actions github-actions bot added the type/docs Issues related to technical documentation; the Docs Squad uses this label across many repositories label May 27, 2024
@chaudum chaudum marked this pull request as ready for review May 27, 2024 20:08
@chaudum chaudum requested a review from a team as a code owner May 27, 2024 20:08
@chaudum chaudum requested a review from salvacorts May 27, 2024 20:08
pkg/storage/bloom/v1/mempool/pool.go Outdated Show resolved Hide resolved
pkg/storage/bloom/v1/mempool/pool.go Outdated Show resolved Hide resolved
pkg/storage/bloom/v1/mempool/pool.go Outdated Show resolved Hide resolved
pkg/storage/bloom/v1/util.go Show resolved Hide resolved
# and best effort re-cycling of buffers using Go's sync.Pool), fixed (a
# fixed size memory pool with configurable slab sizes, see mem-pool-buckets)
# CLI flag: -bloom.memory-management.alloc-type
[bloom_page_alloc_type: <string> | default = "dynamic"]
Copy link
Contributor

Choose a reason for hiding this comment

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

Is this something we want to expose to users? Or do we want to have it to run some experiments and will later remove it?

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 think this must be configurable, but it's kind of an "expert setting". We could hide it from the docs

pkg/bloomgateway/bloomgateway_test.go Outdated Show resolved Hide resolved
pkg/storage/bloom/v1/block.go Show resolved Hide resolved
@chaudum chaudum force-pushed the chaudum/allocator branch 2 times, most recently from a2cbf40 to 96152ca Compare June 2, 2024 15:53
@github-actions github-actions bot removed the type/docs Issues related to technical documentation; the Docs Squad uses this label across many repositories label Jun 3, 2024
chaudum added 11 commits June 6, 2024 11:26
This allows for using different implementations of allocators depending
on the use case
Signed-off-by: Christian Haudum <[email protected]>
Signed-off-by: Christian Haudum <[email protected]>
Signed-off-by: Christian Haudum <[email protected]>
Signed-off-by: Christian Haudum <[email protected]>
Signed-off-by: Christian Haudum <[email protected]>
Signed-off-by: Christian Haudum <[email protected]>
```
loki_mempool_available_buffers_per_slab{slab="..."}
loki_mempool_errors_total{slab="...", reason="..."}
```

Signed-off-by: Christian Haudum <[email protected]>
@chaudum chaudum requested a review from salvacorts June 6, 2024 10:07
Signed-off-by: Christian Haudum <[email protected]>
Copy link
Contributor

@salvacorts salvacorts left a comment

Choose a reason for hiding this comment

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

LGTM!

Signed-off-by: Christian Haudum <[email protected]>
@chaudum chaudum merged commit fc26431 into main Jun 6, 2024
59 checks passed
@chaudum chaudum deleted the chaudum/allocator branch June 6, 2024 14:41
owen-d added a commit that referenced this pull request Jun 6, 2024
chaudum added a commit that referenced this pull request Jun 7, 2024
…ruptions (#13162)"

This reverts commit 41c5ee2.

Signed-off-by: Christian Haudum <[email protected]>
chaudum added a commit that referenced this pull request Jun 7, 2024
---

Revert "fix(regression):  reverts #13039 to prevent use-after-free corruptions (#13162)"

This reverts commit 41c5ee2.

Signed-off-by: Christian Haudum <[email protected]>
chaudum added a commit that referenced this pull request Jun 7, 2024
---

Revert "fix(regression):  reverts #13039 to prevent use-after-free corruptions (#13162)"

This reverts commit 41c5ee2.

Signed-off-by: Christian Haudum <[email protected]>
chaudum added a commit that referenced this pull request Jun 7, 2024
---

Revert "fix(regression):  reverts #13039 to prevent use-after-free corruptions (#13162)"

This reverts commit 41c5ee2.

Signed-off-by: Christian Haudum <[email protected]>
chaudum added a commit that referenced this pull request Jun 10, 2024
---

Revert "fix(regression):  reverts #13039 to prevent use-after-free corruptions (#13162)"

This reverts commit 41c5ee2.

Signed-off-by: Christian Haudum <[email protected]>
chaudum added a commit that referenced this pull request Jun 19, 2024
---

Revert "fix(regression):  reverts #13039 to prevent use-after-free corruptions (#13162)"

This reverts commit 41c5ee2.

Signed-off-by: Christian Haudum <[email protected]>
chaudum added a commit that referenced this pull request Jun 20, 2024
This PR re-introduces the fixed size memory pool that was originally introduced with #13039 but reverted with #13162
Additionally, it removes the package-global variable to store the type of allocator that should be used. Instead, the allocator type is passed during the bloom store creation.

Signed-off-by: Christian Haudum <[email protected]>
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.

2 participants