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
9 changes: 9 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,12 @@ Argument | Description | D
---------------------------|-------------------------------------------------|--------
`http://proxy.example.com` | The hostname or IP address of the proxy server. |

### GOMEMLIMIT

Normally the [Go runtime][runtime] will release memory back to the Operating System when requested. In certain environments this may cause issues such as Out of Memory errors. The `GOMEMLIMIT` variable is a numeric value in bytes with an optional unit suffix. The supported suffixes include B, KiB, MiB, GiB, and TiB. This should not be treated has a hard limit. The process can use more memory if that memory is required. A rough number is to set `GOMEMLIMIT` to 90% of the maximum amount of memory usage. For example if you wanted to keep memory usage below `10GiB` then use `GOMEMLIMIT=8GiB`.
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

@clayton-cornell I added some doc here but its rough, would love additional eyes.

mattdurham marked this conversation as resolved.
Show resolved Hide resolved

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

The `GOMEMLIMIT` variable will be automatically set if {{< param "PRODUCT_NAME" >}} can determine the appropriate value. If the `GOMEMLIMIT` value is set before running {{< param "PRODUCT_NAME" >}} then that setting will be honored. The value will be set to 90% of the cgroup value set. If the limit cannot be determined and no value was explicitly passed then no changes will occur.
mattdurham marked this conversation as resolved.
Show resolved Hide resolved

[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