Exporter Go Runtime
If you are running in an environment with limited memory, or you are running a large number of exporters, you may want to control the exporter's usage of memory.
Under normal circumstances, the exporter process will retain OS memory that was used by the Go garbage collector but is no longer needed, in case it may be needed again in the future, unless the host OS is under memory pressure. The result of this behavior (which is the normal behavior of the Go runtime) is that the resident set size will not decrease until the host OS memory is almost all used. Under most circumstances, this will not cause any issues, but if you are in an environment where you need to conserve memory, the following options are provided:
- You may set the
FREE_INTERVAL
environment variable to a Go duration string, e.g.,60s
and run the exporter in debug mode by setting theGODEBUG
environment variable to a value includingmadvdontneed=1
, e.g.,GODEBUG=gctrace=1,madvdontneed=1
. The exporter will call the FreeOSMemory() at the specified interval. This tells the Go runtime to attempt to release memory which is no longer needed. Please note that this does not guarantee that the memory will be released to the OS, but over time you should see the RSS shrink sooner than without these settings. - You may set the
RESTART_INTERVAL
environment variable to a Go duration string, e.g.,10m
. The exporter will restart its own process at the specified iterval (by calling the OSexec
syscall). As no new process is created, the process identifier (PID) does not change, but the machine code, data, heap, and stack of the process are replaced by those of the new program (source: Wikipedia). This has the side effect of freeing the resident set, so that it will return to its original size. - In addition to these, you may also set
GOMAXPROCS
,GOGC
, andGOMEMLIMIT
(see documentation) to further limit the amount of resources that the Go runtime may use.