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

update automatically settting gomemlimit #1188

Merged
merged 14 commits into from
Oct 30, 2024
Merged
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ Main (unreleased)
- (_Public preview_) Added rate limiting of cluster state changes to reduce the
number of unnecessary, intermediate state updates. (@thampiotr)

- Graduate automatically setting GOMEMLIMIT to Generally Available from Public Preview. (@mattdurham)

### Bugfixes

- Fixed a clustering mode issue where a fatal startup failure of the clustering service
Expand Down
20 changes: 20 additions & 0 deletions docs/sources/reference/cli/environment-variables.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ The following environment variables are supported:

* `GODEBUG`
* `HTTP_PROXY`
* `GOMEMLIMIT`

Refer to the [Go runtime][runtime] documentation for more information about Go runtime environment variables.

Expand All @@ -35,4 +36,23 @@ Argument | Description | D
---------------------------|-------------------------------------------------|--------
`http://proxy.example.com` | The hostname or IP address of the proxy server. |

### GOMEMLIMIT

Usually, the [Go runtime][runtime] will release memory back to the operating system when requested.
In some environments, this may cause issues such as Out Of Memory (OOM) errors.
You can use the `GOMEMLIMIT` environment variable to set a soft memory cap and limit the maximum memory {{< param "PRODUCT_NAME" >}} can use.
You can set `GOMEMLIMIT` to a numeric value in bytes with an optional unit suffix.
The supported unit suffixes are `B`, `KiB`, `MiB`, `GiB`, and `TiB`.
Don't treat the `GOMEMLIMIT` environment variable as a hard memory limit.
{{< param "PRODUCT_NAME" >}} processes can use more memory if that memory is required.
A rough number is to set `GOMEMLIMIT` to is 90% of the maximum memory required.
For example, if you want to keep memory usage below `10GiB`, use `GOMEMLIMIT=8GiB`.

#### Automatic setting of GOMEMLIMIT
mattdurham marked this conversation as resolved.
Show resolved Hide resolved

The `GOMEMLIMIT` environment variable is set automatically {{< param "PRODUCT_NAME" >}} can determine the appropriate value.
If you set the `GOMEMLIMIT` environment variable before you run {{< param "PRODUCT_NAME" >}} then that setting will be used.
The variable value is set to 90% of the `cgroup` value set.
mattdurham marked this conversation as resolved.
Show resolved Hide resolved
No changes will occur if the limit cannot be determined and you did not explicitly define a `GOMEMLIMIT` value.

[runtime]: https://pkg.go.dev/runtime
1 change: 0 additions & 1 deletion docs/sources/reference/cli/run.md
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,6 @@ original configuration.
Include `--config.extra-args` to pass additional command line flags from the original format to the converter.
Refer to [alloy convert][] for more details on how `extra-args` work.


[alloy convert]: ../convert/
[clustering]: ../../../concepts/clustering/
[go-discover]: https://github.com/hashicorp/go-discover
Expand Down
4 changes: 1 addition & 3 deletions internal/alloycli/cmd_run.go
Original file line number Diff line number Diff line change
Expand Up @@ -200,9 +200,7 @@ func (fr *alloyRun) Run(configPath string) error {

// Set the memory limit, this will honor GOMEMLIMIT if set
// If there is a cgroup will follow that
if fr.minStability.Permits(featuregate.StabilityPublicPreview) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Want to remove the Permits function? 😂
It could be useful though, just that I don't think it's used now so YAGNI.

memlimit.SetGoMemLimitWithOpts(memlimit.WithLogger(slog.New(l.Handler())))
}
memlimit.SetGoMemLimitWithOpts(memlimit.WithLogger(slog.New(l.Handler())))

// Enable the profiling.
setMutexBlockProfiling(l)
Expand Down