Debian Codegraph @

processor/memorylimiterprocessor/README.md

raw
1 # Memory Limiter Processor
2
3 <!-- status autogenerated section -->
4 | Status | |
5 | ------------- |-----------|
6 | Stability | [alpha]: profiles |
7 | | [beta]: traces, metrics, logs |
8 | Distributions | [core], [contrib], [k8s] |
9 | Issues | [![Open issues](https://img.shields.io/github/issues-search/open-telemetry/opentelemetry-collector?query=is%3Aissue%20is%3Aopen%20label%3Aprocessor%2Fmemorylimiter%20&label=open&color=orange&logo=opentelemetry)](https://github.com/open-telemetry/opentelemetry-collector/issues?q=is%3Aopen+is%3Aissue+label%3Aprocessor%2Fmemorylimiter) [![Closed issues](https://img.shields.io/github/issues-search/open-telemetry/opentelemetry-collector?query=is%3Aissue%20is%3Aclosed%20label%3Aprocessor%2Fmemorylimiter%20&label=closed&color=blue&logo=opentelemetry)](https://github.com/open-telemetry/opentelemetry-collector/issues?q=is%3Aclosed+is%3Aissue+label%3Aprocessor%2Fmemorylimiter) |
10
11 [alpha]: https://github.com/open-telemetry/opentelemetry-collector/blob/main/docs/component-stability.md#alpha
12 [beta]: https://github.com/open-telemetry/opentelemetry-collector/blob/main/docs/component-stability.md#beta
13 [core]: https://github.com/open-telemetry/opentelemetry-collector-releases/tree/main/distributions/otelcol
14 [contrib]: https://github.com/open-telemetry/opentelemetry-collector-releases/tree/main/distributions/otelcol-contrib
15 [k8s]: https://github.com/open-telemetry/opentelemetry-collector-releases/tree/main/distributions/otelcol-k8s
16 <!-- end autogenerated section -->
17
18 ## Overview
19
20 The memory limiter processor is used to prevent out of memory situations on
21 the collector. Given that the amount and type of data the collector processes is
22 environment-specific and resource utilization of the collector is also dependent
23 on the configured processors, it is important to put checks in place regarding
24 memory usage.
25
26 ## Functionality
27
28 The memory limiter processor performs periodic checks of memory
29 usage and will begin refusing data and forcing GC to reduce
30 memory consumption when defined limits have been exceeded.
31
32 The processor uses soft and hard memory limits. The hard limit is defined via the
33 `limit_mib` configuration option, and is always above or equal
34 to the soft limit. The difference between the soft limit and hard limit is defined via
35 the `spike_limit_mib` configuration option.
36
37 The processor will enter memory limited mode and will start refusing the data when
38 memory usage exceeds the soft limit. This is done by returning errors to the preceding component
39 in the pipeline that made the ConsumeLogs/Trace/Metrics function call.
40
41 In memory limited mode the error returned by ConsumeLogs/Trace/Metrics function is a
42 non-permanent error. When receivers see this error they are expected to retry sending
43 the same data. The receivers may also apply backpressure to their own data sources
44 in order to slow the inflow of data into the Collector, and to allow memory usage
45 to go below the set limits.
46
47 > Warning: Data will be permanently lost if the component preceding the memory limiter
48 > in the telemetry pipeline does not correctly retry sending data after it has
49 > been refused by the memory limiter.
50 > We consider such components to be incorrectly implemented.
51
52 When the memory usage is above the hard limit the processor will additionally
53 force garbage collection to be performed.
54
55 Normal operation is resumed when memory usage drops below the soft limit, meaning data
56 will no longer be refused and the processor won't force garbage collection to
57 be performed.
58
59 ## Best Practices
60
61 Note that while the processor can help mitigate out of memory situations,
62 it is not a replacement for properly sizing and configuring the
63 collector. Keep in mind that if the soft limit is crossed, the collector will
64 return errors to all receive operations until enough memory is freed. This may
65 eventually result in dropped data since the receivers may not be able to
66 retry the data indefinitely.
67
68 It is highly recommended to configure the `GOMEMLIMIT`
69 [environment variable](https://pkg.go.dev/runtime#hdr-Environment_Variables) as well
70 as the `memory_limiter` processor on every collector. `GOMEMLIMIT` should be set to
71 80% of the hard memory limit of your collector. For the `memory_limiter` processor, the
72 best practice is to add it as the first processor in a pipeline. This is to ensure that backpressure
73 can be sent to applicable receivers and minimize the likelihood of dropped data when the
74 `memory_limiter` gets triggered.
75
76 The value of the `spike_limit_mib` configuration option should be selected in a way
77 that ensures that memory usage cannot increase by more than this value within a single
78 memory check interval. Otherwise, memory usage may exceed the hard limit, even if temporarily.
79 A good starting point for `spike_limit_mib` is 20% of the hard limit. Bigger
80 `spike_limit_mib` values may be necessary for spiky traffic or for longer check intervals.
81
82
83 ## Configuration
84
85 Please refer to [memorylimiter.go](../../internal/memorylimiter/memorylimiter.go) for the config spec.
86
87 The following configuration options **must be changed**:
88 - `check_interval` (default = 0s): Time between measurements of memory
89 usage. The recommended value is 1 second.
90 If the expected traffic to the Collector is very spiky then decrease the `check_interval`
91 or increase `spike_limit_mib` to avoid memory usage going over the hard limit.
92 - `limit_mib` (default = 0): Maximum amount of memory, in MiB, targeted to be
93 allocated by the process heap. Note that typically the total memory usage of
94 process will be about 50MiB higher than this value. This defines the hard limit.
95 - `spike_limit_mib` (default = 20% of `limit_mib`): Maximum spike expected between the
96 measurements of memory usage. The value must be less than `limit_mib`. The soft limit
97 value will be equal to (limit_mib - spike_limit_mib).
98 The recommended value for `spike_limit_mib` is about 20% `limit_mib`.
99 - `limit_percentage` (default = 0): Maximum amount of total memory targeted to be
100 allocated by the process heap. This configuration is supported on Linux systems with cgroups
101 and it's intended to be used in dynamic platforms like docker.
102 This option is used to calculate `memory_limit` from the total available memory.
103 For instance setting of 75% with the total memory of 1GiB will result in the limit of 750 MiB.
104 The fixed memory setting (`limit_mib`) takes precedence
105 over the percentage configuration.
106 - `spike_limit_percentage` (default = 20% of `limit_percentage`): Maximum spike expected between the
107 measurements of memory usage. The value must be less than `limit_percentage`.
108 This option is used to calculate `spike_limit_mib` from the total available memory.
109 For instance setting of 25% with the total memory of 1GiB will result in the spike limit of 250MiB.
110 This option is intended to be used only with `limit_percentage`.
111
112 Examples:
113
114 ```yaml
115 processors:
116 memory_limiter:
117 check_interval: 1s
118 limit_mib: 4000
119 spike_limit_mib: 800
120 ```
121
122 - Hard limit will be set to **4000 MiB**.
123 - Soft limit will be set to 4000 - 800 = **3200 MiB**.
124
125 ```yaml
126 processors:
127 memory_limiter:
128 check_interval: 1s
129 limit_percentage: 80
130 spike_limit_percentage: 15
131 ```
132
133 On a machine with 1000 MiB total memory available:
134
135 - Hard limit will be set to 1000 * 0.80 = **800 MiB**.
136 - Soft limit will be set to 1000 * 0.80 - 1000 * 0.15 = 1000 * 0.65 = **650 MiB**.
137
138 Refer to [config.yaml](../../internal/memorylimiter/testdata/config.yaml) for detailed
139 examples on using the processor.