Commit 7fc6dd70 authored by afreyssin's avatar afreyssin

Allows a multithread producer.

parent 583d94be
......@@ -1090,7 +1090,18 @@
<classpath path="${project.class.path}"/>
</java>
</target>
<!-- Runs the 25 performance sample producer: send 50.000 transient messages on queue -->
<target name="perfs_prod_qx" depends="simple_init"
description="--> Starts the PERFS producer with 25 clients">
<java classname="perfs.Producer" failonerror="no" fork="yes"
dir="${run.dir}">
<classpath path="${project.class.path}"/>
<jvmarg line="-DNbClient=25 -DRound=40 -DNbMsgPerRound=50 -Dmps=50 -DMsgSize=500 -DMsgTransient=false -DTransacted=false" />
<arg line="queue"/>
</java>
</target>
<!-- Runs the performance sample producer: send 50.000 transient messages on queue -->
<target name="perfs_prod_q1" depends="simple_init"
description="--> Starts the PERFS producer">
......@@ -1140,7 +1151,7 @@
<java classname="perfs.Producer" failonerror="no" fork="yes"
dir="${run.dir}">
<classpath path="${project.class.path}"/>
<jvmarg line="-DRound=50 -DMsgSize=500 -DMsgTransient=true" />
<jvmarg line="-DRound=50 -DMsgSize=500 -Dmps=10500 -DMsgTransient=true" />
<arg line="topic"/>
</java>
</target>
......
......@@ -34,12 +34,13 @@ import org.objectweb.joram.client.jms.Destination;
/**
* MessageProducer sending messages on queue or topic for performance statistics.
*/
public class Producer {
public class Producer implements Runnable {
static int NbClient = 1;
static int Round = 50;
static int NbMsgPerRound = 1000;
static int MsgSize = 1000;
static int mps = 10000;
static Destination dest = null;
static ConnectionFactory cf = null;
......@@ -51,18 +52,21 @@ public class Producer {
String value = System.getProperty(key, Boolean.toString(def));
return Boolean.parseBoolean(value);
}
public static void main (String args[]) throws Exception {
NbClient = Integer.getInteger("NbClient", NbClient).intValue();
Round = Integer.getInteger("Round", Round).intValue();
NbMsgPerRound = Integer.getInteger("NbMsgPerRound", NbMsgPerRound).intValue();
MsgSize = Integer.getInteger("MsgSize", MsgSize).intValue();
mps = Integer.getInteger("mps", mps).intValue();
MsgTransient = getBoolean("MsgTransient", MsgTransient);
SwapAllowed = getBoolean("SwapAllowed", SwapAllowed);
transacted = getBoolean("Transacted", transacted);
InitialContext ictx = new InitialContext();
Destination dest = (Destination) ictx.lookup(args[0]);
ConnectionFactory cf = (ConnectionFactory) ictx.lookup("cf");
dest = (Destination) ictx.lookup(args[0]);
cf = (ConnectionFactory) ictx.lookup("cf");
ictx.close();
System.out.println("Destination: " + (dest.isQueue()?"Queue":"Topic"));
......@@ -70,50 +74,59 @@ public class Producer {
System.out.println("Message: SwapAllowed=" + SwapAllowed);
System.out.println("Transacted=" + transacted);
System.out.println("NbMsg=" + (Round*NbMsgPerRound) + ", MsgSize=" + MsgSize);
Connection cnx = cf.createConnection();
Session session = cnx.createSession(transacted, Session.AUTO_ACKNOWLEDGE);
MessageProducer producer = session.createProducer(dest);
if (MsgTransient) {
producer.setDeliveryMode(javax.jms.DeliveryMode.NON_PERSISTENT);
for (int i=0; i<NbClient; i++) {
new Thread(new Producer()).start();
}
}
byte[] content = new byte[MsgSize];
for (int i = 0; i< MsgSize; i++)
content[i] = (byte) (i & 0xFF);
long dtx = 0;
long start = System.currentTimeMillis();
for (int i=0; i<(Round*NbMsgPerRound); i++) {
BytesMessage msg = session.createBytesMessage();
if (SwapAllowed) {
msg.setBooleanProperty("JMS_JORAM_SWAPALLOWED", true);
public void run() {
try {
Connection cnx = cf.createConnection();
Session session = cnx.createSession(transacted, Session.AUTO_ACKNOWLEDGE);
MessageProducer producer = session.createProducer(dest);
if (MsgTransient) {
producer.setDeliveryMode(javax.jms.DeliveryMode.NON_PERSISTENT);
}
msg.writeBytes(content);
msg.setLongProperty("time", System.currentTimeMillis());
msg.setIntProperty("index", i);
producer.send(msg);
if (transacted && ((i%10) == 9)) session.commit();
if ((i%NbMsgPerRound) == (NbMsgPerRound-1)) {
long dtx1 = (i * 1000L) / mps;
long dtx2 = System.currentTimeMillis() - start;
if (dtx1 > (dtx2 + 20)) {
dtx += (dtx1 - dtx2);
Thread.sleep(dtx1 - dtx2);
byte[] content = new byte[MsgSize];
for (int i = 0; i< MsgSize; i++)
content[i] = (byte) (i & 0xFF);
long dtx = 0;
long start = System.currentTimeMillis();
for (int i=0; i<(Round*NbMsgPerRound); i++) {
BytesMessage msg = session.createBytesMessage();
if (SwapAllowed) {
msg.setBooleanProperty("JMS_JORAM_SWAPALLOWED", true);
}
msg.writeBytes(content);
msg.setLongProperty("time", System.currentTimeMillis());
msg.setIntProperty("index", i);
producer.send(msg);
if (transacted && ((i%10) == 9)) session.commit();
if ((i%NbMsgPerRound) == (NbMsgPerRound-1)) {
long dtx1 = (i * 1000L) / mps;
long dtx2 = System.currentTimeMillis() - start;
if (dtx1 > (dtx2 + 20)) {
dtx += (dtx1 - dtx2);
Thread.sleep(dtx1 - dtx2);
}
}
}
long end = System.currentTimeMillis();
long dt = end - start;
System.out.println("----------------------------------------------------");
System.out.println("| sender dt=" + ((dt *1000L)/(Round*NbMsgPerRound)) + "us -> " +
((1000L * (Round*NbMsgPerRound)) / (dt)) + "msg/s");
System.out.println("| sender wait=" + dtx + "ms");
cnx.close();
} catch (Exception exc) {
exc.printStackTrace();
}
long end = System.currentTimeMillis();
long dt = end - start;
System.out.println("----------------------------------------------------");
System.out.println("| sender dt=" + ((dt *1000L)/(Round*NbMsgPerRound)) + "us -> " +
((1000L * (Round*NbMsgPerRound)) / (dt)) + "msg/s");
System.out.println("| sender wait=" + dtx + "ms");
cnx.close();
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment