Do not materialise labels when comparing certs #256
Merged
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.
Hey,
similar to some other issues submitted recently, we faced OOM kills when running
the exporter with a high number of k8s secrets. This PR seems to resolve #255 (the issue contains a reproducer).
While I thought the issue was the extremely memory intensive method
getLabels
, itwas in a way just a part of the issue. While this method does allocate heavily,
the main problem is that the exporter itself is slow. And since it doesn't have a
context, it is not cancelled and many concurrect collections happen, all allocating
and the process slowly gets OOM killed as memory mounts.
The new codebase allows for much faster parsing of certs (or, more specifically, their
deduplication). This then makes collection pretty much instant and no memory gets accumulated.
Here's how this looked and how it looks now with the fix:
High level perf stats
Original memory profile (when just parsing certs):
New memory profile:
Benchmark comparison (before/after):
Changes made
trimComponents
function that exits early in case we don't trim components (and thus don't allocate a slice of strings, dopath.Join
etc.)fmt.Sprintf
in the metric construction to save ourselves an allocationgetLabels
calls in the deduplication path - and inlined all the comparisons without allocating amap
- this is the meat of this PRI have some other changes drafted, but they have relatively low impact. Here are some numbers on the
trimComponents
part, which was perhaps the biggestoffendor after the
getLabels
stuff was sorted.