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

Add the option to configure memory ballast for Loki #5081

Merged
merged 8 commits into from
Jan 10, 2022

Conversation

SasSwart
Copy link
Contributor

@SasSwart SasSwart commented Jan 9, 2022

What this PR does / why we need it:
Adds the option to configure a memory ballast in order to enable reducing garbage collection when needed.
Which issue(s) this PR fixes:
Fixes #781

Special notes for your reviewer:
PR Based on reading this, and a comparable PR in cortex.
Checklist

  • Documentation added
  • Tests updated
  • Add an entry in the CHANGELOG.md about the changes.

@SasSwart SasSwart requested a review from a team as a code owner January 9, 2022 17:42
@CLAassistant
Copy link

CLAassistant commented Jan 9, 2022

CLA assistant check
All committers have signed the CLA.

@SasSwart SasSwart changed the title Add memory ballast Add the option to configure memory ballast for Loki Jan 9, 2022
Copy link
Contributor

@dannykopping dannykopping left a comment

Choose a reason for hiding this comment

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

LGTM, thanks for this @SasSwart!
We'll definitely need some documentation about this, though. Do you mind adding that?

@SasSwart
Copy link
Contributor Author

SasSwart commented Jan 9, 2022

LGTM, thanks for this @SasSwart! We'll definitely need some documentation about this, though. Do you mind adding that?

On it.

Add additional information to Flag description
@pull-request-size pull-request-size bot added size/S and removed size/XS labels Jan 9, 2022
@SasSwart
Copy link
Contributor Author

SasSwart commented Jan 9, 2022

@dannykopping Done. Added more clarity to flag description as well.

@dannykopping
Copy link
Contributor

@dannykopping Done. Added more clarity to flag description as well.

Sorry, I should've been more clear. We have our docs at https://grafana.com/docs/loki/latest/configuration/ - which is linked to the docs directory. The comments are worthwhile, for sure, so you can leave those as they are; I think we'll need an update to the yaml config overview, perhaps plus a page in Operations about how/when to use this ballast setting.

This is asking a lot so don't feel obligated; we can add that after merging the PR.

@cyriltovena
Copy link
Contributor

I agree I don't know when I should use it either

@SasSwart
Copy link
Contributor Author

SasSwart commented Jan 10, 2022

This is asking a lot so don't feel obligated

No, it should definitely be on me to add docs for my contribution.
Not sure how I missed that the entire docs directory. My bad.
Adding docs

@SasSwart
Copy link
Contributor Author

While adding documentation, I noticed that I wasn't providing a tag for unmarshalling BallastBytes from the config file.

I've moved the BallastBytes value to the root config struct instead of the ConfigWrapper and provided the tag.

I also removed the option to set this as a Command Line argument in favor of the config file.
This seems to align better with the other configuration options.

@dannykopping
Copy link
Contributor

While adding documentation, I noticed that I wasn't providing a tag for unmarshalling BallastBytes from the config file.

I've moved the BallastBytes value to the root config struct instead of the ConfigWrapper and provided the tag.

I also removed the option to set this as a Command Line argument in favor of the config file. This seems to align better with the other configuration options.

Thanks for this.

We generally allow for the setting of important config options via both YAML and CLI; would you mind restoring this one? It can be defined in pkg/loki/loki.go under func (c *Config) RegisterFlags(f *flag.FlagSet) like we do for auth_enabled, for example.

Copy link
Contributor

@cyriltovena cyriltovena left a comment

Choose a reason for hiding this comment

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

LGTM

@dannykopping
Copy link
Contributor

Thanks @SasSwart 🙌
We'll wait for @KMiller-Grafana to approve the docs changes and then merge.

@bboreham
Copy link
Contributor

reduce the amount of time spent resizing goroutine stack sizes.

May I ask what that relates to? Normally I would say, as the code does, it's to reduce garbage-collection.

@SasSwart
Copy link
Contributor Author

Hey @bboreham

That would be a wording mistake on my side. When opening the PR, I must've referenced the wrong section of this issue. Thanks for spotting this.

I seem to have referred to the top level comment, whereas my contribution is more related to this comment.

I'll update the PR description.

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.

Thanks for the PR! LGTM!

@owen-d owen-d merged commit 79c337e into grafana:main Jan 10, 2022
Copy link
Contributor

@KMiller-Grafana KMiller-Grafana left a comment

Choose a reason for hiding this comment

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

This PR was merged in before my doc suggestions were written. Please consider using the suggestions in further revision.

Memory ballast is cool!

@@ -93,6 +93,12 @@ Pass the `-config.expand-env` flag at the command line to enable this way of set
# if true. If false, the OrgID will always be set to "fake".
[auth_enabled: <boolean> | default = true]

# The amount of virtual memory to reserve as a ballast in order to optimise
Copy link
Contributor

@KMiller-Grafana KMiller-Grafana Jan 10, 2022

Choose a reason for hiding this comment

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

Wording suggestion:
Change

The amount of virtual memory to reserve as a ballast in order to optimise

to be

The amount of virtual memory in bytes to reserve as ballast in order to optimize

Comment on lines +26 to +29
## Memory Ballast
In compute constrained environments, garbage collection can become a significant factor. This can be optimised, at the expense of memory consumption, by configuring a memory ballast using the `ballast_bytes` configuration option.

A larger memory ballast will mean that standard heap size volatility is less relatively significant, and therefore less likely to trigger garbage collection. This will result in lower compute overhead, but higher memory consumption, as the heap is cleaned less frequently.
Copy link
Contributor

Choose a reason for hiding this comment

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

We use sentence case for headers. Here's my rewrite of this section of prose:

Memory ballast

In compute-constrained environments, garbage collection can become a significant performance factor. Frequently-run garbage collection interferes with running the application by using CPU resources. The use of memory ballast can mitigate the issue. Memory ballast allocates extra, but unused virtual memory in order to inflate the quantity of live heap space. Garbage collection is triggered by the growth of heap space usage. The inflated quantity of heap space reduces the perceived growth, so garbage collection occurs less frequently.

Configure memory ballast using the ballast_bytes configuration option.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks for the notes @KMiller-Grafana,

I'll prepare a follow up PR with these changes.

dannykopping referenced this pull request Jan 14, 2022
* Add memory ballast

* Add changelog entry

* Add documentation

Add additional information to Flag description

* Ensure that ballast_bytes can be configured from config file

Add documentation

* Add Operational scalability documentation related to memory ballast

* Restore config.ballast-bytes cli flag

* Move config.ballast-bytes cli flag declaration

* Update memory ballast documentation as per https://github.com/grafana/loki/pull/5081\#pullrequestreview-848460132

Co-authored-by: Owen Diehl <ow.diehl@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.

Improve cpu/time performance by reusing request goroutines.
8 participants