From 5582cc1751125f7c3aaaae417a10cf0021a19d37 Mon Sep 17 00:00:00 2001 From: Robert Davies Date: Sun, 16 Dec 2007 20:16:59 +0000 Subject: [PATCH] update performance tests git-svn-id: https://svn.apache.org/repos/asf/activemq/trunk@604691 13f79535-47bb-0310-9956-ffa450edef68 --- .../perf/AMQStoreDurableTopicTest.java | 16 ++- .../activemq/perf/AMQStoreQueueTest.java | 4 +- .../perf/JournalKahaDurableTopicTest.java | 4 +- .../activemq/perf/JournalKahaQueueTest.java | 4 +- .../activemq/perf/KahaDurableTopicTest.java | 4 +- .../apache/activemq/perf/KahaQueueTest.java | 4 +- .../perf/QueueConnectionMemoryTest.java | 8 +- .../perf/SimpleDurableTopicNetworkTest.java | 48 +++++++ .../activemq/perf/SimpleNetworkTest.java | 125 ++++++++++++++++++ .../apache/activemq/perf/SimpleQueueTest.java | 5 + .../apache/activemq/perf/SimpleTopicTest.java | 19 +-- .../activemq/perf/SlowConsumerTopicTest.java | 2 +- 12 files changed, 216 insertions(+), 27 deletions(-) create mode 100644 activemq-core/src/test/java/org/apache/activemq/perf/SimpleDurableTopicNetworkTest.java create mode 100644 activemq-core/src/test/java/org/apache/activemq/perf/SimpleNetworkTest.java diff --git a/activemq-core/src/test/java/org/apache/activemq/perf/AMQStoreDurableTopicTest.java b/activemq-core/src/test/java/org/apache/activemq/perf/AMQStoreDurableTopicTest.java index 5108367c03..8c1610ff9f 100644 --- a/activemq-core/src/test/java/org/apache/activemq/perf/AMQStoreDurableTopicTest.java +++ b/activemq-core/src/test/java/org/apache/activemq/perf/AMQStoreDurableTopicTest.java @@ -25,12 +25,22 @@ import org.apache.activemq.store.amq.AMQPersistenceAdapter; */ public class AMQStoreDurableTopicTest extends SimpleDurableTopicTest { - protected void configureBroker(BrokerService answer) throws Exception { + protected void configureBroker(BrokerService answer,String uri) throws Exception { File dataFileDir = new File("target/test-amq-data/perfTest/amqdb"); + dataFileDir.mkdirs(); answer.setDeleteAllMessagesOnStartup(true); AMQPersistenceAdapter adaptor = new AMQPersistenceAdapter(); - adaptor.setDirectory(dataFileDir); + adaptor.setArchiveDataLogs(true); + adaptor.setMaxFileLength(1024 * 64); + answer.setDataDirectoryFile(dataFileDir); answer.setPersistenceAdapter(adaptor); - answer.addConnector(bindAddress); + answer.addConnector(uri); + } + + protected void setUp() throws Exception { + numberofProducers=6; + numberOfConsumers=6; + this.consumerSleepDuration=0; + super.setUp(); } } diff --git a/activemq-core/src/test/java/org/apache/activemq/perf/AMQStoreQueueTest.java b/activemq-core/src/test/java/org/apache/activemq/perf/AMQStoreQueueTest.java index 0bf8cbdf87..00b85ae1c2 100644 --- a/activemq-core/src/test/java/org/apache/activemq/perf/AMQStoreQueueTest.java +++ b/activemq-core/src/test/java/org/apache/activemq/perf/AMQStoreQueueTest.java @@ -26,7 +26,7 @@ import org.apache.activemq.store.amq.AMQPersistenceAdapter; */ public class AMQStoreQueueTest extends SimpleQueueTest { - protected void configureBroker(BrokerService answer) throws Exception { + protected void configureBroker(BrokerService answer,String uri) throws Exception { File dataFileDir = new File("target/test-amq-data/perfTest/amq"); @@ -34,7 +34,7 @@ public class AMQStoreQueueTest extends SimpleQueueTest { adaptor.setDirectory(dataFileDir); answer.setPersistenceAdapter(adaptor); - answer.addConnector(bindAddress); + answer.addConnector(uri); answer.setDeleteAllMessagesOnStartup(true); } diff --git a/activemq-core/src/test/java/org/apache/activemq/perf/JournalKahaDurableTopicTest.java b/activemq-core/src/test/java/org/apache/activemq/perf/JournalKahaDurableTopicTest.java index aad51fc958..980f5fe999 100644 --- a/activemq-core/src/test/java/org/apache/activemq/perf/JournalKahaDurableTopicTest.java +++ b/activemq-core/src/test/java/org/apache/activemq/perf/JournalKahaDurableTopicTest.java @@ -27,7 +27,7 @@ import org.apache.activemq.store.kahadaptor.KahaPersistenceAdapter; */ public class JournalKahaDurableTopicTest extends SimpleDurableTopicTest { - protected void configureBroker(BrokerService answer) throws Exception { + protected void configureBroker(BrokerService answer,String uri) throws Exception { File dataFileDir = new File("target/test-amq-data/perfTest"); File journalDir = new File(dataFileDir, "journal").getCanonicalFile(); @@ -38,7 +38,7 @@ public class JournalKahaDurableTopicTest extends SimpleDurableTopicTest { journalAdaptor.setMaxCheckpointWorkers(1); answer.setPersistenceAdapter(journalAdaptor); - answer.addConnector(bindAddress); + answer.addConnector(uri); answer.setDeleteAllMessagesOnStartup(true); } diff --git a/activemq-core/src/test/java/org/apache/activemq/perf/JournalKahaQueueTest.java b/activemq-core/src/test/java/org/apache/activemq/perf/JournalKahaQueueTest.java index 8771e33d21..2d8ef2e5d4 100644 --- a/activemq-core/src/test/java/org/apache/activemq/perf/JournalKahaQueueTest.java +++ b/activemq-core/src/test/java/org/apache/activemq/perf/JournalKahaQueueTest.java @@ -28,7 +28,7 @@ import org.apache.activemq.store.kahadaptor.KahaPersistenceAdapter; */ public class JournalKahaQueueTest extends SimpleQueueTest { - protected void configureBroker(BrokerService answer) throws Exception { + protected void configureBroker(BrokerService answer,String uri) throws Exception { File dataFileDir = new File("target/test-amq-data/perfTest"); File journalDir = new File(dataFileDir, "journal").getCanonicalFile(); @@ -39,7 +39,7 @@ public class JournalKahaQueueTest extends SimpleQueueTest { journalAdaptor.setMaxCheckpointWorkers(1); answer.setPersistenceAdapter(journalAdaptor); - answer.addConnector(bindAddress); + answer.addConnector(uri); answer.setDeleteAllMessagesOnStartup(true); } diff --git a/activemq-core/src/test/java/org/apache/activemq/perf/KahaDurableTopicTest.java b/activemq-core/src/test/java/org/apache/activemq/perf/KahaDurableTopicTest.java index 70767eb1e5..450448b857 100644 --- a/activemq-core/src/test/java/org/apache/activemq/perf/KahaDurableTopicTest.java +++ b/activemq-core/src/test/java/org/apache/activemq/perf/KahaDurableTopicTest.java @@ -32,10 +32,10 @@ public class KahaDurableTopicTest extends SimpleDurableTopicTest { * result=factory.getBroker(); result.start(); return result; } */ - protected void configureBroker(BrokerService answer) throws Exception { + protected void configureBroker(BrokerService answer,String uri) throws Exception { KahaPersistenceAdapter adaptor = new KahaPersistenceAdapter(); answer.setPersistenceAdapter(adaptor); - answer.addConnector(bindAddress); + answer.addConnector(uri); answer.setDeleteAllMessagesOnStartup(true); } diff --git a/activemq-core/src/test/java/org/apache/activemq/perf/KahaQueueTest.java b/activemq-core/src/test/java/org/apache/activemq/perf/KahaQueueTest.java index aba2ec7807..757d0358e1 100644 --- a/activemq-core/src/test/java/org/apache/activemq/perf/KahaQueueTest.java +++ b/activemq-core/src/test/java/org/apache/activemq/perf/KahaQueueTest.java @@ -24,10 +24,10 @@ import org.apache.activemq.store.kahadaptor.KahaPersistenceAdapter; */ public class KahaQueueTest extends SimpleQueueTest { - protected void configureBroker(BrokerService answer) throws Exception { + protected void configureBroker(BrokerService answer,String uri) throws Exception { KahaPersistenceAdapter adaptor = new KahaPersistenceAdapter(); answer.setPersistenceAdapter(adaptor); - answer.addConnector(bindAddress); + answer.addConnector(uri); answer.setDeleteAllMessagesOnStartup(true); } diff --git a/activemq-core/src/test/java/org/apache/activemq/perf/QueueConnectionMemoryTest.java b/activemq-core/src/test/java/org/apache/activemq/perf/QueueConnectionMemoryTest.java index cda419f64d..bb98607fc6 100644 --- a/activemq-core/src/test/java/org/apache/activemq/perf/QueueConnectionMemoryTest.java +++ b/activemq-core/src/test/java/org/apache/activemq/perf/QueueConnectionMemoryTest.java @@ -47,18 +47,18 @@ public class QueueConnectionMemoryTest extends SimpleQueueTest { // just cancel super class test } - protected void configureBroker(BrokerService answer) throws Exception { + protected void configureBroker(BrokerService answer,String uri) throws Exception { KahaPersistenceAdapter adaptor = new KahaPersistenceAdapter(); answer.setPersistenceAdapter(adaptor); - answer.addConnector(bindAddress); + answer.addConnector(uri); answer.setDeleteAllMessagesOnStartup(true); } public void testMemory() throws Exception { if (broker == null) { - broker = createBroker(); + broker = createBroker(bindAddress); } - factory = createConnectionFactory(); + factory = createConnectionFactory(bindAddress); Connection con = factory.createConnection(); Session session = con.createSession(false, Session.AUTO_ACKNOWLEDGE); destination = createDestination(session, destinationName); diff --git a/activemq-core/src/test/java/org/apache/activemq/perf/SimpleDurableTopicNetworkTest.java b/activemq-core/src/test/java/org/apache/activemq/perf/SimpleDurableTopicNetworkTest.java new file mode 100644 index 0000000000..102a00b133 --- /dev/null +++ b/activemq-core/src/test/java/org/apache/activemq/perf/SimpleDurableTopicNetworkTest.java @@ -0,0 +1,48 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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.perf; + +import javax.jms.ConnectionFactory; +import javax.jms.DeliveryMode; +import javax.jms.Destination; +import javax.jms.JMSException; + +import org.apache.activemq.broker.BrokerService; +import org.apache.activemq.network.NetworkConnector; + + +public class SimpleDurableTopicNetworkTest extends SimpleNetworkTest { + + protected void setUp() throws Exception { + numberofProducers=6; + numberOfConsumers=6; + samepleCount=100; + playloadSize = 1; + super.setUp(); + } + + + protected PerfProducer createProducer(ConnectionFactory fac, Destination dest, int number, byte payload[]) throws JMSException { + PerfProducer pp = new PerfProducer(fac, dest, payload); + pp.setDeliveryMode(DeliveryMode.PERSISTENT); + return pp; + } + + protected PerfConsumer createConsumer(ConnectionFactory fac, Destination dest, int number) throws JMSException { + return new PerfConsumer(fac, dest, "subs:" + number); + } +} diff --git a/activemq-core/src/test/java/org/apache/activemq/perf/SimpleNetworkTest.java b/activemq-core/src/test/java/org/apache/activemq/perf/SimpleNetworkTest.java new file mode 100644 index 0000000000..3ccad236e1 --- /dev/null +++ b/activemq-core/src/test/java/org/apache/activemq/perf/SimpleNetworkTest.java @@ -0,0 +1,125 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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.perf; + +import javax.jms.Connection; +import javax.jms.ConnectionFactory; +import javax.jms.Session; + +import org.apache.activemq.broker.BrokerService; +import org.apache.activemq.network.NetworkConnector; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; + +import junit.framework.TestCase; + + +public class SimpleNetworkTest extends SimpleTopicTest { + + private static final Log LOG = LogFactory.getLog(SimpleNetworkTest.class); + protected String consumerBindAddress = "tcp://localhost:61616"; + protected String producerBindAddress = "tcp://localhost:61617"; + protected static final String CONSUMER_BROKER_NAME = "Consumer"; + protected static final String PRODUCER_BROKER_NAME = "Producer"; + protected BrokerService consumerBroker; + protected BrokerService producerBroker; + protected ConnectionFactory consumerFactory; + protected ConnectionFactory producerFactory; + + protected void setUp() throws Exception { + if (consumerBroker == null) { + consumerBroker = createConsumerBroker(consumerBindAddress); + } + if (producerBroker == null) { + producerBroker = createProducerBroker(producerBindAddress); + } + consumerFactory = createConnectionFactory("vm://"+CONSUMER_BROKER_NAME); + producerFactory = createConnectionFactory("vm://"+ PRODUCER_BROKER_NAME); + //consumerFactory = createConnectionFactory(consumerBindAddress); + //producerFactory = createConnectionFactory(producerBindAddress); + Connection con = consumerFactory.createConnection(); + Session session = con.createSession(false, Session.AUTO_ACKNOWLEDGE); + destination = createDestination(session, destinationName); + LOG.info("Testing against destination: " + destination); + LOG.info("Running " + numberofProducers + " producer(s) and " + numberOfConsumers + " consumer(s)"); + con.close(); + producers = new PerfProducer[numberofProducers]; + consumers = new PerfConsumer[numberOfConsumers]; + for (int i = 0; i < numberOfConsumers; i++) { + consumers[i] = createConsumer(consumerFactory, destination, i); + consumers[i].setSleepDuration(consumerSleepDuration); + } + for (int i = 0; i < numberofProducers; i++) { + array = new byte[playloadSize]; + for (int j = i; j < array.length; j++) { + array[j] = (byte)j; + } + producers[i] = createProducer(producerFactory, destination, i, array); + } + } + + protected void tearDown() throws Exception { + for (int i = 0; i < numberOfConsumers; i++) { + consumers[i].shutDown(); + } + for (int i = 0; i < numberofProducers; i++) { + producers[i].shutDown(); + } + + if (producerBroker != null) { + producerBroker.stop(); + producerBroker = null; + } + if (consumerBroker != null) { + consumerBroker.stop(); + consumerBroker = null; + } + } + + protected BrokerService createConsumerBroker(String uri) throws Exception { + BrokerService answer = new BrokerService(); + configureConsumerBroker(answer,uri); + answer.start(); + return answer; + } + + protected void configureConsumerBroker(BrokerService answer,String uri) throws Exception { + answer.setPersistent(false); + answer.setBrokerName(CONSUMER_BROKER_NAME); + answer.setDeleteAllMessagesOnStartup(true); + answer.addConnector(uri); + answer.setUseShutdownHook(false); + } + + protected BrokerService createProducerBroker(String uri) throws Exception { + BrokerService answer = new BrokerService(); + configureProducerBroker(answer,uri); + answer.start(); + return answer; + } + + protected void configureProducerBroker(BrokerService answer,String uri) throws Exception { + answer.setBrokerName(PRODUCER_BROKER_NAME); + answer.setDeleteAllMessagesOnStartup(true); + NetworkConnector connector = answer.addNetworkConnector("static://"+consumerBindAddress); + connector.setDuplex(true); + answer.addConnector(uri); + answer.setUseShutdownHook(false); + } + + +} diff --git a/activemq-core/src/test/java/org/apache/activemq/perf/SimpleQueueTest.java b/activemq-core/src/test/java/org/apache/activemq/perf/SimpleQueueTest.java index ba1dbfeffd..5bd925cdb2 100644 --- a/activemq-core/src/test/java/org/apache/activemq/perf/SimpleQueueTest.java +++ b/activemq-core/src/test/java/org/apache/activemq/perf/SimpleQueueTest.java @@ -28,5 +28,10 @@ public class SimpleQueueTest extends SimpleTopicTest { protected Destination createDestination(Session s, String destinationName) throws JMSException { return s.createQueue(destinationName); } + + protected void setUp() throws Exception { + this.consumerSleepDuration=2000; + super.setUp(); + } } diff --git a/activemq-core/src/test/java/org/apache/activemq/perf/SimpleTopicTest.java b/activemq-core/src/test/java/org/apache/activemq/perf/SimpleTopicTest.java index 9efb1b909b..0377d7c986 100644 --- a/activemq-core/src/test/java/org/apache/activemq/perf/SimpleTopicTest.java +++ b/activemq-core/src/test/java/org/apache/activemq/perf/SimpleTopicTest.java @@ -61,9 +61,9 @@ public class SimpleTopicTest extends TestCase { */ protected void setUp() throws Exception { if (broker == null) { - broker = createBroker(); + broker = createBroker(bindAddress); } - factory = createConnectionFactory(); + factory = createConnectionFactory(bindAddress); Connection con = factory.createConnection(); Session session = con.createSession(false, Session.AUTO_ACKNOWLEDGE); destination = createDestination(session, destinationName); @@ -109,9 +109,9 @@ public class SimpleTopicTest extends TestCase { * * @throws Exception */ - protected BrokerService createBroker() throws Exception { + protected BrokerService createBroker(String uri) throws Exception { BrokerService answer = new BrokerService(); - configureBroker(answer); + configureBroker(answer,uri); answer.start(); return answer; } @@ -123,15 +123,16 @@ public class SimpleTopicTest extends TestCase { protected PerfConsumer createConsumer(ConnectionFactory fac, Destination dest, int number) throws JMSException { return new PerfConsumer(fac, dest); } - - protected void configureBroker(BrokerService answer) throws Exception { - answer.addConnector(bindAddress); + + + protected void configureBroker(BrokerService answer,String uri) throws Exception { answer.setDeleteAllMessagesOnStartup(true); + answer.addConnector(uri); answer.setUseShutdownHook(false); } - protected ActiveMQConnectionFactory createConnectionFactory() throws Exception { - return new ActiveMQConnectionFactory(bindAddress); + protected ActiveMQConnectionFactory createConnectionFactory(String uri) throws Exception { + return new ActiveMQConnectionFactory(uri); } public void testPerformance() throws JMSException, InterruptedException { diff --git a/activemq-core/src/test/java/org/apache/activemq/perf/SlowConsumerTopicTest.java b/activemq-core/src/test/java/org/apache/activemq/perf/SlowConsumerTopicTest.java index e6729c3556..c3b99662bd 100644 --- a/activemq-core/src/test/java/org/apache/activemq/perf/SlowConsumerTopicTest.java +++ b/activemq-core/src/test/java/org/apache/activemq/perf/SlowConsumerTopicTest.java @@ -66,7 +66,7 @@ public class SlowConsumerTopicTest extends SimpleTopicTest { } protected ActiveMQConnectionFactory createConnectionFactory() throws Exception { - ActiveMQConnectionFactory result = super.createConnectionFactory(); + ActiveMQConnectionFactory result = super.createConnectionFactory(bindAddress); ActiveMQPrefetchPolicy policy = new ActiveMQPrefetchPolicy(); policy.setTopicPrefetch(1000); result.setPrefetchPolicy(policy);