[jboss-cvs] JBoss Messaging SVN: r6961 - in trunk/examples/core: embedded and 8 other directories.
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Thu May 21 07:50:03 EDT 2009
Author: timfox
Date: 2009-05-21 07:50:03 -0400 (Thu, 21 May 2009)
New Revision: 6961
Added:
trunk/examples/core/perf/
trunk/examples/core/perf/build.xml
trunk/examples/core/perf/perf.properties
trunk/examples/core/perf/readme.html
trunk/examples/core/perf/server0/
trunk/examples/core/perf/server0/jbm-configuration.xml
trunk/examples/core/perf/server0/jbm-jboss-beans.xml
trunk/examples/core/perf/src/
trunk/examples/core/perf/src/org/
trunk/examples/core/perf/src/org/jboss/
trunk/examples/core/perf/src/org/jboss/core/
trunk/examples/core/perf/src/org/jboss/core/example/
trunk/examples/core/perf/src/org/jboss/core/example/PerfExample.java
trunk/examples/core/perf/src/org/jboss/core/example/PerfListener.java
trunk/examples/core/perf/src/org/jboss/core/example/PerfParams.java
trunk/examples/core/perf/src/org/jboss/core/example/PerfSender.java
trunk/examples/core/perf/src/org/jboss/jms/
trunk/examples/core/perf/src/org/jboss/jms/example/
Modified:
trunk/examples/core/embedded/build.xml
Log:
added perf example
Modified: trunk/examples/core/embedded/build.xml
===================================================================
--- trunk/examples/core/embedded/build.xml 2009-05-21 10:57:20 UTC (rev 6960)
+++ trunk/examples/core/embedded/build.xml 2009-05-21 11:50:03 UTC (rev 6961)
@@ -42,10 +42,11 @@
<target name="run" depends="compile">
- <java classname="org.jboss.core.example.EmbeddedExample" fork="true" resultproperty="example-result">
- <jvmarg value="-Xms50M"/>
- <jvmarg value="-Xmx50M"/>
- <classpath refid="local.classpath"/>
- </java>
+ <java classname="org.jboss.core.example.EmbeddedExample" fork="true" resultproperty="example-result">
+ <jvmarg value="-Xms50M"/>
+ <jvmarg value="-Xmx50M"/>
+ <classpath refid="local.classpath"/>
+ </java>
+
</target>
</project>
Added: trunk/examples/core/perf/build.xml
===================================================================
--- trunk/examples/core/perf/build.xml (rev 0)
+++ trunk/examples/core/perf/build.xml 2009-05-21 11:50:03 UTC (rev 6961)
@@ -0,0 +1,68 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE project [
+ <!ENTITY libraries SYSTEM "../../../thirdparty/libraries.ent">
+ ]>
+
+<!-- =========================================================================================== -->
+<!-- -->
+<!-- JBoss, Home of Professional Open Source -->
+<!-- Copyright 2005, JBoss Inc., and individual contributors as indicated -->
+<!-- by the @authors tag. See the copyright.txt in the distribution for a -->
+<!-- full listing of individual contributors. -->
+<!-- -->
+<!-- This is free software; you can redistribute it and/or modify it -->
+<!-- under the terms of the GNU Lesser General Public License as -->
+<!-- published by the Free Software Foundation; either version 2.1 of -->
+<!-- the License, or (at your option) any later version. -->
+<!-- -->
+<!-- This software is distributed in the hope that it will be useful, -->
+<!-- but WITHOUT ANY WARRANTY; without even the implied warranty of -->
+<!-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -->
+<!-- Lesser General Public License for more details. -->
+<!-- -->
+<!-- You should have received a copy of the GNU Lesser General Public -->
+<!-- License along with this software; if not, write to the Free -->
+<!-- Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA -->
+<!-- 02110-1301 USA, or see the FSF site: http://www.fsf.org. -->
+<!-- -->
+<!-- =========================================================================================== -->
+
+
+<project name="JBoss Messaging Perf Example">
+
+ <import file="../../common/build.xml"/>
+
+ <target name="runSender">
+ <java classname="org.jboss.core.example.PerfSender" fork="true" resultproperty="example-result">
+ <jvmarg value="-Xms512M"/>
+ <jvmarg value="-Xmx512M"/>
+ <jvmarg value="-XX:+UseParallelGC"/>
+ <jvmarg value="-XX:+AggressiveOpts"/>
+ <jvmarg value="-XX:+UseFastAccessorMethods"/>
+ <classpath refid="runtime.classpath"/>
+ </java>
+ </target>
+
+ <target name="runListener">
+ <java classname="org.jboss.core.example.PerfSender" fork="true" resultproperty="example-result">
+ <jvmarg value="-Xms512M"/>
+ <jvmarg value="-Xmx512M"/>
+ <jvmarg value="-XX:+UseParallelGC"/>
+ <jvmarg value="-XX:+AggressiveOpts"/>
+ <jvmarg value="-XX:+UseFastAccessorMethods"/>
+ <classpath refid="runtime.classpath"/>
+ </java>
+ </target>
+
+ <target name="runServer">
+ <java classname="org.jboss.core.example.SpawnedJBMServer" fork="true" resultproperty="example-result">
+ <jvmarg value="-Xms512M"/>
+ <jvmarg value="-Xmx512M"/>
+ <jvmarg value="-XX:+UseParallelGC"/>
+ <jvmarg value="-XX:+AggressiveOpts"/>
+ <jvmarg value="-XX:+UseFastAccessorMethods"/>
+ <classpath refid="runtime.classpath"/>
+ </java>
+ </target>
+
+</project>
\ No newline at end of file
Added: trunk/examples/core/perf/perf.properties
===================================================================
--- trunk/examples/core/perf/perf.properties (rev 0)
+++ trunk/examples/core/perf/perf.properties 2009-05-21 11:50:03 UTC (rev 6961)
@@ -0,0 +1,9 @@
+num-messages=20000
+num-warmup-messages=2000
+message-size=1400
+durable=false
+transacted=false
+batch-size=1000
+drain-queue=true
+queue-name=perfQueue
+throttle-rate=20000
\ No newline at end of file
Added: trunk/examples/core/perf/readme.html
===================================================================
--- trunk/examples/core/perf/readme.html (rev 0)
+++ trunk/examples/core/perf/readme.html 2009-05-21 11:50:03 UTC (rev 6961)
@@ -0,0 +1,92 @@
+<html>
+ <head>
+ <title>JBoss Messaging Performance Example</title>
+ <link rel="stylesheet" type="text/css" href="../../common/common.css">
+ </head>
+ <body>
+ <h1>Performance Example TODO TODO</h1>
+ <br>
+ <p>This example shows you how to send and receive a message to a JMS Queue with JBoss Messaging.</p>
+ <p>Queues are a standard part of JMS, please consult the JMS 1.1 specification for full details.</p>
+ <p>A Queue is used to send messages point to point, from a producer to a consumer. The queue guarantees message ordering between these 2 points.</p>
+ <br>
+ <h2>Example step-by-step</h2>
+ <p><i>To run the example, simply type <code>ant</code> from this directory</i></p>
+ <br>
+ <ol>
+ <li>First we need to get an initial context so we can look-up the JMS connection factory and destination objects from JNDI. This initial context will get it's properties from the <code>client-jndi.properties</code> file in the directory <code>../common/config</code></li>
+ <pre>
+ <code>InitialContext initialContext = getContext();</code>
+ </pre>
+
+ <li>We look-up the JMS queue object from JNDI</li>
+ <pre>
+ <code>Queue queue = (Queue) initialContext.lookup("/queue/exampleQueue");</code>
+ </pre>
+
+ <li>We look-up the JMS connection factory object from JNDI</li>
+ <pre>
+ <code>ConnectionFactory cf = (ConnectionFactory) initialContext.lookup("/ConnectionFactory");</code>
+ </pre>
+
+ <li>We create a JMS connection</li>
+ <pre>
+ <code>connection = cf.createConnection();</code>
+ </pre>
+
+ <li>We create a JMS session. The session is created as non transacted and will auto acknowledge messages.</li>
+ <pre>
+ <code>Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);</code>
+ </pre>
+
+ <li>We create a JMS message producer on the session. This will be used to send the messages.</li>
+ <pre>
+ <code>MessageProducer messageProducer = session.createProducer(topic);</code>
+ </pre>
+
+ <li>We create a JMS text message that we are going to send.</li>
+ <pre>
+ <code>TextMessage message = session.createTextMessage("This is a text message");</code>
+ </pre>
+
+ <li>We send message to the queue</li>
+ <pre>
+ <code>messageProducer.send(message);</code>
+ </pre>
+
+ <li>We create a JMS Message Consumer to receive the message.</li>
+ <pre>
+ <code>MessageConsumer messageConsumer = session.createConsumer(queue);</code>
+ </pre>
+
+ <li>We start the connection. In order for delivery to occur on any consumers or subscribers on a connection, the connection must be started</li>
+ <pre>
+ <code>connection.start();</code>
+ </pre>
+
+ <li>The message arrives at the consumer. In this case we use a timeout of 5000 milliseconds but we could use a blocking 'receive()'</li>
+ <pre>
+ <code>TextMessage messageReceived = (TextMessage) messageConsumer.receive(5000);</code>
+ </pre>
+
+ <li>And finally, <b>always</b> remember to close your JMS connections and resources after use, in a <code>finally</code> block. Closing a JMS connection will automatically close all of its sessions, consumers, producer and browser objects</li>
+
+ <pre>
+ <code>finally
+ {
+ if (initialContext != null)
+ {
+ initialContext.close();
+ }
+ if (connection != null)
+ {
+ connection.close();
+ }
+ }</code>
+ </pre>
+
+
+
+ </ol>
+ </body>
+</html>
\ No newline at end of file
Added: trunk/examples/core/perf/server0/jbm-configuration.xml
===================================================================
--- trunk/examples/core/perf/server0/jbm-configuration.xml (rev 0)
+++ trunk/examples/core/perf/server0/jbm-configuration.xml 2009-05-21 11:50:03 UTC (rev 6961)
@@ -0,0 +1,15 @@
+<configuration xmlns="urn:jboss:messaging"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="urn:jboss:messaging /schema/jbm-configuration.xsd">
+
+
+ <!-- Acceptors -->
+ <acceptors>
+ <acceptor name="netty-acceptor">
+ <factory-class>org.jboss.messaging.integration.transports.netty.NettyAcceptorFactory</factory-class>
+ </acceptor>
+ </acceptors>
+
+ <security-enabled>false</security-enabled>
+
+</configuration>
Added: trunk/examples/core/perf/server0/jbm-jboss-beans.xml
===================================================================
--- trunk/examples/core/perf/server0/jbm-jboss-beans.xml (rev 0)
+++ trunk/examples/core/perf/server0/jbm-jboss-beans.xml 2009-05-21 11:50:03 UTC (rev 6961)
@@ -0,0 +1,17 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<deployment xmlns="urn:jboss:bean-deployer:2.0">
+
+ <!-- The core configuration -->
+ <bean name="Configuration" class="org.jboss.messaging.core.config.impl.FileConfiguration"/>
+
+ <!-- The core server -->
+ <bean name="MessagingServer" class="org.jboss.messaging.core.server.impl.MessagingServerImpl">
+ <constructor>
+ <parameter>
+ <inject bean="Configuration"/>
+ </parameter>
+ </constructor>
+ </bean>
+
+</deployment>
Added: trunk/examples/core/perf/src/org/jboss/core/example/PerfExample.java
===================================================================
--- trunk/examples/core/perf/src/org/jboss/core/example/PerfExample.java (rev 0)
+++ trunk/examples/core/perf/src/org/jboss/core/example/PerfExample.java 2009-05-21 11:50:03 UTC (rev 6961)
@@ -0,0 +1,103 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2005-2008, Red Hat Middleware LLC, and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.core.example;
+
+import org.jboss.common.example.JBMExample;
+import org.jboss.messaging.core.client.ClientConsumer;
+import org.jboss.messaging.core.client.ClientMessage;
+import org.jboss.messaging.core.client.ClientProducer;
+import org.jboss.messaging.core.client.ClientSession;
+import org.jboss.messaging.core.client.ClientSessionFactory;
+import org.jboss.messaging.core.client.impl.ClientSessionFactoryImpl;
+import org.jboss.messaging.core.config.TransportConfiguration;
+import org.jboss.messaging.integration.transports.netty.NettyConnectorFactory;
+
+/**
+ *
+ * A PerfExample
+ *
+ * @author <a href="mailto:tim.fox at jboss.com">Tim Fox</a>
+ *
+ *
+ */
+public class PerfExample extends JBMExample
+{
+ public static void main(String[] args)
+ {
+ new PerfExample().run(args);
+ }
+
+ public boolean runExample() throws Exception
+ {
+ final String perfAddress = "perfAddress";
+
+ final String perfQueueName = "perfQueue";
+
+ ClientSessionFactory factory = null;
+
+ ClientSession session = null;
+
+ try
+ {
+ factory = new ClientSessionFactoryImpl(new TransportConfiguration(NettyConnectorFactory.class.getName()));
+
+ session = factory.createSession();
+
+ session.createQueue(perfAddress, perfQueueName, true);
+
+ ClientProducer producer = session.createProducer(perfAddress);
+
+ ClientMessage message = session.createClientMessage(true);
+
+ message.getBody().writeString("Hello");
+
+ producer.send(message);
+
+ session.start();
+
+ ClientConsumer consumer = session.createConsumer(perfQueueName);
+
+ ClientMessage msgReceived = consumer.receive();
+
+ System.out.println("message = " + msgReceived.getBody().readString());
+
+ consumer.close();
+
+ session.deleteQueue(perfQueueName);
+
+ return true;
+ }
+ finally
+ {
+ if (session != null)
+ {
+ session.close();
+ }
+
+ if (factory != null)
+ {
+ factory.close();
+ }
+ }
+ }
+
+}
Added: trunk/examples/core/perf/src/org/jboss/core/example/PerfListener.java
===================================================================
--- trunk/examples/core/perf/src/org/jboss/core/example/PerfListener.java (rev 0)
+++ trunk/examples/core/perf/src/org/jboss/core/example/PerfListener.java 2009-05-21 11:50:03 UTC (rev 6961)
@@ -0,0 +1,54 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2005-2009, Red Hat Middleware LLC, and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+
+
+package org.jboss.core.example;
+
+/**
+ * A PerfListener
+ *
+ * @author <a href="mailto:tim.fox at jboss.com">Tim Fox</a>
+ *
+ *
+ */
+public class PerfListener
+{
+
+ // Constants -----------------------------------------------------
+
+ // Attributes ----------------------------------------------------
+
+ // Static --------------------------------------------------------
+
+ // Constructors --------------------------------------------------
+
+ // Public --------------------------------------------------------
+
+ // Package protected ---------------------------------------------
+
+ // Protected -----------------------------------------------------
+
+ // Private -------------------------------------------------------
+
+ // Inner classes -------------------------------------------------
+
+}
Added: trunk/examples/core/perf/src/org/jboss/core/example/PerfParams.java
===================================================================
--- trunk/examples/core/perf/src/org/jboss/core/example/PerfParams.java (rev 0)
+++ trunk/examples/core/perf/src/org/jboss/core/example/PerfParams.java 2009-05-21 11:50:03 UTC (rev 6961)
@@ -0,0 +1,147 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2005, JBoss Inc., and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.core.example;
+
+import java.io.Serializable;
+
+/**
+ *
+ * Class that holds the parameters used in the performance examples
+ *
+ * @author <a href="ataylor at redhat.com">Andy Taylor</a>
+ */
+public class PerfParams implements Serializable
+{
+ private static final long serialVersionUID = -4336539641012356002L;
+
+ private int noOfMessagesToSend = 1000;
+ private int noOfWarmupMessages;
+ private int messageSize = 1024; // in bytes
+ private boolean durable = false;
+ private boolean isSessionTransacted = false;
+ private int batchSize = 5000;
+ private boolean drainQueue = true;
+ private String queueName = "perfQueue";
+ private int throttleRate;
+
+ public int getNoOfMessagesToSend()
+ {
+ return noOfMessagesToSend;
+ }
+
+ public void setNoOfMessagesToSend(final int noOfMessagesToSend)
+ {
+ this.noOfMessagesToSend = noOfMessagesToSend;
+ }
+
+ public int getNoOfWarmupMessages()
+ {
+ return noOfWarmupMessages;
+ }
+
+ public void setNoOfWarmupMessages(final int noOfWarmupMessages)
+ {
+ this.noOfWarmupMessages = noOfWarmupMessages;
+ }
+
+ public int getMessageSize()
+ {
+ return messageSize;
+ }
+
+ public void setMessageSize(int messageSize)
+ {
+ this.messageSize = messageSize;
+ }
+
+ public boolean isDurable()
+ {
+ return durable;
+ }
+
+ public void setDurable(final boolean durable)
+ {
+ this.durable = durable;
+ }
+
+ public boolean isSessionTransacted()
+ {
+ return isSessionTransacted;
+ }
+
+ public void setSessionTransacted(final boolean sessionTransacted)
+ {
+ isSessionTransacted = sessionTransacted;
+ }
+
+ public int getBatchSize()
+ {
+ return batchSize;
+ }
+
+ public void setBatchSize(final int batchSize)
+ {
+ this.batchSize = batchSize;
+ }
+
+ public boolean isDrainQueue()
+ {
+ return drainQueue;
+ }
+
+ public void setDrainQueue(final boolean drainQueue)
+ {
+ this.drainQueue = drainQueue;
+ }
+
+ public String getQueueName()
+ {
+ return queueName;
+ }
+
+ public void setQueueName(final String queueName)
+ {
+ this.queueName = queueName;
+ }
+
+
+ public int getThrottleRate()
+ {
+ return throttleRate;
+ }
+
+ public void setThrottleRate(final int throttleRate)
+ {
+ this.throttleRate = throttleRate;
+ }
+
+ public String toString()
+ {
+ return "message to send = " + noOfMessagesToSend + ", Durable = " +
+ durable + ", session transacted = " + isSessionTransacted +
+ (isSessionTransacted ? ", transaction batch size = " + batchSize : "") + ", drain queue = " + drainQueue +
+ ", queue name = " + queueName +
+ ", Throttle rate = " + throttleRate;
+ }
+
+
+}
Added: trunk/examples/core/perf/src/org/jboss/core/example/PerfSender.java
===================================================================
--- trunk/examples/core/perf/src/org/jboss/core/example/PerfSender.java (rev 0)
+++ trunk/examples/core/perf/src/org/jboss/core/example/PerfSender.java 2009-05-21 11:50:03 UTC (rev 6961)
@@ -0,0 +1,315 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2005-2008, Red Hat Middleware LLC, and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.core.example;
+
+import java.io.FileInputStream;
+import java.io.InputStream;
+import java.util.Properties;
+
+import javax.jms.JMSException;
+import javax.jms.Message;
+import javax.jms.MessageConsumer;
+
+import org.jboss.common.example.JBMExample;
+import org.jboss.messaging.core.client.ClientMessage;
+import org.jboss.messaging.core.client.ClientProducer;
+import org.jboss.messaging.core.client.ClientSession;
+import org.jboss.messaging.core.client.ClientSessionFactory;
+import org.jboss.messaging.core.client.impl.ClientSessionFactoryImpl;
+import org.jboss.messaging.core.config.TransportConfiguration;
+import org.jboss.messaging.integration.transports.netty.NettyConnectorFactory;
+import org.jboss.messaging.utils.TokenBucketLimiter;
+import org.jboss.messaging.utils.TokenBucketLimiterImpl;
+
+/**
+ *
+ * A PerfSender
+ *
+ * @author <a href="mailto:tim.fox at jboss.com">Tim Fox</a>
+ *
+ *
+ */
+public class PerfSender extends JBMExample
+{
+ public static void main(String[] args)
+ {
+ try
+ {
+ Properties props = null;
+
+ InputStream is = null;
+
+ try
+ {
+ is = new FileInputStream("perf.properties");
+
+ props = new Properties();
+
+ props.load(is);
+ }
+ finally
+ {
+ if (is != null)
+ {
+ is.close();
+ }
+ }
+
+ int noOfMessages = Integer.valueOf(props.getProperty("num-messages"));
+ int noOfWarmupMessages = Integer.valueOf(props.getProperty("num-warmup-messages"));
+ int messageSize = Integer.valueOf(props.getProperty("message-size"));
+ boolean durable = Boolean.valueOf(props.getProperty("durable"));
+ boolean transacted = Boolean.valueOf(props.getProperty("transacted"));
+ int batchSize = Integer.valueOf(props.getProperty("batch-size"));
+ boolean drainQueue = Boolean.valueOf(props.getProperty("drain-queue"));
+ String queueName = props.getProperty("queue-name");
+ int throttleRate = Integer.valueOf(props.getProperty("throttle-rate"));
+
+ PerfParams perfParams = new PerfParams();
+ perfParams.setNoOfMessagesToSend(noOfMessages);
+ perfParams.setNoOfWarmupMessages(noOfWarmupMessages);
+ perfParams.setMessageSize(messageSize);
+ perfParams.setDurable(durable);
+ perfParams.setSessionTransacted(transacted);
+ perfParams.setBatchSize(batchSize);
+ perfParams.setDrainQueue(drainQueue);
+ perfParams.setQueueName(queueName);
+ perfParams.setThrottleRate(throttleRate);
+
+ new PerfSender(perfParams).run(args);
+ }
+ catch (Exception e)
+ {
+ e.printStackTrace();
+ }
+ }
+
+ private final PerfParams perfParams;
+
+ private PerfSender(final PerfParams perfParams)
+ {
+ super();
+
+ this.perfParams = perfParams;
+ }
+
+ private ClientSessionFactory factory;
+
+ private ClientSession session;
+
+ private long start;
+
+ public boolean runExample() throws Exception
+ {
+ runSender(perfParams);
+
+ return true;
+ }
+
+ private void init(final boolean transacted, final String queueName) throws Exception
+ {
+ factory = new ClientSessionFactoryImpl(new TransportConfiguration(NettyConnectorFactory.class.getName()));
+
+ factory.setAckBatchSize(perfParams.getBatchSize());
+
+ session = factory.createSession(!transacted, !transacted);
+
+ session.createQueue(perfParams.getQueueName(), perfParams.getQueueName(), perfParams.isDurable());
+ }
+
+ private void displayAverage(final long numberOfMessages, final long start, final long end)
+ {
+ double duration = (1.0 * end - start) / 1000; // in seconds
+ double average = (1.0 * numberOfMessages / duration);
+ log.info(String.format("average: %.2f msg/s (%d messages in %2.2fs)", average, numberOfMessages, duration));
+ }
+
+ private void runSender(final PerfParams perfParams)
+ {
+ try
+ {
+ log.info("params = " + perfParams);
+ init(perfParams.isSessionTransacted(), perfParams.getQueueName());
+ start = System.currentTimeMillis();
+ log.info("warming up by sending " + perfParams.getNoOfWarmupMessages() + " messages");
+ sendMessages(perfParams.getNoOfWarmupMessages(),
+ perfParams.getBatchSize(),
+ perfParams.isDurable(),
+ perfParams.isSessionTransacted(),
+ false,
+ perfParams.getThrottleRate(),
+ perfParams.getMessageSize());
+ log.info("warmed up");
+ start = System.currentTimeMillis();
+ sendMessages(perfParams.getNoOfMessagesToSend(),
+ perfParams.getBatchSize(),
+ perfParams.isDurable(),
+ perfParams.isSessionTransacted(),
+ true,
+ perfParams.getThrottleRate(),
+ perfParams.getMessageSize());
+ long end = System.currentTimeMillis();
+ displayAverage(perfParams.getNoOfMessagesToSend(), start, end);
+ }
+ catch (Exception e)
+ {
+ e.printStackTrace();
+ }
+ finally
+ {
+ if (session != null)
+ {
+ try
+ {
+ session.close();
+ }
+ catch (Exception e)
+ {
+ e.printStackTrace();
+ }
+ }
+ }
+ }
+
+ private void sendMessages(final int numberOfMessages,
+ final int txBatchSize,
+ final boolean durable,
+ final boolean transacted,
+ final boolean display,
+ final int throttleRate,
+ final int messageSize) throws Exception
+ {
+ ClientProducer producer = session.createProducer(perfParams.getQueueName());
+
+ ClientMessage message = session.createClientMessage(durable);
+
+ byte[] payload = new byte[messageSize];
+
+ message.getBody().writeBytes(payload);
+
+ final int modulo = 2000;
+
+ TokenBucketLimiter tbl = throttleRate != -1 ? new TokenBucketLimiterImpl(throttleRate, false) : null;
+
+ boolean committed = false;
+ for (int i = 1; i <= numberOfMessages; i++)
+ {
+ producer.send(message);
+
+ if (transacted)
+ {
+ if (i % txBatchSize == 0)
+ {
+ session.commit();
+ committed = true;
+ }
+ else
+ {
+ committed = false;
+ }
+ }
+ if (display && (i % modulo == 0))
+ {
+ double duration = (1.0 * System.currentTimeMillis() - start) / 1000;
+ log.info(String.format("sent %6d messages in %2.2fs", i, duration));
+ }
+
+ if (tbl != null)
+ {
+ tbl.limit();
+ }
+ }
+ if (transacted && !committed)
+ {
+ session.commit();
+ }
+ }
+
+ private void drainQueue(final MessageConsumer consumer) throws JMSException
+ {
+ log.info("draining queue");
+ while (true)
+ {
+ Message m = consumer.receive(5000);
+ if (m == null)
+ {
+ log.info("queue is drained");
+ break;
+ }
+ }
+ }
+
+ // public boolean runExample() throws Exception
+ // {
+ // final String perfAddress = "perfAddress";
+ //
+ // final String perfQueueName = "perfQueue";
+ //
+ // ClientSessionFactory factory = null;
+ //
+ // ClientSession session = null;
+ //
+ // try
+ // {
+ // factory = new ClientSessionFactoryImpl(new TransportConfiguration(NettyConnectorFactory.class.getName()));
+ //
+ // session = factory.createSession();
+ //
+ // session.createQueue(perfAddress, perfQueueName, true);
+ //
+ // ClientProducer producer = session.createProducer(perfAddress);
+ //
+ // ClientMessage message = session.createClientMessage(true);
+ //
+ // message.getBody().writeString("Hello");
+ //
+ // producer.send(message);
+ //
+ // session.start();
+ //
+ // ClientConsumer consumer = session.createConsumer(perfQueueName);
+ //
+ // ClientMessage msgReceived = consumer.receive();
+ //
+ // System.out.println("message = " + msgReceived.getBody().readString());
+ //
+ // consumer.close();
+ //
+ // session.deleteQueue(perfQueueName);
+ //
+ // return true;
+ // }
+ // finally
+ // {
+ // if (session != null)
+ // {
+ // session.close();
+ // }
+ //
+ // if (factory != null)
+ // {
+ // factory.close();
+ // }
+ // }
+ // }
+
+}
More information about the jboss-cvs-commits
mailing list