Author: aco
Date: Thu Jun 1 03:28:24 2006
New Revision: 410824
URL: http://svn.apache.org/viewvc?rev=410824&view=rev
Log:
Added a producer tool to the performance tools
Added:
incubator/activemq/trunk/tooling/maven-activemq-perf-plugin/src/main/java/org/apache/activemq/tool/JmsProducerClient.java
Modified:
incubator/activemq/trunk/tooling/maven-activemq-perf-plugin/src/main/java/org/apache/activemq/tool/JmsBasicClientSupport.java
incubator/activemq/trunk/tooling/maven-activemq-perf-plugin/src/main/java/org/apache/activemq/tool/JmsConfigurableClientSupport.java
incubator/activemq/trunk/tooling/maven-activemq-perf-plugin/src/main/java/org/apache/activemq/tool/JmsPerfClientSupport.java
incubator/activemq/trunk/tooling/maven-activemq-perf-plugin/src/main/java/org/apache/activemq/tool/PerfMeasurable.java
Modified:
incubator/activemq/trunk/tooling/maven-activemq-perf-plugin/src/main/java/org/apache/activemq/tool/JmsBasicClientSupport.java
URL:
http://svn.apache.org/viewvc/incubator/activemq/trunk/tooling/maven-activemq-perf-plugin/src/main/java/org/apache/activemq/tool/JmsBasicClientSupport.java?rev=410824&r1=410823&r2=410824&view=diff
==============================================================================
---
incubator/activemq/trunk/tooling/maven-activemq-perf-plugin/src/main/java/org/apache/activemq/tool/JmsBasicClientSupport.java
(original)
+++
incubator/activemq/trunk/tooling/maven-activemq-perf-plugin/src/main/java/org/apache/activemq/tool/JmsBasicClientSupport.java
Thu Jun 1 03:28:24 2006
@@ -32,6 +32,10 @@
return createConnectionFactory(DEFAULT_CONNECTION_FACTORY_CLASS, url,
null);
}
+ public ConnectionFactory createConnectionFactory(String url, Map props) {
+ return createConnectionFactory(DEFAULT_CONNECTION_FACTORY_CLASS, url,
props);
+ }
+
public ConnectionFactory createConnectionFactory(String clazz, String url)
{
return createConnectionFactory(clazz, url, null);
}
@@ -54,7 +58,7 @@
Class factoryClass = Class.forName(clazz);
Constructor c = factoryClass.getConstructor(new Class[]
{String.class});
ConnectionFactory factoryObj =
(ConnectionFactory)c.newInstance(new Object[] {url});
-
+
return factoryObj;
} catch (Exception e) {
throw new RuntimeException (e);
Modified:
incubator/activemq/trunk/tooling/maven-activemq-perf-plugin/src/main/java/org/apache/activemq/tool/JmsConfigurableClientSupport.java
URL:
http://svn.apache.org/viewvc/incubator/activemq/trunk/tooling/maven-activemq-perf-plugin/src/main/java/org/apache/activemq/tool/JmsConfigurableClientSupport.java?rev=410824&r1=410823&r2=410824&view=diff
==============================================================================
---
incubator/activemq/trunk/tooling/maven-activemq-perf-plugin/src/main/java/org/apache/activemq/tool/JmsConfigurableClientSupport.java
(original)
+++
incubator/activemq/trunk/tooling/maven-activemq-perf-plugin/src/main/java/org/apache/activemq/tool/JmsConfigurableClientSupport.java
Thu Jun 1 03:28:24 2006
@@ -22,6 +22,7 @@
import javax.jms.*;
import java.util.Map;
import java.util.HashMap;
+import java.util.Iterator;
public class JmsConfigurableClientSupport extends JmsBasicClientSupport {
private static final Log log =
LogFactory.getLog(JmsConfigurableClientSupport.class);
@@ -47,11 +48,24 @@
protected MessageProducer jmsMessageProducer = null;
protected MessageConsumer jmsMessageConsumer = null;
+ public ConnectionFactory createConnectionFactory(ConnectionFactory
factory) {
+ jmsFactory = factory;
+ configureJmsObject(jmsFactory, factorySettings);
+ return jmsFactory;
+ }
+
public ConnectionFactory createConnectionFactory(String url) {
jmsFactory = super.createConnectionFactory(factoryClass, url,
factorySettings);
return jmsFactory;
}
+ public ConnectionFactory createConnectionFactory(String url, Map props) {
+ // Add previous settings to current settings
+ props.putAll(factorySettings);
+ jmsFactory = super.createConnectionFactory(factoryClass, url, props);
+ return jmsFactory;
+ }
+
public ConnectionFactory createConnectionFactory(String clazz, String url)
{
factoryClass = clazz;
jmsFactory = super.createConnectionFactory(clazz, url,
factorySettings);
@@ -59,8 +73,8 @@
}
public ConnectionFactory createConnectionFactory(String clazz, String url,
Map props) {
- factoryClass = clazz;
// Add previous settings to current settings
+ factoryClass = clazz;
props.putAll(factorySettings);
jmsFactory = super.createConnectionFactory(clazz, url, props);
return jmsFactory;
@@ -168,6 +182,14 @@
return topic;
}
+ public void addConfigParam(Map props) {
+ for (Iterator i=props.keySet().iterator(); i.hasNext();) {
+ String key = (String)i.next();
+ Object val = props.get(key);
+ addConfigParam(key, val);
+ }
+ }
+
public void addConfigParam(String key, Object value) {
// Simple mapping of JMS Server to connection factory class
if (key.equalsIgnoreCase("server")) {
@@ -221,6 +243,61 @@
} else {
log.warn("Unknown setting: " + key + " = " + value);
}
+ }
+
+ public String getServerType() {
+ return serverType;
+ }
+
+ public String getFactoryClass() {
+ return factoryClass;
+ }
+
+ public Map getFactorySettings() {
+ // Create a new HashMap to make the previous one read-only
+ return new HashMap(factorySettings);
+ }
+
+ public Map getConnectionSettings() {
+ // Create a new HashMap to make the previous one read-only
+ return new HashMap(connectionSettings);
+ }
+
+ public Map getSessionSettings() {
+ // Create a new HashMap to make the previous one read-only
+ return new HashMap(sessionSettings);
+ }
+
+ public Map getDestinationSettings() {
+ // Create a new HashMap to make the previous one read-only
+ Map temp = new HashMap(queueSettings);
+ temp.putAll(topicSettings);
+ return connectionSettings;
+ }
+
+ public Map getQueueSettings() {
+ // Create a new HashMap to make the previous one read-only
+ return new HashMap(queueSettings);
+ }
+
+ public Map getTopicSettings() {
+ // Create a new HashMap to make the previous one read-only
+ return new HashMap(topicSettings);
+ }
+
+ public Map getProducerSettings() {
+ // Create a new HashMap to make the previous one read-only
+ return new HashMap(producerSettings);
+ }
+
+ public Map getConsumerSettings() {
+ // Create a new HashMap to make the previous one read-only
+ return new HashMap(consumerSettings);
+ }
+
+ public Map getMessageSettings() {
+ // Create a new HashMap to make the previous one read-only
+ return new HashMap(messageSettings);
}
public void configureJmsObject(Object jmsObject, Map props) {
Modified:
incubator/activemq/trunk/tooling/maven-activemq-perf-plugin/src/main/java/org/apache/activemq/tool/JmsPerfClientSupport.java
URL:
http://svn.apache.org/viewvc/incubator/activemq/trunk/tooling/maven-activemq-perf-plugin/src/main/java/org/apache/activemq/tool/JmsPerfClientSupport.java?rev=410824&r1=410823&r2=410824&view=diff
==============================================================================
---
incubator/activemq/trunk/tooling/maven-activemq-perf-plugin/src/main/java/org/apache/activemq/tool/JmsPerfClientSupport.java
(original)
+++
incubator/activemq/trunk/tooling/maven-activemq-perf-plugin/src/main/java/org/apache/activemq/tool/JmsPerfClientSupport.java
Thu Jun 1 03:28:24 2006
@@ -26,19 +26,23 @@
protected PerfEventListener listener = null;
+ public void reset() {
+ setThroughput(0);
+ }
+
public long getThroughput() {
return throughput;
}
- public void setThroughput(long val) {
+ public synchronized void setThroughput(long val) {
this.throughput = val;
}
- public void incThroughput() {
+ public synchronized void incThroughput() {
throughput++;
}
- public void incThroughput(long val) {
+ public synchronized void incThroughput(long val) {
throughput += val;
}
Added:
incubator/activemq/trunk/tooling/maven-activemq-perf-plugin/src/main/java/org/apache/activemq/tool/JmsProducerClient.java
URL:
http://svn.apache.org/viewvc/incubator/activemq/trunk/tooling/maven-activemq-perf-plugin/src/main/java/org/apache/activemq/tool/JmsProducerClient.java?rev=410824&view=auto
==============================================================================
---
incubator/activemq/trunk/tooling/maven-activemq-perf-plugin/src/main/java/org/apache/activemq/tool/JmsProducerClient.java
(added)
+++
incubator/activemq/trunk/tooling/maven-activemq-perf-plugin/src/main/java/org/apache/activemq/tool/JmsProducerClient.java
Thu Jun 1 03:28:24 2006
@@ -0,0 +1,242 @@
+/**
+ *
+ * Copyright 2005-2006 The Apache Software Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.activemq.tool;
+
+import javax.jms.ConnectionFactory;
+import javax.jms.TextMessage;
+import javax.jms.Destination;
+import javax.jms.JMSException;
+import java.util.Map;
+import java.util.Arrays;
+
+public class JmsProducerClient extends JmsPerfClientSupport {
+
+ private ConnectionFactory factory = null;
+ private String factoryClass = "";
+ private String brokerUrl = "";
+ private String[] destName = null;
+
+ private Destination[] dest = null;
+ private TextMessage message = null;
+
+ public JmsProducerClient(ConnectionFactory factory, String destName) {
+ this.factory = factory;
+ this.destName = new String[] {destName};
+ }
+
+ public JmsProducerClient(String factoryClass, String brokerUrl, String
destName) {
+ this.factoryClass = factoryClass;
+ this.brokerUrl = brokerUrl;
+ this.destName = new String[] {destName};
+ }
+
+ public JmsProducerClient(String brokerUrl, String destName) {
+ this.brokerUrl = brokerUrl;
+ this.destName = new String[] {destName};
+ }
+
+ public JmsProducerClient(ConnectionFactory factory, String[] destName) {
+ this.factory = factory;
+ this.destName = destName;
+ }
+
+ public JmsProducerClient(String factoryClass, String brokerUrl, String[]
destName) {
+ this.factoryClass = factoryClass;
+ this.brokerUrl = brokerUrl;
+ this.destName = destName;
+ }
+
+ public JmsProducerClient(String brokerUrl, String[] destName) {
+ this.brokerUrl = brokerUrl;
+ this.destName = destName;
+ }
+
+ public void createProducer() throws JMSException {
+ createProducer(0);
+ }
+
+ public void createProducer(Map settings) throws JMSException {
+ createProducer(0, settings);
+ }
+
+ public void createProducer(int messageSize, Map settings) throws
JMSException {
+ addConfigParam(settings);
+ createProducer(messageSize);
+ }
+
+ public void createProducer(int messageSize) throws JMSException {
+
+ listener.onConfigStart();
+
+ // Create connection factory
+ if (factory != null) {
+ createConnectionFactory(factory);
+ } else if (factoryClass != null) {
+ createConnectionFactory(factoryClass, brokerUrl);
+ } else {
+ createConnectionFactory(brokerUrl);
+ }
+ createConnectionFactory(brokerUrl);
+
+
+ // Create destinations
+ dest = new Destination[destName.length];
+ for (int i=0; i<destName.length; i++) {
+ if (destName[i].startsWith("topic://")) {
+ dest[i] =
createTopic(destName[i].substring("topic://".length()));
+ } else if (destName[i].startsWith("queue://")) {
+ dest[i] =
createQueue(destName[i].substring("queue://".length()));
+ } else {
+ dest[i] = createQueue(destName[i]);
+ }
+ }
+
+ // Create actual message producer
+ if (dest.length > 1) {
+ createMessageProducer(null);
+ } else {
+ createMessageProducer(dest[0]);
+ }
+
+ // Create message to sent
+ if (messageSize > 0) {
+ byte[] val = new byte[messageSize];
+ Arrays.fill(val, (byte)0);
+ String buff = new String(val);
+ message = createTextMessage(buff);
+ }
+
+ listener.onConfigEnd();
+ }
+
+ public void sendCountBasedMessages(long messageCount) throws JMSException {
+ // Parse through different ways to send messages
+ // Avoided putting the condition inside the loop to prevent effect on
performance
+ try {
+ getConnection().start();
+ // Send one type of message only, avoiding the creation of
different messages on sending
+ if (message != null) {
+ // Send to more than one actual destination
+ if (dest.length > 1) {
+ listener.onPublishStart();
+ for (int i=0; i<messageCount; i++) {
+ for (int j=0; j<dest.length; j++) {
+ getMessageProducer().send(dest[j], message);
+ }
+ }
+ listener.onPublishEnd();
+ // Send to only one actual destination
+ } else {
+ listener.onPublishStart();
+ for (int i=0; i<messageCount; i++) {
+ getMessageProducer().send(message);
+ }
+ listener.onPublishEnd();
+ }
+
+ // Send different type of messages using indexing to identify each
one.
+ // Message size will vary. Definitely slower, since messages
properties
+ // will be set individually each send.
+ } else {
+ // Send to more than one actual destination
+ if (dest.length > 1) {
+ listener.onPublishStart();
+ for (int i=0; i<messageCount; i++) {
+ for (int j=0; j<dest.length; j++) {
+ getMessageProducer().send(dest[j],
createTextMessage("Text Message [" + i + "]"));
+ }
+ }
+ listener.onPublishEnd();
+
+ // Send to only one actual destination
+ } else {
+ listener.onPublishStart();
+ for (int i=0; i<messageCount; i++) {
+ getMessageProducer().send(createTextMessage("Text
Message [" + i + "]"));
+ }
+ listener.onPublishEnd();
+ }
+ }
+ } finally {
+ getConnection().close();
+ }
+ }
+
+ public void sendTimeBasedMessages(long duration) throws JMSException {
+ long endTime = System.currentTimeMillis() + duration;
+ // Parse through different ways to send messages
+ // Avoided putting the condition inside the loop to prevent effect on
performance
+
+ // Send one type of message only, avoiding the creation of different
messages on sending
+ try {
+ getConnection().start();
+
+ if (message != null) {
+ // Send to more than one actual destination
+ if (dest.length > 1) {
+ listener.onPublishStart();
+ while (System.currentTimeMillis() < endTime) {
+ for (int j=0; j<dest.length; j++) {
+ getMessageProducer().send(dest[j], message);
+ }
+ }
+ listener.onPublishEnd();
+ // Send to only one actual destination
+ } else {
+ listener.onPublishStart();
+ while (System.currentTimeMillis() < endTime) {
+ getMessageProducer().send(message);
+ }
+ listener.onPublishEnd();
+ }
+
+ // Send different type of messages using indexing to identify each
one.
+ // Message size will vary. Definitely slower, since messages
properties
+ // will be set individually each send.
+ } else {
+ // Send to more than one actual destination
+ long count = 1;
+ if (dest.length > 1) {
+ listener.onPublishStart();
+ while (System.currentTimeMillis() < endTime) {
+ for (int j=0; j<dest.length; j++) {
+ getMessageProducer().send(dest[j],
createTextMessage("Text Message [" + count++ + "]"));
+ }
+ }
+ listener.onPublishEnd();
+
+ // Send to only one actual destination
+ } else {
+ listener.onPublishStart();
+ while (System.currentTimeMillis() < endTime) {
+ getMessageProducer().send(createTextMessage("Text
Message [" + count++ + "]"));
+ }
+ listener.onPublishEnd();
+ }
+ }
+ } finally {
+ getConnection().close();
+ }
+ }
+
+ public static void main(String[] args) throws Exception {
+ JmsProducerClient prod = new
JmsProducerClient("org.apache.activemq.ActiveMQConnectionFactory",
"tcp://localhost:61616", "topic://TEST.FOO");
+ prod.setPerfEventListener(new PerfEventAdapter());
+ prod.createProducer();
+ prod.sendTimeBasedMessages(2000);
+ }
+}
Modified:
incubator/activemq/trunk/tooling/maven-activemq-perf-plugin/src/main/java/org/apache/activemq/tool/PerfMeasurable.java
URL:
http://svn.apache.org/viewvc/incubator/activemq/trunk/tooling/maven-activemq-perf-plugin/src/main/java/org/apache/activemq/tool/PerfMeasurable.java?rev=410824&r1=410823&r2=410824&view=diff
==============================================================================
---
incubator/activemq/trunk/tooling/maven-activemq-perf-plugin/src/main/java/org/apache/activemq/tool/PerfMeasurable.java
(original)
+++
incubator/activemq/trunk/tooling/maven-activemq-perf-plugin/src/main/java/org/apache/activemq/tool/PerfMeasurable.java
Thu Jun 1 03:28:24 2006
@@ -17,6 +17,7 @@
package org.apache.activemq.tool;
public interface PerfMeasurable {
+ public void reset();
public long getThroughput();
public long getInterval();
public long getDuration();