FWIW, this is what we came up with in a hurry: GitHub - hnc-agency/shq (no docs, no tests, no specs, just the bare implementation ).
Downside: It uses a managing (per queue) gen_server
process, which is what you tried to avoid. However, the gen_server
overhead could be removed if necessary, implementing it as a streamlined special process, but for a quick implementation we went with gen_server
.
Upsides that (should) make up for that are…
- constant time (
O(1)
) access for all operations (both insertion and retrieval, both front and rear) because we avoided theordered_set
table type and usedset
instead - avoiding the (arguably expensive)
erlang:unique_integer
altogether while ensuring queue order - making it work across nodes, ie removing the local node restriction (or rather, this comes for free because we are using a process)
- no need for a named table (but the managing process can be named if you so wish)
- fully OTP compliant, ie it can be used in a supervision tree
Aside from the gen_server
overhead, I believe this is as fast as we can get with the things we already have at our hands, ie without resorting to NIF magic or implementing new functions in ets