Repository navigation
fix: automemlimit - #5180
fix: automemlimit#5180
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
26f702b to
257aae3
Compare
|
igor-kupczynski
left a comment
There was a problem hiding this comment.
LGTM, with some nits around the comments.
FWIIW there's a lot of prior art in using this lib in dev tools
Maybe one more thing to consider -- should we allow an opt out? (e.g. via an env var?). I don't see why would anyone NOT want it, esp if GOMEMLIMIT takes precedence, but maybe? WDYT @jbsouvestre
| Project | How it uses automemlimit |
|---|---|
Caddy (cmd/main.go) |
Always on. Uses the cgroup limit, falls back to system memory, logs through its zap logger. Opt-out is the library's env vars. |
Prometheus (cmd/prometheus/main.go) |
--auto-gomemlimit flag (on by default in 3.x, as far as I remember), plus .ratio and .refresh-interval flags; the refresh help text calls out VPA. Cgroup with system fallback. |
| Thanos | Flag plus ratio. Cgroup with system fallback. |
| Grafana Tempo | Config AutoMemLimitEnabled / AutoMemLimitRatio, refreshes every 15s, cgroup with system fallback. |
| Grafana Alloy | Always on with library defaults (cgroup only, 0.9). Comment says it honors GOMEMLIMIT if set. |
| Kyverno | Ratio flag, cgroup with system fallback. |
| // // Set the AUTOMEMLIMIT environment variable to a ratio in (0.0, 1.0], or "off". | ||
| // re-reads the limit every minute ( to support VPA in place resize). | ||
| func SetMemoryLimit(ctx context.Context) { | ||
| // Info level drops the "GOMEMLIMIT is unchanged" debug line logged on every refresh. |
There was a problem hiding this comment.
should we drop "GOMEMLIMIT is unchanged" to debug? or maybe set the log level to warn? I'm worried about the log spam from 3x deployments x 32 shards every minute
There was a problem hiding this comment.
The "GOMEMLIMIT is unchanged" line is already gone: automemlimit logs it at debug, and the logger has been capped at info since a887fb2. So each pod logs one line at startup, plus one per actual limit change. I checked it in a 512Mi container resized to 1Gi: two lines across the refresh, nothing in between.
I would keep info rather than warn, so the startup line (which shows the effective limit) stays visible. 381727e rewords the code comment so this is clear from the code.
| // FROM: https://github.com/KimMachineGun/automemlimit#usage | ||
| // // Importing this package sets GOMEMLIMIT automatically from the cgroup memory limit. | ||
| // // By default, it sets GOMEMLIMIT to 90% of the cgroup memory limit. | ||
| // // Set the AUTOMEMLIMIT environment variable to a ratio in (0.0, 1.0], or "off". | ||
| // re-reads the limit every minute ( to support VPA in place resize). |
There was a problem hiding this comment.
nit: can you reword what does this do in like one line/sentence, and then move the copy paste comment above the package import (as this is what triggers the side effect)
There was a problem hiding this comment.
Reworded to a short godoc in 381727e. I did not move the copied text above the import: that side effect belongs to the root automemlimit package (its init()), while we import the memlimit subpackage and call memlimit.Set explicitly, so the import alone does nothing.
- Rewrite the SetMemoryLimit godoc as a short description that names the GOMEMLIMIT and AUTOMEMLIMIT overrides. - Clarify why the logger is capped at info: automemlimit logs the per-refresh "unchanged" line at debug, so only startup and real changes are logged. - Add a Memory Limit Configuration section to the self-hosting configuration options.
|
@igor-kupczynski re opt-out: the library's env vars already cover it. One difference from most projects in your table: we don't fall back to system memory when there is no cgroup limit, we keep Go's default. That mainly affects hatchet-lite on a bare VM, where 90% of host memory wouldn't protect much anyway, so I kept it conservative. |
Description
Should fix some OOMKilled issues by setting the go memory limit to 90%
Fixes # (issue)
Type of change
Checklist
Changes have been:
🤖 AI Disclosure