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

Dmitry Demeshchuk demeshchuk@REDACTED
Fri Apr 11 02:02:42 CEST 2014


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.

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}.
3. The process itself (on its own side) does a selective receive like that:

receive
    {ManageRef, From, Msg} -> handle_call(From, Msg, State)
after 0 ->
    receive
        Msg -> gen_server_like_dispatch_msg(Msg)
    end
end

This could potentially help with sending managing messages to the processes
that may have overloaded inbox with thousands of messages. Say, we see that
the process gets overloaded and we send an operational message of some kind
("discard the entire inbox", for example).

Thoughts?

-- 
Best regards,
Dmitry Demeshchuk
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20140410/d04a093d/attachment.htm>


More information about the erlang-questions mailing list