-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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 automemlimit #6537
base: main
Are you sure you want to change the base?
Add automemlimit #6537
Conversation
Signed-off-by: Alex Bozhenko <alex@synadia.com>
@@ -136,5 +139,10 @@ func main() { | |||
defer undo() | |||
} | |||
|
|||
// If GOMEMLIMIT is not set, adjust GOMEMLIMIT if running under linux/cgroups quotas. | |||
memlimit.SetGoMemLimitWithOpts(memlimit.WithRatio(0.8), memlimit.WithLogger(slog.Default())) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Probably do not want to use slog here, but I was not sure how to plug it to the server logger, since memlimit.WithLogger expects slog logger.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we would need to make the server logger implement the Handler
interface from slog, then here call slog.New(s.Logger())
@@ -18,3 +19,5 @@ require ( | |||
golang.org/x/sys v0.30.0 | |||
golang.org/x/time v0.10.0 | |||
) | |||
|
|||
require github.com/pbnjay/memory v0.0.0-20210728143218-7b4eea64cf58 // indirect |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this dependency is not tagged nor released in 4-7 years... pinged the author on whether they could tag one
@@ -136,5 +139,10 @@ func main() { | |||
defer undo() | |||
} | |||
|
|||
// If GOMEMLIMIT is not set, adjust GOMEMLIMIT if running under linux/cgroups quotas. | |||
memlimit.SetGoMemLimitWithOpts(memlimit.WithRatio(0.8), memlimit.WithLogger(slog.Default())) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The ratio should be a config option?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes I think sudden default to 0.8 might be too sudden as a knob, in the config would be better. With default GOMEMLIMIT you cannot do fractions but would be interesting if this dependency supports doing 0.85 for example.
Summary
The problem:

A Guide to the Go Garbage Collector suggests:
When running in Kubernetes, the memory limit set using cgroups
Let's use the library that can automatically set the GOMEMLIMIT to a set percentage of memory limit of the cgroup
Reproducibe test plan:
Build a docker image for test:
The GOMEMLIMIT is set to 80% of the cgroup memory limit, as expected.
Signed-off-by: Alex Bozhenko alex@synadia.com