The Novell exteNd Messaging Platform's JMS defines the
JMS_jbmq_Compress
message property, which allows messages to be compressed automatically as part of the send/receive process. While compression is an expensive operation, it may sometimes yield better performance. As an example, if have a slow network connection available or if you are sending very large messages which contain repetitive patterns, compression might give better performance.Another thing to keep in mind when using compression is that on the JMS server, this might help performance since less data need to be stored in the database for persistent messages. The only way to know if compression will help you application is by testing it. This program included here does a simple measurement of sending/receiving compressed and uncompressed messages and prints out the result:
In this example, we first create a large text message with repetitive patterns. Then we send/receive the message fifty times, first without compression and then with compression. The result is printed after each run. You can change the example to use transient messages if that reflects your application better. Creating the sender and the receiver in two different processes might also provide a more realistic result.package compress; import javax.naming.InitialContext; import javax.jms.Queue; import javax.jms.Session; import javax.jms.Message; import javax.jms.TextMessage; import javax.jms.QueueSender; import javax.jms.DeliveryMode; import javax.jms.QueueSession; import javax.jms.QueueReceiver; import javax.jms.MessageListener; import javax.jms.QueueConnection; import javax.jms.QueueConnectionFactory; /** This class does a rough performance comparison of sending/receiving compressed and uncompressed large text messages. */ public class Perf { public static void main(String[] args) throws Exception { | // resolve the queue connection factory and queue from JNDI | InitialContext ctx = new InitialContext(); | QueueConnectionFactory connFactory = (QueueConnectionFactory) | ctx.lookup("queue/connectionFactory"); | Queue queue = (Queue) ctx.lookup("queue/queue0"); | | // create a queue connection | QueueConnection queueConn = connFactory.createQueueConnection(); | | // create the queue session with auto acknowledge | QueueSession session = | queueConn.createQueueSession(false, Session.AUTO_ACKNOWLEDGE); | | // create the sender and receiver | QueueSender sender = session.createSender(queue); | QueueReceiver receiver = session.createReceiver(queue); | | // start the queue connection | queueConn.start(); | | // create a very large text message | String s = "text with lots of repetivive patterns ... "; | for (int i = 0; i < 10; i++) s += s; | Message message = session.createTextMessage(s); | | // record time before starting test | long start = System.currentTimeMillis(); | | // loop to send messages | for (int i = 0; i < 50; i++) | sender.send(message); | | // loop to receive messages | for (int i = 0; i < 50; i++) { | | TextMessage textMessage = (TextMessage) receiver.receive(); | | if (textMessage.getText().length() != s.length()) | | throw new Exception("wrong message: " + textMessage); | } | | // record time after test finished | long stop = System.currentTimeMillis(); | | // print result | System.out.println("without compression: " + (stop-start) + " ms"); | | // enable compression | message.setBooleanProperty("JMS_jbmq_Compress", true); | | // record time before starting test | start = System.currentTimeMillis(); | | // loop to send messages | for (int i = 0; i < 50; i++) | sender.send(message); | | // loop to receive messages | for (int i = 0; i < 50; i++) { | | TextMessage textMessage = (TextMessage) receiver.receive(); | | if (textMessage.getText().length() != s.length()) | | throw new Exception("wrong message: " + textMessage); | } | | // record time after test finished | stop = System.currentTimeMillis(); | | // print result | System.out.println("with compression : " + (stop-start) + " ms"); | | queueConn.close(); } }
Copyright © 2000-2003, Novell, Inc. All rights reserved. |