Prometheus: stream HTTP responses (a double digit % reduction of both CPU and memory footprint) (backport #14885) #15018
+21
−55
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.
prometheus_text_format:format/1produces a binary of the format for the entire registry. For clusters with many resources, this can lead to large replies from/metrics/[:registry]especially for large registries likeper-object. Instead of formatting the response and then sending it, we can stream the response by taking advantage of the newformat_into/3callback (which needs to be added upstream to theprometheusdep). This usescowboy_req:stream_body/3to stream the iodata asprometheusworks through the registry.This should hopefully be a nice memory improvement. The other benefit is that results are sent eagerly. For a stress-testing example,
make run-brokerrabbitmqctl import_definitions path/to/100k-classic-queues.jsoncurl -s localhost:15692/metrics/per-objectBefore this change
curlwould wait for around 8 seconds and then the entire response would arrive. With this change the results start streaming in immediately.Discussed in #14865
This is an automatic backport of pull request #14885 done by Mergify.