[jboss-cvs] JBoss Messaging SVN: r4140 - projects/jms-perf/src/java/jms.
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Wed Apr 30 10:18:11 EDT 2008
Author: jmesnil
Date: 2008-04-30 10:18:11 -0400 (Wed, 30 Apr 2008)
New Revision: 4140
Modified:
projects/jms-perf/src/java/jms/JMSTestBase.java
Log:
refactored sendAndReceiveManyMessages(): first send/receive many message to warmup and then send/receive messages for a given duration
Modified: projects/jms-perf/src/java/jms/JMSTestBase.java
===================================================================
--- projects/jms-perf/src/java/jms/JMSTestBase.java 2008-04-30 12:54:07 UTC (rev 4139)
+++ projects/jms-perf/src/java/jms/JMSTestBase.java 2008-04-30 14:18:11 UTC (rev 4140)
@@ -36,8 +36,8 @@
protected static final String QUEUE = "MyQueue";
private static final String TEXT = "hello, world!";
protected static final String SERVER_HOST;
- private static final int DURATION = 10000;
- private static final int WARMUP = DURATION / 10;
+ private static final int MESSAGES_WARMUP = 1000;
+ private static final int DURATION = 5000;
// Attributes ----------------------------------------------------
@@ -156,9 +156,12 @@
// assertQueueIsEmpty(session, queue);
MessageConsumer consumer = session.createConsumer(queue);
+ MessageProducer producer = session.createProducer(queue);
+ producer.setDeliveryMode(deliveryMode);
- final AtomicLong receivedCountDuringWarmup = new AtomicLong(0);
- final AtomicLong receivedCountAfterWarmup = new AtomicLong(0);
+ warmup(producer, consumer, session.createMessage(), ackMode);
+
+ final AtomicLong receivedCount = new AtomicLong(0);
final long start = System.currentTimeMillis();
@@ -166,10 +169,7 @@
{
public void onMessage(Message msg)
{
- if (System.currentTimeMillis() - start < WARMUP)
- receivedCountDuringWarmup.incrementAndGet();
- else
- receivedCountAfterWarmup.incrementAndGet();
+ receivedCount.incrementAndGet();
if (ackMode == Session.CLIENT_ACKNOWLEDGE)
{
@@ -184,29 +184,26 @@
}
});
- MessageProducer producer = session.createProducer(queue);
- producer.setDeliveryMode(deliveryMode);
Message message = session.createTextMessage(TEXT);
long sentCount = 0;
- while (System.currentTimeMillis() - start < DURATION)
+ while((System.currentTimeMillis() - start) < DURATION)
{
producer.send(message);
sentCount++;
}
- info("sent " + sentCount + " messages");
- while ((receivedCountDuringWarmup.get() + receivedCountAfterWarmup
- .get()) < sentCount)
+ info("sent " + sentCount + " messages in " + (System.currentTimeMillis() - start) + "ms");
+ while (receivedCount.longValue() < sentCount)
{
+ // info(sentCount - receivedCount.longValue());
Thread.yield();
}
- assertEquals(sentCount, receivedCountDuringWarmup.longValue()
- + receivedCountAfterWarmup.longValue());
+ assertEquals(sentCount, receivedCount.longValue());
//assertQueueIsEmpty(session, queue);
- long duration = System.currentTimeMillis() - start - WARMUP;
- display(sentCount, receivedCountAfterWarmup.longValue(), duration);
+ long duration = System.currentTimeMillis() - start;
+ display(sentCount, receivedCount.longValue(), duration);
conn.stop();
conn.close();
@@ -218,9 +215,22 @@
// Private -------------------------------------------------------
+ private void warmup(MessageProducer producer, MessageConsumer consumer, Message message, int ackMode) throws JMSException
+ {
+ for (int i = 0; i < MESSAGES_WARMUP; i++)
+ {
+ producer.send(message);
+ Message m = consumer.receive(1000);
+ assertNotNull(m);
+ if (ackMode == Session.CLIENT_ACKNOWLEDGE)
+ m.acknowledge();
+ }
+ info("warmed up by sending/receiving " + MESSAGES_WARMUP + " messages");
+ }
+
private void info(String info)
{
- if (false)
+ if (true)
System.out.println(info);
}
More information about the jboss-cvs-commits
mailing list