[jboss-dev-forums] [Design of Messaging on JBoss (Messaging/JBoss)] - Re: Optimisations: A couple of low hanging fruits going for

jmesnil do-not-reply at jboss.com
Wed May 14 11:33:18 EDT 2008


"timfox" wrote : There are a couple of areas for valuable optimisation if anyone would like to take them:
  | 
  | 1)
  | 
  | One is that generating JMS message ids before sending can slow things down significantly (maybe 5%??).
  | 
  | I noticed that if i set producer.setDisableMessageID(true) on the producer before sending performance increases significantly
  | 
  | I am sending 1k non persistent bytes messages from client one my laptop to server on another machine with gigabit lan and i can get about 45K msgs / sec :), but this drops to about 40K or less with disablemessageid set to false
  | 
  | I suspect this is due to the following in JBossMessageProducer:
  | 
  |   | String id = UUID.randomUUID().toString();
  |   | bm.setJMSMessageID("ID:" + id);
  |   | 
  | 
  | which involves generation and two (?) string copies.
  | 

It seems the bottleneck is the generation of the UUID.

When using UUID.randomUUID(), the implementation uses a SecureRandom.
If I use Random instead and creates the UUID with new UUID(rand.nextLong(), nextLong(), the perf increases significantely.

I've isolated this in the following tests:


  |    public void testRandomUUID() throws Exception
  |    {
  |       long start = System.currentTimeMillis();
  |       
  |       for (int i = 0; i < MANY_TIMES; i++)
  |       {
  |          UUID uuid = UUID.randomUUID();
  |          String id = "ID:" + uuid;
  |       }
  |       
  |       long duration = System.currentTimeMillis() - start;
  |       System.out.println(getName() + ": " + duration);      
  |    }
  |    
  |    public void testSecureRandom() throws Exception
  |    {
  |       doManyRandomLongs(new SecureRandom());
  |    }
  | 
  |    public void testRandom() throws Exception
  |    {
  |       doManyRandomLongs(new Random());
  |    }
  | 
  |    public void doManyRandomLongs(Random rand) {
  |       long start = System.currentTimeMillis();
  |       
  |       for (int i = 0; i < MANY_TIMES; i++)
  |       {
  |          UUID uuid = new UUID(rand.nextLong(), rand.nextLong());
  |          String id = "ID:" + uuid;
  |       }
  |       
  |       long duration = System.currentTimeMillis() - start;
  |       System.out.println(getName() + ": " + duration);
  |    }
  | 

When running the loop 1 million times, I've got:
testRandomUUID: 18625
testSecureRandom: 19430
testRandom: 5059

=> using Random.nextLong instead of RandomUUID, we go from 18s to 5s



View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4150792#4150792

Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4150792



More information about the jboss-dev-forums mailing list