Collector Memory and Garbage Collection
The OpenTelemetry Collector is a Go program. How much memory it uses depends on the data passing through it and on when the Go garbage collector (GC) runs. Five settings decide whether a traffic spike ends in refused data, a busy GC, or an OOM kill:
- the container's memory limit,
- the
memory_limiterprocessor, GOMEMLIMIT,GOGC,GOMAXPROCSand the CPU limit.
This page explains what each one does and what changing it does, so you can tune them for your own traffic. The values in the examples are starting points; the collector's own telemetry tells you how to adjust them.
Time to Complete
15-20 minutes
How the Settings Fit Together
Four of these are memory thresholds, stacked from the top down:
- The container memory limit is the hard ceiling. Cross it and the kernel
kills the process (
OOMKilled, exit code 137). - The hard limit of
memory_limitersits below it. Above the hard limit, the processor forces a garbage collection. GOMEMLIMITsits at or just below the hard limit. As memory approaches it, the Go runtime collects garbage more often to stay under it.- The soft limit of
memory_limitersits belowGOMEMLIMIT. Above the soft limit, the processor refuses new data.
From the top down:
container memory limit kernel kills the process (OOMKilled)
memory_limiter hard processor forces a GC
GOMEMLIMIT at or below the hard limit; Go runtime collects more
often to stay below it
memory_limiter soft processor refuses new data with a retryable error
Keep the order soft limit < GOMEMLIMIT ≤ hard limit < container limit. With that order, the processor refuses data first, the runtime collects harder as memory nears the hard limit, and both happen well before the kernel steps in.
Set a Memory Limit
Always run the collector with a memory limit. Without one:
limit_percentageinmemory_limiteris taken of the whole machine's memory, not the collector's share of it.- The upstream Helm chart cannot work out
GOMEMLIMIT. - Nothing stops the collector from using all of the node's memory.
resources:
requests:
memory: 512Mi
limits:
memory: 1Gi
On Linux, memory_limiter reads the limit from the container's cgroup, so the
percentages follow the limit when you change it.
memory_limiter Processor
The
memory_limiter processor
checks memory use every check_interval and acts at two thresholds:
- Hard limit:
limit_percentage(orlimit_mib). Above it, the processor also forces a garbage collection. - Soft limit: the hard limit minus
spike_limit_percentage(orspike_limit_mib). Above it, the processor refuses new data. The receiver gets a retryable error, so clients that retry send the data again later. If you leave the spike limit unset, it defaults to 20% of the hard limit.
processors:
memory_limiter:
check_interval: 1s
limit_percentage: 80 # hard limit
spike_limit_percentage: 20 # soft limit = 80 - 20 = 60
service:
pipelines:
traces:
receivers: [otlp]
processors: [memory_limiter, batch]
exporters: [otlphttp/b14]
Put it first. The README's best practice is to add memory_limiter as the
first processor in every pipeline. Data it refuses then never takes memory in
the processors after it.
What tuning it does:
| Change | Effect |
|---|---|
Raise limit_percentage | More memory before forced GC. Less room between the hard limit and an OOM kill. |
Raise spike_limit_percentage | Lower soft limit. Data is refused earlier, and a burst is less likely to reach the hard limit. |
Lower spike_limit_percentage | The collector accepts more before refusing, but a sudden burst can go past the hard limit before the next check. |
Shorter check_interval | Catches spikes sooner, at the cost of checking more often. |
Size the spike limit to the largest jump in memory you see between two checks.
GOMEMLIMIT
GOMEMLIMIT sets a soft limit on
the total memory the Go runtime uses. As memory gets close to it, the GC runs
more often and memory is freed before it builds up. Without GOMEMLIMIT, the
runtime does not know about the container limit. It lets the heap grow until
the next GC is due, and a spike can carry the heap past the container limit
first.
The memory_limiter README recommends setting GOMEMLIMIT on every
collector, at about 80% of the collector's hard memory limit. Set it as an
environment variable, with a unit such as MiB or GiB:
containers:
- name: otel-collector
env:
- name: GOMEMLIMIT
value: 819MiB # about 80% of the 1Gi limit
resources:
limits:
memory: 1Gi
With the memory_limiter example above, 80% of the container limit puts
GOMEMLIMIT at the hard limit, above the soft limit. Keep it in that range:
- Too low, at or below the soft limit: the GC runs constantly while the processor is still accepting data. The Go GC guide calls this thrashing. The runtime caps GC at about 50% of CPU, so throughput drops instead of the process stopping.
- Too high, above the hard limit or near the container limit: the runtime starts working to stay under it too late to help. The process can also use memory the Go runtime does not know about, and the GC guide suggests leaving 5-10% headroom for that.
GOMEMLIMIT is a soft limit. If the live data in the collector is larger than
the limit, Go lets memory grow past it rather than stop. memory_limiter and
the container limit still need to be in place.
GOGC
GOGC sets how much the heap can grow
after a garbage collection before the next one starts. The default is 100:
the heap can grow by about the size of the live data.
| Change | Effect |
|---|---|
Raise GOGC (for example 200) | Fewer collections and less CPU spent on GC. More memory between collections. |
Lower GOGC (for example 50) | More frequent collections and more CPU spent on GC. A smaller heap. |
With GOMEMLIMIT set, a higher GOGC is a common trade: the GC runs rarely at
low load, and GOMEMLIMIT makes it run more often as memory gets close to the
limit.
Do not set GOGC=off. It turns the garbage collector off until memory reaches
GOMEMLIMIT. The heap then sits close to the limit all the time, so the GC
is collecting near the limit under normal load and there is no headroom left
for a spike. Without GOMEMLIMIT, GOGC=off means no garbage collection at
all.
GOMAXPROCS and CPU Limits
GOMAXPROCS is how many threads run Go code at once. The GC uses these
threads too, so it affects how quickly a collection finishes.
- Go 1.25 and later: On Linux, the runtime
reads the container's CPU limit
and sets
GOMAXPROCSfrom it. It updates the value if the limit changes. A CPU limit is safe for these builds. - Older Go builds:
GOMAXPROCSdefaults to the number of CPUs on the node, not the container's CPU limit. A collector on a 32-core node with a 1-CPU limit runs 32 threads of work in 1 CPU of time. The kernel throttles it, and garbage collection and export stall while it does. Either setGOMAXPROCSto match the CPU limit, or leave the CPU limit off and set a CPU request.
Check the release notes for your collector version to see which Go version built it.
containers:
- name: otel-collector
env:
- name: GOMAXPROCS
value: "2" # match resources.limits.cpu on builds older than Go 1.25
resources:
limits:
cpu: "2"
Setting GOMAXPROCS yourself turns off the runtime's automatic value, Go 1.25
and later included.
Helm Chart Values
Upstream opentelemetry-collector chart
The upstream
opentelemetry-collector chart
has a useGOMEMLIMIT value, true by default. When it is on, the chart sets
GOMEMLIMIT to 80% of resources.limits.memory. It only does so when
resources.limits.memory is set, and the chart sets no resources by default:
useGOMEMLIMIT: true
resources:
limits:
memory: 1Gi # the chart renders GOMEMLIMIT=819MiB
If no memory limit is set, the chart prints a warning after install and does
not set GOMEMLIMIT.
The chart's default configuration puts memory_limiter first in each
pipeline, with limit_percentage: 80 and spike_limit_percentage: 25.
GOMEMLIMIT at 80% then sits at the hard limit, above the soft limit of 55%.
To change the limits, override config.processors.memory_limiter:
config:
processors:
memory_limiter:
check_interval: 1s
limit_percentage: 80
spike_limit_percentage: 20
Scout Collector chart
The Scout Collector chart
(base14/scout-collector) handles GOMEMLIMIT differently by collector type:
agent-collectoranddaemon-collectoruse the upstream chart, soGOMEMLIMITis set to 80% of their memory limits, which the chart sets by default. Change it throughagent-collector.resourcesanddaemon-collector.resources.- Supervised collectors (
scout.supervisor, including the high availability gateway) do not setGOMEMLIMIT. Add it withscout.supervisor.extraEnvs. The list applies to every supervised collector, so pick a value that fits the smallest memory limit among them.
scout:
supervisor:
extraEnvs:
- name: K8S_CLUSTER_NAME
value: my-cluster
- name: GOMEMLIMIT
value: 819MiB # about 80% of the 1Gi default limit
Helm replaces lists rather than merging them, so repeat the entries you
already have, such as K8S_CLUSTER_NAME, when you add GOMEMLIMIT.
The chart's memory_limiter uses limit_percentage: 80 and
spike_limit_percentage: 25, like the upstream chart, so GOMEMLIMIT at 80%
sits at the hard limit here too.
Agents Small, Gateways Wide
Size agents and gateways in different ways:
- Agents and daemons run next to the workloads they collect from. Keep them small, with tight memory limits. A scraping agent cannot share its work by adding replicas, so if it needs more memory, give it a bigger limit or split its scrapes across more agents.
- Gateways receive OTLP and forward it. They are stateless, so scale them out with a HorizontalPodAutoscaler, behind a gRPC-aware (L7) load balancer, instead of giving one replica more memory. Each replica keeps the same memory settings, and more replicas share the load.
See Scaling the collector for when and how to scale, and High Availability for running a gateway with the Scout Collector chart.
Tune with the Collector's Own Telemetry
The collector reports its own telemetry, and that tells you whether the settings on this page fit your traffic. Send it to Scout and start from the OTel Collector Data Flow dashboard (see Troubleshooting Missing Data).
| Signal | What it tells you | What to change |
|---|---|---|
otelcol_processor_memory_limiter_refused_* rising, with otelcol_receiver_refused_* | The soft limit is being hit and data is being refused. | Scale out, raise the memory limit, or lower the spike limit if spikes are small. |
otelcol_process_runtime_heap_alloc_bytes close to GOMEMLIMIT all the time | The GC is working hard to stay under the limit. | Raise the memory limit or scale out. Check GOGC is not off. |
otelcol_process_cpu_seconds high while throughput is flat | CPU is going to GC. | Raise GOMEMLIMIT towards the hard limit, or raise the memory limit. |
otelcol_process_memory_rss near the container limit | Little headroom left before an OOM kill. | Lower GOMEMLIMIT and the memory_limiter limits, or raise the container limit. |
Containers restarting with OOMKilled | Memory went past the container limit. | Check every setting on this page is in place and in order. |
Metric names can carry _total or unit suffixes depending on how the
collector exports its telemetry, so match on the prefix.
Alert on OOM kills. Restarts with reason OOMKilled are the clearest sign
that the memory settings are wrong. On Kubernetes, kube-state-metrics reports
the reason; see
Reasons are here and nowhere else
and the restart alert under
Key Alerts to Configure.
In k8X, a killed container shows
Last state: OOMKilled (exit 137).
Checklist
- A memory limit is set on every collector container
-
memory_limiteris the first processor in every pipeline -
GOMEMLIMITis set, above the soft limit and at or below the hard limit ofmemory_limiter -
GOGCis notoff - On builds older than Go 1.25,
GOMAXPROCSmatches the CPU limit, or there is no CPU limit - Gateways scale out with an HPA; agents stay small
- Collector telemetry is in Scout and OOM kills raise an alert
References
- Memory Limiter Processor
- A Guide to the Go Garbage Collector
- Go runtime environment variables
- Go 1.25 release notes: container-aware GOMAXPROCS
- OpenTelemetry Collector Helm chart
- Collector internal telemetry
Related Guides
- Debugging OTel Pipelines — diagnostic tools and common failure scenarios
- Recommended Collector Configuration — compression, batching, retries and memory limiter
- Kubernetes Helm Setup — installing the Scout Collector chart
- Collector deployment topology — agents, gateways and scaling