Sunday, November 27, 2005

During the Code Reviews we had past couple of weeks I got a chance to look back at how we've done JMS development. I’d like to share what I’ve learnt with u guys.

One thing we noted during the reviews is that we have not paid enough attention at all to optimization of JMS. And by the comments I found in many forums this is the norm in many projects. So from now on I’m determined to pay more attention to performance whenever I do JMS related development :).

Before dwelling in to the tips I’d like to note down the basic steps of getting JMS to work.

  1. Lookup JMS connection factory
  2. Create connection & session
  3. Lookup destination (Queue or Topic)
  4. Create producers or consumers
  5. Create Msg
  6. Send or Receive Msgs

Now let’s see what we can do to improve our JMS related work. Of course I’ve not tried all of them and would like to here more about the implementation aspects of these from you guys. (Specially points 6 and 9)

  1. Close Resources (Connections, Sessions, Producers, Consumers) in a finally block
  2. Start Connections after starting producer/consumer
  3. Always start consumers before the producers to stop initial messages getting queued
  4. Choose DUPS_OK_ACKNOWLEDGE or AUTO_ACKNOWLEDGE unless it’s really necessary to use CLIENT_ACKNOWLEDGE
  5. Choose Non-durable messages wherever possible to avoid persistency overhead
  6. Process messages concurrently through a ConnectionConsumer using server session pool where each session in the pool would execute separate message concurrently (I think the implementation of this is Vendor specific. Any ideas?)
  7. Set the TimeToLive value as low as feasible (default is for messages to never expire).
  8. Configure number of message driven beans by specifying instance pool size in jboss.xml file.
  9. Use separate transactional sessions and non-transactional sessions for transactional and non-transactional messages.
Post a Comment