Friday, 22 April 2011

JMS and ActiveMQ's configurations

JMS is kind of important and mature piece of the java server side architecture. It is used in quite a lot of situations.
  • You want to make sure the message will be received but you do not want to wait until it is received :)
  • You want to send a message to multiple targets
  • You do not need an answer immediately and you do not want to overload the target system
Also, in some of these cases it is critical to have the message persisted, while other cases really don't. For example typical business messages require persistence. Even if the server fails, after recovering the disks, you still have the message and sooner or later it will be processed.
A distributed ehcache synchronization really does not need any persistence. If the message is lost because of a power outage, the speed and throughput is much more important than persistence. Being honest I would use RMI for ehcache synchronization rather than JMS but RMI is not a good choice when you have firewalls between your servers. Most software developer does not have a choice, JMS is the standard for all kind of messaging, it is part of JEE/J2EE and most other platforms, it is everywhere.

The market for JMS products is narrowed down to a few big players and some agile small ones. The big players are Apache ActiveMQ and IBM's Websphere MQ. If you look at the google trends graphs of the two products, Websphere is in slow decline while ActiveMQ has a stable hit rate at google search. ActiveMQ generates bigger activity since 2009, while Websphere MQ keeps generating money for IBM.


So, if you want a mainstream JMS server, ActiveMQ is the only choice. I would never recommend IBM software for anyone :-)

The small (but agile) players...

ActiveMQ is blue, RabbitMQ is red, it has a nice activity especially since it is backed by springsource/vmware, and HornetQ is the yellow one.

So I was very interested in ActiveMQ and how hard can we kick into it before it is becoming a bottleneck in the system. I used the default configuration and a single threaded sender and receiver to send and receive a text message and it constantly and reliably did not let through more than 25 messages in the second. This was bad experience of course, one would expect much more than that. So I looked into it, and the default configuration runs with KahaDB and forces the message synced to the disk. I disabled the disk sync and it increased the speed to 300 messages/sec. That is closer to what I would like to see :-)
Another persistence options is JDBC, I used the default derby just for a comparison and it produced 100 messages / sec, still not that bad, it would make some sense to give it a try with MySQL and PostgreSQL. With no persistence at all: 700 messages / second. Not bad...

The default configuration is good for anyone. It is safe but its performance is not that impressive. Some applications do not need this safe operation and you can use another storage options that performs much better. Now if you have the two different need in one application, then it seems that you can not configure each queue to behave differently. They will be all forced to write to disk or all of them will be not synced to disk, so it seems to me that in such cases it is better to have two differently configured ActiveMQ for the two different requirement.

6 comments:

  1. JMS actually allows you to control the persistence on a per message basis. Try changing the delivery mode setting on your JMS producer object before sending the messages.

    ReplyDelete
  2. Hi Hiram,

    Yes absolutely, one should use that. What I am concerned about is how the messages generated by someone else's code get dispatched. Can I control the persistence behavior of those messages as well?

    ReplyDelete
  3. It would be nice a similar test with HornetQ.

    ReplyDelete
  4. Hi Kocka, it possible if you implement a Broker plugin (it allows you to modify all client requests before being processed by the broker), but that's an ActiveMQ specific feature.

    ReplyDelete
  5. Hiram: Thanks for the idea! I think I will look into it, it may be a solution for the problem that I am trying to solve. Being ActiveMQ specific is not a problem.

    ReplyDelete
  6. Hiram: Thanks for this conclusion, i have some questions about your test on disabling disk sync on kahadb : you have use a persistent msg ? if it's yes, each version of activemq that you have used ? can you send me the configuration that you have set for persistence adapter (activemq.xml)?

    For you information, i have tested activemq with PostgreSQL, with persistence : 280 msg /s

    ReplyDelete