-
Notifications
You must be signed in to change notification settings - Fork 95
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
APCng storage - avoid worst-case memory usage in buildPermutationTree #123
base: main
Are you sure you want to change the base?
Conversation
@@ -539,10 +530,9 @@ private function getValues(string $type, array $metaData): array /** @phpstan-ig | |||
if (isset($metaData['buckets'])) { | |||
$metaData['buckets'][] = 'sum'; | |||
$labels[] = $metaData['buckets']; | |||
$metaData['labelNames'][] = '__histogram_buckets'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since I don't use the number of label names anymore, I removed that parameter from buildPermutationTree and removed this line as it seemed unused. I don't see any change in the output for histograms but if this actually used then I can re-add it.
Signed-off-by: Josh Hoffer <jhoffer@datava.com>
This would be great to land, we are hitting the PHP limit as well. |
I've tested a copy of this PR and it works well to reduce memory usage with histograms |
The peak memory usage of the APCng storage adapter while collecting the metrics for display is currently always the worst-case for the cardinality of the metric label values.
This change replaces the buildPermutationTree implementation with a (cartesian product) generator which avoids keeping every metric label value permutation in memory at once. This can reduce peak memory usage by orders of magnitude for metrics with high cardinality but sparse actual usage. This helps avoid exceeding the PHP memory_limit.
Besides the reduced memory usage, I haven't seen much of a difference in how long
buildPermutationTree
takes to run. (To improve that, only the actually used metric label pairs could be to tracked separately to avoid building the permutations completely.)