No, sorry, I think I wasn’t clear. I don’t want to suggest anything like multiple message queues.
My main point is, that in Erlang you can already fetch messages from your message queue out of order, using selective receive. Semantically, this language feature is enough to solve all the problems EEP 76 lists: first you do a selective receive that matches on the messages that need priority handling with a 0 timeout, and if you find none in the message queue, you pick the next (ordinary) message from the head of the queue.
The problem EEP 76 tries to solve is not that the language doesn’t have a way to handle priority messages out of order, but that their are performance issues with the existing solution when the message queue is long. EEP 76 wants to solve the performance issue by introducing new semantics (inserting priority messages before existing non-priority messages in the queue).
My suggestion is to change nothing about the semantics of message queues, but solve the performance problem. And I tried to say that we can speed up selective receives the same way we can speed up slow SELECT
-s on a large DB table: by indexing the data!
Most of my previous post was about how we could describe indices based on message patterns using existing language features (such as match specifications and the process_flag/2
API), but those are just technical details. The main idea is to leave message sending/receiving semantics unchanged, and add indices to the message queue to speed up selective receives.
The big benefit is that the indices should be configured by the process that will do the selective receives, so you don’t have to modify both the sender and the receiver of the messages to use priority messages instead of regular ones when needed. All the code related to priority-handling of messages (the call to set up message queue indexing and the selective receive statement(s)) would likely stay close to each other, in the same module.