Skip to content

[feat] Emitter Pools - #105

Merged
arkgil merged 14 commits into
beam-telemetry:mainfrom
scohen:emitter_pools
Mar 25, 2026
Merged

arkgil merged 14 commits into
beam-telemetry:mainfrom
scohen:emitter_pools

Conversation

@scohen

@scohen scohen commented Apr 3, 2025

Copy link
Copy Markdown
Contributor

During testing at Whatnot, we found that when emitting around 50k metrics per second, the current pool implementation caused the calling processes to stall while waiting for :gen_udp to write data. This stalling caused significant degradation to our application, and eventually caused an outage.

To address this, we came up with the concept of using a pool of emitters. An emitter is a process that contains a socket (either UDP or domain), receives metrics and writes them to a socket. This architecture frees up the calling processes so they can write a metric and not wait on a result. Emitters also allow us to combine metrics so they fill up a UDP packet. The end result, according to our testing, moved us from 50k to 1MM metrics per second.

@scohen

scohen commented Apr 3, 2025

Copy link
Copy Markdown
Contributor Author

I think this PR is significant enough to bump the minor version (or make this the 1.0 release). It should be backwards compatible with the old implementation, and even with the default configuration, should perform better and be safer than the pooled implementation.

@scohen

scohen commented Apr 29, 2025

Copy link
Copy Markdown
Contributor Author

@arkgil PTAL!

@arkgil arkgil left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @scohen! I know it took a while 😅

Comment thread lib/telemetry_metrics_statsd.ex Outdated
Comment thread lib/telemetry_metrics_statsd.ex Outdated
Comment thread mix.exs
Comment thread lib/telemetry_metrics_statsd/options.ex Outdated
Comment thread lib/telemetry_metrics_statsd/options.ex Outdated
Comment thread test/telemetry_metrics_statsd/emitter/congestion_test.exs Outdated
Comment thread test/telemetry_metrics_statsd/emitter/domain_test.exs Outdated
Comment thread test/telemetry_metrics_statsd/emitter/udp_test.exs
Comment thread test/support/helpers.ex Outdated
Comment thread test/telemetry_metrics_statsd_test.exs Outdated
scohen added 7 commits August 1, 2025 09:33
During testing at Whatnot, we found that when emitting around 50k
metrics per second, the current pool implementation caused the calling
processes to stall while waiting for `:gen_udp` to write data. This
stalling caused significant degradation to our application, and
eventually caused an outage.

To address this, we came up with the concept of using a pool of
emitters. An emitter is a process that contains a socket (either UDP
or domain), receives metrics and writes them to a socket. This
architecture frees up the calling processes so they can write a metric
and not wait on a result. Emitters also allow us to combine metrics so
they fill up a UDP packet. The end result, according to our testing,
moved us from 50k to 780k metrics per second.
Adds the emit percentage as a metric. Also added tests
@scohen
scohen requested a review from arkgil August 1, 2025 18:06
@whatyouhide

Copy link
Copy Markdown
Contributor

@arkgil @scohen is this something we're still pursuing?

@arkgil

arkgil commented Mar 12, 2026 via email

Copy link
Copy Markdown
Collaborator

Comment thread test/telemetry_metrics_statsd/emitter/udp_test.exs Outdated
Comment thread test/telemetry_metrics_statsd/emitter/udp_test.exs
Comment thread test/telemetry_metrics_statsd/emitter/udp_test.exs
Comment thread test/telemetry_metrics_statsd/emitter/udp_test.exs Outdated
Comment thread test/telemetry_metrics_statsd/emitter/udp_test.exs Outdated
Comment thread test/telemetry_metrics_statsd/emitter/udp_test.exs Outdated
Comment thread test/telemetry_metrics_statsd/emitter/udp_test.exs Outdated
Comment thread test/telemetry_metrics_statsd/emitter/udp_test.exs Outdated
Comment thread test/telemetry_metrics_statsd/emitter/udp_test.exs Outdated
Comment thread test/telemetry_metrics_statsd/emitter/udp_test.exs Outdated
Comment thread test/telemetry_metrics_statsd/emitter/udp_test.exs Outdated
Comment thread test/telemetry_metrics_statsd/emitter/udp_test.exs Outdated
@scohen

scohen commented Mar 17, 2026

Copy link
Copy Markdown
Contributor Author

5x the scale Steve originally built it for

To be fair, I tested it at a million metrics per second, we're not there yet ;)

@scohen
scohen requested a review from arkgil March 18, 2026 20:31

@arkgil arkgil left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lfg

Comment thread lib/telemetry_metrics_statsd/emitter/congestion.ex Outdated
:ok

{:error, :econnrefused} ->
# TODO: Carrying over socket lib behavior, this seems like something we'd like to know about.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@scohen would you mind removing the comment and the one below? they don't add much without the context of the original socket PR

Normalize errors during initialization emitters via our helpers; also
add an option for starting a non-linked emitter process, which
prevents a crash on startup from taking down the test.
@scohen

scohen commented Mar 23, 2026

Copy link
Copy Markdown
Contributor Author

@arkgil all green!

@arkgil

arkgil commented Mar 25, 2026

Copy link
Copy Markdown
Collaborator

🚀

@arkgil
arkgil merged commit 37b75e5 into beam-telemetry:main Mar 25, 2026
9 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

3 participants