mirror of
https://github.com/Kpa-clawbot/meshcore-analyzer.git
synced 2026-09-26 17:07:53 +00:00
Red commit: 929da3c6dcc1b619c27478291125d1c91323db8f — CI: https://github.com/Kpa-clawbot/CoreScope/commit/929da3c6dcc1b619c27478291125d1c91323db8f/checks Fixes #1010. ## What Adds `GOMEMLIMIT` support to both `cmd/server` and `cmd/ingestor` per the locked triage scope on #1010. Precedence (env wins): 1. `GOMEMLIMIT` env var 2. `runtime.maxMemoryMB` config field (new) 3. Server only: implicit `packetStore.maxMemoryMB * 1.5` (existing #836 behavior, unchanged when `runtime.maxMemoryMB` is absent) 4. Otherwise unset — default Go behavior preserved (backwards compatible) Each startup logs a `[memlimit]` line echoing the effective source/limit, or an "unset → default" note when neither is set. ## Changes - `cmd/ingestor/memlimit.go` — new, `applyMemoryLimit(runtimeMaxMB, envSet)`. - `cmd/ingestor/memlimit_test.go` — new, env/config/none/precedence assertions. - `cmd/ingestor/config.go` — new `RuntimeConfig{MaxMemoryMB int}` field. - `cmd/ingestor/main.go` — wires `applyMemoryLimit` into startup right after `LoadConfig`. - `cmd/server/config.go` — new `RuntimeConfig` + `cfg.Runtime` field. - `cmd/server/main.go` — adds explicit `runtime.maxMemoryMB` precedence over packetStore-derived; existing `warnIfMemlimitUnderprovisioned` (#1264) unchanged. - `config.example.json` — new `runtime` block with `_comment_runtime_maxMemoryMB` per the Config Documentation Rule. - `README.md` — sizing-table row with ≥1.5× working set floor + death-spiral warning. ## TDD - Red: `929da3c6` — ingestor `applyMemoryLimit` stub returns `(0,"none")`; four tests fail on assertions (`expected source=env, got "none"`, etc.) — no compile errors. - Green: `953ec9d8` — implements ingestor `applyMemoryLimit`, wires startup, threads `runtime.maxMemoryMB` through server too. ## Preflight `bash ~/.openclaw/skills/pr-preflight/scripts/run-all.sh origin/master` → clean (all gates pass, all warnings pass). ## Out of scope - `pprof`-verified GC-trigger acceptance criterion from the original issue — requires production tracing; the triage scope is the operator-tunable plumbing. - Container auto-detection of cgroup memory limit (already covered by #1264's `warnIfMemlimitUnderprovisioned`). --------- Co-authored-by: corescope-bot <bot@corescope>
27 lines
818 B
Go
27 lines
818 B
Go
package main
|
|
|
|
import "runtime/debug"
|
|
|
|
// applyMemoryLimit configures Go's soft memory limit (GOMEMLIMIT) for the
|
|
// ingestor process. See #1010.
|
|
//
|
|
// Precedence:
|
|
// 1. GOMEMLIMIT env var (parsed by the runtime at startup) — we do not
|
|
// override; report source="env" with limit=0.
|
|
// 2. runtimeMaxMB > 0 (from config runtime.maxMemoryMB) — set limit of
|
|
// runtimeMaxMB MiB via debug.SetMemoryLimit; source="config".
|
|
// 3. Otherwise no limit applied; source="none" (default behavior).
|
|
//
|
|
// Returns the limit (bytes) we set, or 0 if we did not set one.
|
|
func applyMemoryLimit(runtimeMaxMB int, envSet bool) (int64, string) {
|
|
if envSet {
|
|
return 0, "env"
|
|
}
|
|
if runtimeMaxMB <= 0 {
|
|
return 0, "none"
|
|
}
|
|
limit := int64(runtimeMaxMB) * 1024 * 1024
|
|
debug.SetMemoryLimit(limit)
|
|
return limit, "config"
|
|
}
|