3 ms·
The ordered one is nice, but I do have to wonder about the efficiency of it. If I read https://blog.ndpar.com/2010/11/10/erlang-selective-receive/ https://blog.
by WJW 3y ago
The ordered one is nice, but I do have to wonder about the efficiency of it. If I read https://blog.ndpar.com/2010/11/10/erlang-selective-receive/ https://blog.ndpar.com/2010/11/10/erlang-selective-receive/ correctly, ALL messages in the save queue are re-delivered after a new message has been matched, so if you are unlucky and happen to hit a poor ordering then you will receive O(N^2) messages when submitting N jobs. Probably fine for 1000 messages like in the example, probably not fine for batches of 1000000 jobs.
- mikhailfranco 3y agoYes, worst case quadratic, but redelivered is not resent. Everything is local to the process. In fact, I think the save queue is just a high water mark index at the head of the mailbox. Processing new messages for an existing receive pattern means matching from the end of the mailbox to the HWM. Redelivering for a new receive pattern means resetting the HWM to 0 and rematching everything. So potentially quadratic in matching, but no overhead of copying.