Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Priority Messages #9269

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

rickard-green
Copy link
Contributor

@rickard-green rickard-green commented Jan 7, 2025

Reference implementation for EEP 76 (pull request 73) on the eep repository.

The message queue (MQ) can now begin with a priority message queue (PMQ)
where priority messages can be appended. The priority message queue is
identified using a priority message queue start marker (PMQS) and a priority
message queue end marker (PMQE). When a priority message is received it is
inserted just before the PMQE marker.

MQ -> PMQS -> PrioMsg1 -> ... -> PrioMsgN -> PMQE -> Msg1 -> ... -> MsgN

The receive expression will try to match messages from the beginning of
the MQ going through the messages in PMQ one by one continuing with
non-priority messages when it has reached the end of the PMQ.

The selective receive optimization will continue to work. When there are
any receive markers present, an incoming priority message will be
scanned for receive marker references. If not found, the receive can
continue as usual. If a reference found in the priority message corresponds
to the currently used receive marker, the priority message will be matched
against before continuing with the next ordinary message.

If a priority message contains a reference corresponding to a receive
marker and the receive marker is used in multiple receive expressions,
the second and following receive expressions will have to scan the whole
PMQ before continuing to the location of the receive marker. A PMQ receive
marker could be inserted preventing this. However, the PMQ is expected to
be small, and it is quite unexpected that a reference is part of a priority
message, so this has not been implemented.
The action performed when an ordinary message is received, is to append it
to the end of the message queue. When receiving a priority marked message
that action might not be taken, but instead an alternate action might be
taken, i.e, the message might be appended to the end of the priority message
queue. There currently exist one type of alternate action messages, namely
messages sent using an alias.

This commit generalize the alias message passing functionality to alternate
action message passing which can be used by priority messages as well as
alias messages (and potentially other future alternate action messages).

Both local and distributed alternate action messages are supported.
This commit introduce functionality for registering messages that should
be accepted as priority messages. Currently these types of messages can
be handled as priority messages:

* Priority marked messages (sent using the priority option of the send/3
  BIF). The receiver registers a pid for which priority marked messages will
  be accepted. If the priority message is sent from the registered process,
  it will be accepted as a priority message; otherwise, as an ordinary
  message.
* Exit messages. The receiver registers a pid or port for which exit signals
  converted to exit messages should be treated as priority messages. Both
  exit messages resulting from a broken link as well as exit messages
  resulting from a call to the exit/2 BIF will be accepted as priority
  messages. Other exit messages will be treated as ordinary messages.
* Monitor messages, e.g., 'DOWN' messages. The receiver register a monitor
  reference for which the corresponding monitor message will be treated
  as a priority message. Other monitor messages will be treated as ordinary
  messages.

With this commit priority messages will also actually be delivered into the
priority message queue implemented in an earlier commit.
@rickard-green rickard-green added team:VM Assigned to OTP team VM feature labels Jan 7, 2025
@rickard-green rickard-green self-assigned this Jan 7, 2025
@potatosalad
Copy link
Contributor

potatosalad commented Jan 8, 2025

I really like the consolidation of the various dist operations for sending a message down to DOP_ALTACT_MSG_SEND 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature team:VM Assigned to OTP team VM
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants