Don't rebuild textfile metricsfamily help text for the same name every time #3175
+6
−0
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This "optimization" shouldn't really be necessary in 99.99..% cases, but we recently ran into a memory usage issue because we had a huge number of processes dumping a few of the same metrics into their own textfile collector paths. Because this builds a help text for metricsfamily that is comprised of the names of all files with that same metric, this blew up the memory usage of building and storing all those help texts. So this change caches the help text for a given mf.Name, and doesn't recompute/store it every time.
To test the memory usage change, I dumped 5000 textfiles into a directory, and checked the process memory usage with and without this change. Before the change, node exporter reported
process_resident_memory_bytes 3.608977408e+09
, or >3G of memory. After this it was onlyprocess_resident_memory_bytes 3.0969856e+07
, or ~30M.