Skip to content

Go runtime settings

Last updated: 2026-11-19T00:30:50-03:00 (UTC-3)

Configure garbage-collection percentage pacing and the Go runtime’s soft memory limit through the behavior YAML. The gateway retains its existing defaults; this configuration does not introduce a memory service or change request/relay admission.

runtime:
gc_percent: 200
memory_limit_share: 0.9
memory_limit_mib: 0
YAML parameter Default Meaning and allowed values
runtime.gc_percent 200 Integer -1 through 2147483647. -1 turns off percentage-based pacing; explicit 0 requests Go’s aggressive zero-percent pacing. Omission/null uses 200
runtime.memory_limit_share 0.9 Finite fraction greater than 0 and at most 1, used only for automatic sizing from a recognized cgroup limit. NaN and infinity are rejected
runtime.memory_limit_mib 0 (automatic) Integer -1, 0, or 1–8796093022207. -1 disables the soft cap; 0 uses automatic selection; positive values are MiB (2²⁰ bytes), checked before multiplication

Explicit defaults and zero retain their YAML source. Null/omission uses the default. Invalid policy is rejected even when an environment override wins or the settings view is hidden. The automatic policy uses the process cgroup observation and bounded fraction calculation; when no usable limit is detected, the gateway leaves the runtime’s memory setting unchanged. It does not infer host RAM or a cloud limit. Explicit MiB settings work independently of cgroup detection.

At startup, the gateway reads /proc/self/cgroup and /proc/self/mountinfo to locate the process in a visible Linux memory hierarchy. It selects the smallest usable hard limit in the current cgroup and its visible ancestors: memory.max for v2, or memory.limit_in_bytes for v1. A v1 ancestor is counted only when its memory.use_hierarchy is readable and enabled. memory.high is a throttling boundary, not the hard limit used here. Unreadable, unlimited and invalid values do not manufacture a limit.

Mountinfo escapes and literal membership paths have different meanings. Subtree mounts are mapped only within their declared root. A cgroup namespace can hide ancestors; their limits cannot be reconstructed. Present metadata with an unmappable topology, including an inherited /.. mount root, stays unknown. Only when proc metadata is unavailable does the gateway use its legacy fixed-root probes. These are detected, visible limits, not certification of every host or namespace arrangement.

GC and admission use one immutable startup observation. Changing a container’s memory limit later does not resize either budget; restart the gateway to capture it again. The CPU scheduler has its own Go behavior, described below.

For automatic GC sizing, the gateway takes the integer floor of the detected bytes multiplied by the normalized fraction’s shortest decimal representation, then applies a minimum of one byte. This avoids a rounded floating-point product exceeding the detected limit, including with share 1. A positive fraction too small to produce a whole byte therefore selects one byte instead of silently leaving the cap disabled. Such a tiny soft limit is operationally impractical; use an appropriate deployment limit and fraction. Explicit MiB values, disabled caps and nonempty Go environment overrides retain their existing precedence.

The gateway targets Go 1.26 or newer and preserves Go’s container-aware GOMAXPROCS scheduling. In the default Linux runtime policy, CPU quota is rounded up and normally has a floor of two processors, bounded by logical CPUs and affinity. CPU requests are not CPU limits. A user-supplied GOMAXPROCS or GODEBUG can change Go’s policy; the gateway does not overwrite it or call a setter that would disable Go’s automatic updates. See the Go runtime contract.

CPU scheduling is separate from concurrency and database connections. The gateway’s generation fallback remains 512, the PostgreSQL pool remains 10/1, HTTP zero still adds no connection ceiling, and the shipped HTTP profile explicitly selects 512. These are fixed or explicit choices, not CPU-derived values. Memory-derived relay budgets retain their own floors, ceilings and sources. There is no universal CPU-to-provider-concurrency or CPU-to-database-pool formula: workload, provider quotas, replica count and database capacity must inform those explicit settings. This delivery adds no such calibrated formula or throughput guarantee.

Nonempty GOGC and GOMEMLIMIT take precedence for their respective runtime setting. Go processes them before main, and the gateway preserves and observes that actual state instead of parsing/reapplying the raw text. With no corresponding override, the gateway applies the selected YAML/default policy at its existing startup stage, before constructing the gateway handler.

These are different domains: YAML memory_limit_mib: 0 selects automatic sizing; Go GOMEMLIMIT=0B is an actual zero-byte pressure setting. YAML memory_limit_mib: -1 and Go GOMEMLIMIT=off select the effectively disabled cap, represented internally by 9223372036854775807 bytes.

In the tested Go runtime, GOGC=off or a negative value yields percentage setting -1; valid GOGC=0 stays zero. Malformed or out-of-range GOGC falls back to Go’s 100, so the observed value may differ from the gateway’s configured default 200. The panel shows that actual value with Environment provenance.

Malformed GOMEMLIMIT can abort and print the raw value before gateway code starts. The gateway cannot intercept or sanitize that pre-main diagnostic, including for validate, healthcheck and keygen. Use valid runtime variables; the gateway’s own YAML validation errors remain value-free. gateway validate validates the YAML policy without applying it to the process’s GC/memory settings.

A soft limit is not a container or RSS ceiling

Section titled “A soft limit is not a container or RSS ceiling”

The limit covers Go-managed memory, including stacks, and excludes other memory such as the mapped binary, non-Go allocations and memory held by the operating system. Go can exceed the soft limit and limits GC CPU consumption to avoid continuous collection. A higher GC percentage or a 90% fraction therefore does not guarantee the process stays within its cgroup or avoids OOM. Percentage pacing off does not prevent memory-limit-driven collection.

Keep headroom for the deployment and workload. Kubernetes/Docker resource limits, Go runtime settings, and the gateway’s logical admission/body/relay budgets serve different purposes. This feature does not change resource limits, pool sizes, admission formulas or retries. See the Go GC guide and SetMemoryLimit contract.

With the existing boot_settings_view flag and configuration-read permissions, Settings & sources → Go runtime settings separates:

  • Configured runtime policy: three normalized startup values, their defaults and YAML/default source. These inputs are retained even when an environment setting or fixed limit makes a policy input inactive.
  • Observed at startup: the actual GC percentage and exact memory-limit bytes, with the selection source. The share is active only when the memory source is Derived.

The administrative configuration API exposes the same read-only infrastructure.runtime_settings object: configured has exactly three known policy rows, applied contains GC value/source and memory bytes/source, and restart_required is true. Applied GC is an integer; memory bytes are a canonical decimal string, preserving values beyond JavaScript’s safe integer range without rounding to MiB. Runtime/Environment provenance describes preserved runtime state, not an echo of raw variable text.

An uncaptured factory reports unavailable values/sources. Private startup captures survive unrelated edits and cross-replica refreshes; each replica keeps its own runtime observations. Changes require a rollout. Turning the view off hides metadata without disabling runtime behavior or granting access. Access loss clears the page’s prior snapshots. HTTP budgets, healthcheck selection and lifecycle rows remain separate.

At startup the gateway logs one gc_pacing line, whoever chose the values: gc_percent (the observed percentage, -1 when percentage pacing is off) with gc_source (default, yaml or environment), and memory_limit_bytes (the observed soft limit, 9223372036854775807 when there is none) with memory_source (derived, yaml, environment, or runtime when the gateway left Go’s own value), plus restart_required: true. These are the values and sources infrastructure.runtime_settings.applied reports. Before 2026-11-18 (T173) the line carried no sources and was left out when the environment set both variables. The structured config_applied snapshot additionally includes safe runtime policy and observed state; it contains no raw environment values, secret references or private endpoints.

All modes consume the same behavior YAML. Automatic cgroup sizing applies where the process recognizes a Linux cgroup memory limit; native hosts without one can use an explicit MiB setting or a valid Go environment override. Docker/Kubernetes resource declarations belong to the operator. Configuring a soft limit neither provisions infrastructure nor sets an OS memory limit.

Run gateway validate, then inspect the actual replica’s policy and observations after rollout. For an explicit value, compare exact bytes rather than a rounded MiB label. With an environment override, check the observed source and Go’s startup semantics. Test any workload-specific tuning under load separately; this reconciliation makes no new throughput, latency, heap-size or OOM claim.

The gate covers finite/bounds/overflow, selection/capture/privacy and pointer ownership, plus process-isolated runtime tests. Independent validation uses the actual binary, native Go observations, pinned constrained containers, PostgreSQL refresh and desktop/narrow browser profiles. Those stated local profiles do not certify every native host, container distribution or workload.

The three existing runtime policies share consumed defaults/bounds and generated console constraints through the parameter registry. The configured policy remains distinct from actual startup observations: GC0 is a real percentage choice, GC−1 turns percentage pacing off, MiB0 selects automatic behavior, MiB−1 removes the Go soft cap, and share must be finite and greater than zero through one inclusive. The signed integer descriptors carry their explicit off/automatic sentinels; the share descriptor has an exclusive zero minimum. Definition source kinds describe configured policy, while the separate observed layer can report environment/runtime/derived sources. These rules do not change current cgroup arithmetic, GC application or environment precedence.

The read-only console keeps three configured rows with defaults/source and separate observed GC/exact-byte values. Missing capture stays unavailable. A trusted definition cannot manufacture an observation or turn logical budgets into an RSS guarantee; malformed present metadata does not widen limits. Changes still require a rollout, with the existing boot view and global configuration-read permissions. No runtime editor, new operational switch or ENV-only setting is added.

m7gtw[email protected]