Skip to content

Write bigger chunks to ram_file #136

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

Merged
merged 3 commits into from
Nov 3, 2021

Conversation

binarin
Copy link
Contributor

@binarin binarin commented Oct 13, 2021

ram_file is implemented as a port driver, and has quiet a significant overhead if every single series is emitted separately.

What happens here is that bigger chunk is collected before writing to ram_file. Chunk is collected using binary append, in such a way that is can benefit from binary append optimization in ERTS.

One nice side-effect of collecting binaries is that a lot of iolists in the hottest code path are no longer created, putting significantly
less pressure on the garbage collector.

Observed performance gains can be as high as 20 times (700k metrics emitted by RabbitMQ went from 2 minutes to 5 seconds). Such big difference can be mostly attributed to garbage collection overhead (for some reason it's non-linear in the number of metrics), but profiling shows that 20% improvement is there even without accounting for gc.

`ram_file` is implemented as a port driver, and has quiet a
significant overhead if every single series is emitted separately.

What happens here is that bigger chunk is collected before writing to
ram_file. Chunk is collected using binary append, in such a way that
is can benefit from binary append optimization in ERTS.

One nice side-effect of collecting binaries is that a lot of iolists
in the hottest code path are no longer created, putting significantly
less pressure on the garbage collector.
binarin added a commit to binarin/prometheus.erl that referenced this pull request Oct 18, 2021
Builds on top of prometheus-erl#136

This is useful when e.g. escaping is not needed, as it is in case with
RabbitMQ, where no escaping is needed because strict rules already
apply to names.

This change provides not only direct speedup, but also significantly
reduced garbage collection overhead, as for every output line the
proplist with labels and the list with converted `#'LabelPair'{}`'s
are replaced with just a single binary.

Using RabbitMQ as an example, time to produce ~630k metrics went from
~6 to ~3 seconds.

Downside is that it's only compatible with text format, and spec for
`#'LabelPair'{}' is not respected.
@deadtrickster
Copy link
Collaborator

@binarin please look at the pipeleines - some minor code style things

@deadtrickster deadtrickster merged commit 1880b1e into prometheus-erl:master Nov 3, 2021
binarin added a commit to binarin/prometheus.erl that referenced this pull request Nov 3, 2021
Builds on top of prometheus-erl#136

This is useful when e.g. escaping is not needed, as it is in case with
RabbitMQ, where no escaping is needed because strict rules already
apply to names.

This change provides not only direct speedup, but also significantly
reduced garbage collection overhead, as for every output line the
proplist with labels and the list with converted `#'LabelPair'{}`'s
are replaced with just a single binary.

Using RabbitMQ as an example, time to produce ~630k metrics went from
~6 to ~3 seconds.

Downside is that it's only compatible with text format, and spec for
`#'LabelPair'{}' is not respected.
binarin added a commit to binarin/prometheus.erl that referenced this pull request Nov 5, 2021
Builds on top of prometheus-erl#136

This is useful when e.g. escaping is not needed, as it is in case with
RabbitMQ, where no escaping is needed because strict rules already
apply to names.

This change provides not only direct speedup, but also significantly
reduced garbage collection overhead, as for every output line the
proplist with labels and the list with converted `#'LabelPair'{}`'s
are replaced with just a single binary.

Using RabbitMQ as an example, time to produce ~630k metrics went from
~6 to ~3 seconds.

Downside is that it's only compatible with text format, and spec for
`#'LabelPair'{}' is not respected.
deadtrickster pushed a commit that referenced this pull request Nov 5, 2021
Builds on top of #136

This is useful when e.g. escaping is not needed, as it is in case with
RabbitMQ, where no escaping is needed because strict rules already
apply to names.

This change provides not only direct speedup, but also significantly
reduced garbage collection overhead, as for every output line the
proplist with labels and the list with converted `#'LabelPair'{}`'s
are replaced with just a single binary.

Using RabbitMQ as an example, time to produce ~630k metrics went from
~6 to ~3 seconds.

Downside is that it's only compatible with text format, and spec for
`#'LabelPair'{}' is not respected.

Co-authored-by: Alexey Lebedeff <[email protected]>
michaeldjeffrey added a commit to helium/packet-purchaser that referenced this pull request Dec 7, 2021
current reporting takes about 500ms

prometheus-erl/prometheus.erl#136

This might be able to speed us up quite a bit
michaeldjeffrey added a commit to helium/packet-purchaser that referenced this pull request Dec 8, 2021
current reporting takes about 500ms

prometheus-erl/prometheus.erl#136

This might be able to speed us up quite a bit
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants