A Lightweight Alternative to ApacheMQ or RabbitMQ: OCamlMQ
Join the DZone community and get the full member experience.Join For Free
Download Forrester’s “Vendor Landscape, Application Performance Management” report that examines the evolving role of APM as a key driver of customer satisfaction and business success, brought to you in partnership with BMC.
Because ActiveMQ and RabbitMQ (with STOMP adapters) didn't work the way Fernández needed, he created created ocamlmq. The problems he ran into included excessive memory footprint, performance issues with ApacheMQ's scalable storage backends (KahaDB, JDBC), and performance issues with RabbitMQ's topic message dispatch. Fernández says the memory footprint for ocamplmq is under 3MB at startup while ApacheMQ is over 120MB. He also mentions that RabbitMQ was doing a linear scan of the subscription table per dispatch during its topic message dispatch.
ocamlmq can scale over arbitrarily large numbers of queues with constant memory usage, and it also has strong message saving guarantees. It features message priorities and a per-subscription prefetch limit for queue messages. There is error handling and ACK timeout, so if a subscriber doesn't ACK a message after its timeout, the message will be sent to a different subscriber. If a subscriber dies and its connection expires, messages will also be re-sent automatically.
Millions of subscriptions cause no problems for ocamlmq. It also has topic subscriptions with prefix matching, and simple extensions within the STOMP protocol that can report the number of messages in a queue and the subscribers to a queue or topic. ocamlmq does have a few limitations outside of its intended domain, which is persistent queues and transient topic destinations. It's not designed to perform well when scaled beyond a thousand simultaneous connections and there is no flow control for topic messages (in the proper use case, topics are small and processed fast). ocamlmq currently implements PostgreSQL's backend which can only persist a few thousand messages per second, but it allows message bursts of more than 50k per second in async mode. It also doesn't allow very high message rates (20k/s on 3GHz AMD64).
However, ocamlmq is highly scalable, and it can support millions of queues and topic subscriptions with a low memory footprint. It usually only needs around 150 bytes per subscription. Remember, ActiveMQ requires 120MB on startup. Queries have no additional memory cost, so you are free to use plenty without regard for memory.
The ocamlmq source code can be found on GitHub. You'll need a working OCaml environment and three other libraries.