Forcing immediate mailbox check / reducing receive latency for latency-sensitive processes?

zabrane
Mon, 23 Mar 2026 14:08:19 +0000
Questions / Help

Hi all,

I have a latency-sensitive system where a set of processes sit in
tight receive loops waiting for messages. The messages arrive from
outside the BEAM (via enif_send from a C NIF), and I’ve observed
variable delay between when the message lands in the mailbox and
when the process actually wakes up to match it.

I’m looking for ways to minimize this scheduling gap. What I’ve
explored so far:

process_flag(priority, high): helps but is a permanent
setting, not per-event

process_flag(message_queue_data, off_heap): already using this

+sbwt none / +sfwi 500: tuned, marginal effect

+K true with minimal IO threads

I’m aware of OTP 28’s priority messages (EEP-76), which look very
promising. The ability to have {ready, ...} notifications skip
ahead of any accumulated system messages would be ideal. However,
as far as I can tell, enif_send/4 only accepts an ErlNifPid
and doesn’t support sending to priority aliases or passing the
[priority] option.

My questions:

1. Is there a way to use priority messages from NIF code in
OTP 28? Does enif_send support aliases, or is there a new
NIF API for this?

2. Failing that, has anyone found an effective pattern for
minimizing the delay between enif_send and the target
process’s receive? Any undocumented scheduler hints or
tricks?

3. Would an Erlang-side relay (C sends to pid, Erlang process
forwards to its own priority alias) be worth the extra message
hop, or would the overhead negate the benefit?

Any pointers appreciated, even undocumented or internal mechanisms
are interesting to know about.

Thanks.

18 posts - 8 participants