activemq-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Charles Anthony <charles.anth...@hpdsoftware.com>
Subject RE: ThroughPut : Small vs Large Messages
Date Thu, 22 Jun 2006 13:51:17 GMT
These tests (with the odd differences) were on our LAN.

I've appended the (nasty) code to this email - I'm sure it's not relvant,
but just in case...

Cheers,

Charles.

public class CheckActiveMQAccess {
  protected String activeMQUrl;
  public static final int MS_PER_NS = 1000000;

  public CheckActiveMQAccess(String activeMQUrl) {
    this.activeMQUrl = activeMQUrl;
  }

  public void performCheck(int numberOfCharacters, int iterations) {
    System.out.println("URL           : " + activeMQUrl);
    System.out.println("Message Size  : " + numberOfCharacters);
    System.out.println("Message Count : " + iterations);
    System.out.print("Connecting ...");
    ConnectionFactory factory = new
ActiveMQConnectionFactory(ActiveMQConnection.DEFAULT_USER,
ActiveMQConnection.DEFAULT_PASSWORD, activeMQUrl);
    ActiveMQConnection conn = null;
    try {
      conn = (ActiveMQConnection) factory.createConnection();
      conn.start();
      System.out.println(" Connected");

      Session session = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);

      TemporaryQueue theQueue = session.createTemporaryQueue();


      StopWatch overallTimer = new StopWatch();
      overallTimer.start();

      String message = createRandomString(numberOfCharacters);

      MessageConsumer consumer = session.createConsumer(theQueue);
      int totalBytes = 0;
      for (int i = 0; i < iterations; i++) {

        long nanoStart = Utils.nanoTime();

        totalBytes += sendAndReceive(session, theQueue, message, consumer);
        long nanoStop = Utils.nanoTime();

        long time = (nanoStop - nanoStart) / MS_PER_NS;
        System.out.println("Message " + (i + 1) + " took " + time + " ms");
      }
      overallTimer.stop();

      System.out.println("Total Bytes Sent : " + totalBytes);
      System.out.println("Total Time       : " + overallTimer);
      long bytesPerMs = (totalBytes * 1000) / overallTimer.getTime();
      System.out.println("Bytes per Second : " + bytesPerMs);

      consumer.close();
      session.close();

    } catch (Throwable e) {
      e.printStackTrace();  //To change body of catch statement use Options
| File Templates.
    } finally {

      if (conn != null) {
        try {
          conn.close();
        } catch (JMSException e) {
          //
        }
      }
    }


  }

  private String createRandomString(int numberOfCharacters) {
    StringBuffer sb = new StringBuffer(numberOfCharacters);
    for (int j = 0; j < numberOfCharacters; j++) {
      sb.append((char) ('!' + (char) RandomUtils.nextInt(50)));
    }
    String message = sb.toString();
    return message;
  }

  private int sendAndReceive(Session session, TemporaryQueue theQueue,
String srcMessageContents, MessageConsumer consumer) throws JMSException,
UnsupportedEncodingException {

    BytesMessage messageOut = session.createBytesMessage();

    messageOut.writeBytes(srcMessageContents.getBytes("utf-8"));

    MessageProducer producer = session.createProducer(theQueue);
    producer.send(messageOut, DeliveryMode.NON_PERSISTENT,
producer.getPriority(), producer.getTimeToLive());
    ActiveMQMessageProducer amp = (ActiveMQMessageProducer) producer;


    BytesMessage messageIn = (BytesMessage) consumer.receive();
    byte[] data = new byte[(int) messageIn.getBodyLength()];
    messageIn.readBytes(data);
    String dstMessageContents = new String(data, "utf-8");

    if (!dstMessageContents.equals(srcMessageContents)) {
      System.err.print("Messages don't match");
    }


    producer.close();
    return data.length;
  }


  public static void main(String[] args) {
 
Thread.currentThread().setContextClassLoader(ResourceLocatorService.createCl
assLoader());

    String url = System.getProperty("url");
    if (url == null) {
      Properties props = new Properties();
      try {
        InputStream resourceAsStream =
Thread.currentThread().getContextClassLoader().getResourceAsStream("jms.prop
erties");
        if (resourceAsStream == null) {
          throw new IOException("Couldn't find resource jms.properties on
the classpath");
        }
        props.load(resourceAsStream);
        url = props.getProperty("url");
      } catch (IOException e) {
        System.out.println("Couldn't load jms properties");
        e.printStackTrace();
        System.exit(99);
      }

    }
    int messageSize = Integer.parseInt(System.getProperty("message.size",
"2048"));
    int messageCount = Integer.parseInt(System.getProperty("message.count",
"30"));

    if (url == null) {
      System.out.println("No url");
    } else {
      CheckActiveMQAccess checkActiveMQAccess = new
CheckActiveMQAccess(url);
      checkActiveMQAccess.performCheck(messageSize, messageCount);
    }

  }



-----Original Message-----
From: Rob Davies [mailto:rajdavies@gmail.com]
Sent: 22 June 2006 14:51
To: activemq-users@geronimo.apache.org
Subject: Re: ThroughPut : Small vs Large Messages


charles - this is a bit odd - are you doing the round trip through  
the VPN or on your local network or box ?

cheers,

Rob

On 22 Jun 2006, at 14:15, Charles Anthony wrote:

> Oh well - I tried that but to no avail.
>
> I've just dumped the size of our messages (ObjectMessage, so I just
> serialized the object to a byte[] and took the length - I'm sure  
> it's a bit
> out, as I imagine there is some overhead for the wire-format - but  
> not by a
> huge amount) and 98% are > 2K anyway, so I've just set the default  
> messages
> size in the diagnostic tool to 2k.
>
> Cheers,
>
> Charles.
>
> -----Original Message-----
> From: James Strachan [mailto:james.strachan@gmail.com]
> Sent: 22 June 2006 14:19
> To: activemq-users@geronimo.apache.org
> Subject: Re: ThroughPut : Small vs Large Messages
>
>
> Yeah
>
> On 6/22/06, Charles Anthony <charles.anthony@hpdsoftware.com> wrote:
>> Thanks - would that be the TCP_NODELAY jobby ?
>>
>> -----Original Message-----
>> From: James Strachan [mailto:james.strachan@gmail.com]
>> Sent: 22 June 2006 11:30
>> To: activemq-users@geronimo.apache.org
>> Subject: Re: ThroughPut : Small vs Large Messages
>>
>>
>> It could be the Nagler kicking in - i.e. it might take a little while
>> for the TCP buffers to be flushed to the network for smaller  
>> messages.
>> You can tune TCP to enable/disable waiting for complete tcp buffers
>> before actually sending it to the network - its a throughput v  
>> latency
>> tradeoff setting.
>>
>> On 6/22/06, Charles Anthony <charles.anthony@hpdsoftware.com> wrote:
>>> Hi,
>>>
>>> We use AMQ (4) as the client/server transport in our system. For  
>>> some of
>> our
>>> clients, we host the application at our site, and though connect
> remotely
>>> via VPN. Sometimes, we (well, usually they) have trouble setting  
>>> up the
>> VPN
>>> and setting firewall configs etc - so I am just knocking together a
> little
>>> noddy diagnostics program - i.e. connect to the AMQ server, create a
> temp
>>> queue, create a producer, create a consumer, send and receive a  
>>> load of
>>> messages.
>>>
>>> All well and good.
>>>
>>> I thought I'd go a bit crazy, then, and try and work out message
>> throughput
>>> based on message size (i.e. send & reveive A x byte[B] => bytes  
>>> sent =
>> A*B,
>>> bytes-per-second= A*B/num-secs) - not as a real measurement, but  
>>> more as
>>> wavy-hand type uide.
>>> I've turned async send off for this diagnostic thingy, and  
>>> messages are
>> sent
>>> NON_PERSISTENT.
>>>
>>> Here's the weird thing.
>>>
>>> If send small messages ( < 1300 ish bytes), I am getting  
>>> roundtrip of
>> approx
>>> 200 ms
>>> If send larger messages ( > 1300 ish bytes - say 2048), I am getting
>>> roundtip of < 15 ms
>>>
>>>
>>> Is there a reasonable explanation for this ? Maybe compression  
>>> kicking
> in
>> ?
>>> I'm just a bit befuddled.
>>>
>>> Cheers,
>>>
>>> Charles.
>>>
>>>
>>> ___________________________________________________________
>>> HPD Software Ltd. - Helping Business Finance Business
>>> Email terms and conditions: www.hpdsoftware.com/disclaimer
>>>
>>>
>>>
>>
>>
>> --
>>
>> James
>> -------
>> http://radio.weblogs.com/0112098/
>>
>>
>> ___________________________________________________________
>> HPD Software Ltd. - Helping Business Finance Business
>> Email terms and conditions: www.hpdsoftware.com/disclaimer
>>
>>
>>
>
>
> -- 
>
> James
> -------
> http://radio.weblogs.com/0112098/
>
>
> ___________________________________________________________
> HPD Software Ltd. - Helping Business Finance Business
> Email terms and conditions: www.hpdsoftware.com/disclaimer
>
>



___________________________________________________________
HPD Software Ltd. - Helping Business Finance Business
Email terms and conditions: www.hpdsoftware.com/disclaimer 



Mime
View raw message