GenServer.call latency measurement vs Telemetry instrumentation: selecting an accurate approach
0 reputation · 14 Sept 2022, 17:15 UTC
0 reputation · 14 Sept 2022, 17:15 UTC
When a GenServer receives a high‑frequency synchronous request, the round‑trip time of GenServer.call/3 can become a performance bottleneck. Two documented ways to capture this latency are :timer.tc/1 (or :erlang.monotonic_time/0) and Telemetry events emitted by the BEAM runtime. Each technique has subtle interactions with the scheduler, message queue, and measurement overhead.
Using :timer.tc gives a raw time span in microseconds but adds a function call for every measurement, which can itself influence the observed latency. Telemetry, on the other hand, emits events that can be collected by handlers; while the event payload is lightweight, the handler code and any downstream processing may introduce additional delay. Moreover, the BEAM scheduler flags (+P, +Qw, +sbwt) can change preemption behavior, affecting both measurement methods independently of the GenServer logic.
Deciding which method to use before optimising the GenServer is therefore non‑trivial. The goal is to obtain a trustworthy baseline that reflects the true cost of a call under realistic load, without the measurement itself becoming the bottleneck.
:timer.tc skew the latency measurement for a GenServer handling thousands of calls per second?:timer.tc approach?A thoughtful contribution can make all the difference. Be the first to share one.
Use comments to ask for clarification. Post a solution as an answer.
No question comments on this page.