[erlang-questions] Abusing OTP-8623 for high-priority messages

Björn Gustavsson bjorn@REDACTED
Fri Apr 11 11:01:23 CEST 2014

On Fri, Apr 11, 2014 at 2:02 AM, Dmitry Demeshchuk <demeshchuk@REDACTED> wrote:
> Hi list,
> Today (yeah, just a couple years have passed since R14A) I learned about
> OTP-8623, which allows to do selective receive for messages that contain a
> known reference with O(1) complexity.

Yes, that is basically how it was described in
the release note and how it works in practice.

It is implemented by not looking at the first
part of the message queue that contain
messages received before the reference
was created. In practice, there should only
be a small number of new messages
received after the creation of the reference,
so in practice we have O(1) complexity for
reading out the message.

> Which made me think: what if we make a gen_server'ish process that:
> 1. Creates a reference that is being passed along with the pid, meaning, our
> start_link returns {ok, {Pid, ManageRef}} or something like that. ManageRef
> is actually created within the new process inside init/1 or such.
> 2. Introduce an operation named priority_call, which, basically, sends
> something like {ManageRef, {Pid, Ref}, Msg}.

Apart from the fact that the optimization cannot
at all be applied in this context because it is a
compiler optimization, it would not help at all
because the reference is created when the
process queue is empty, so there are no messages
that can be skipped.

Björn Gustavsson, Erlang/OTP, Ericsson AB

More information about the erlang-questions mailing list