OW2 Consortium joram

Compare Revisions

Ignore whitespace Rev 6456 → Rev 6457

/trunk/joram/samples/src/joram/build.xml
113,16 → 113,6
<param name="osgi.conf" value="${conf.dir}/config.properties"/>
</antcall>
</target>
<!-- Start REST and a single server in NullTransaction mode -->
<target name="rest_server" depends="init"
description="--> Starts a single server in non-persistent mode and REST">
<antcall target="server">
<param name="sid" value="0"/>
<param name="a3.conf" value="${conf.dir}/centralized_a3servers.xml"/>
<param name="osgi.conf" value="${conf.dir}/config_rest.properties"/>
</antcall>
</target>
<!-- Start a single server with the shell commands -->
<target name="shell_server" depends="init"
299,7 → 289,59
<classpath path="${project.class.path}"/>
</java>
</target>
 
<!-- **************************************************
* Rest samples
************************************************** -->
<!-- Start REST and a single server in NullTransaction mode -->
<target name="rest_server" depends="init"
description="--> Starts a single server with REST/JMS API">
<antcall target="server">
<param name="sid" value="0"/>
<param name="a3.conf" value="${conf.dir}/ngt_a3servers.xml"/>
<param name="osgi.conf" value="${conf.dir}/config_rest.properties"/>
</antcall>
</target>
 
<!-- Runs the rest producer -->
<target name="rest.producer" depends="init"
description="--> Runs the rest sample producer">
<java classname="rest.Producer" failonerror="no" fork="yes"
dir="${run.dir}">
<classpath path="${project.class.path}"/>
</java>
</target>
 
<!-- Runs the rest consumer -->
<target name="rest.consumer" depends="init"
description="--> Runs the rest sample consumer">
<java classname="rest.Consumer" failonerror="no" fork="yes"
dir="${run.dir}">
<classpath path="${project.class.path}"/>
</java>
</target>
<!-- Runs the Rest PERFS producer -->
<target name="rest_perfs_prod_q" depends="simple_init"
description="--> Starts the Rest PERFS producer">
<java classname="rest.PerfProducer" failonerror="no" fork="yes"
dir="${run.dir}">
<classpath path="${project.class.path}"/>
<jvmarg line="-DNbClient=2 -DNbMsgPerRound=1000 -DRound=25 -DMsgSize=1000 -DMsgTransient=false -Dmps=250" />
</java>
</target>
<!-- Runs the Rest PERFS consumer -->
<target name="rest_perfs_cons_q" depends="simple_init"
description="--> Starts the Rest PERFS consumer">
<java classname="rest.PerfConsumer" failonerror="no" fork="yes"
dir="${run.dir}">
<classpath path="${project.class.path}"/>
<jvmarg line="-DNbClient=5 -DNbMsgPerRound=1000 -DRound=10" />
</java>
</target>
 
<!-- **************************************************
* Rest bridge Sample
************************************************** -->
364,36 → 406,36
</target>
<!-- Runs the rest performance producer: send X messages on queue -->
<target name="rest_perfs_prod_q" depends="simple_init"
description="--> Starts the Rest PERFS producer">
<java classname="restbridge.PerfProducer" failonerror="no" fork="yes"
dir="${run.dir}">
<classpath path="${project.class.path}"/>
<jvmarg line="-DNbMsgPerRound=1000 -DRound=10 -DasyncSend=true -DTransacted=false -DMsgSize=100 -DMsgTransient=false -Dmps=500" />
</java>
</target>
<target name="restbridge_perfs_prod_q" depends="simple_init"
description="--> Starts the Rest PERFS producer">
<java classname="restbridge.PerfProducer" failonerror="no" fork="yes"
dir="${run.dir}">
<classpath path="${project.class.path}"/>
<jvmarg line="-DNbMsgPerRound=100 -DRound=100 -DasyncSend=false -DTransacted=false -DMsgSize=1000 -DMsgTransient=false -Dmps=1000" />
</java>
</target>
<!-- Runs the performance producer: send X messages on queue -->
<target name="perfs_prod_q" depends="simple_init"
description="--> Starts the PERFS producer">
<java classname="perfs.Producer" failonerror="no" fork="yes"
dir="${run.dir}">
<classpath path="${project.class.path}"/>
<jvmarg line="-DNbMsgPerRound=1000 -DRound=10 -DasyncSend=false -DTransacted=false -DMsgSize=10000 -DMsgTransient=false -Dmps=150000" />
<arg line="queue"/>
</java>
</target>
<!-- Runs the rest performance consumer on queue -->
<target name="rest_perfs_cons_q" depends="simple_init"
description="--> Starts the Rest PERFS consumer">
<java classname="restbridge.PerfConsumer" failonerror="no" fork="yes"
dir="${run.dir}">
<classpath path="${project.class.path}"/>
<jvmarg line="-DNbMsgPerRound=1000 -DTransacted=false -DimplicitAck=false" />
</java>
</target>
<target name="restbridge_perfs_cons_q" depends="simple_init"
description="--> Starts the Rest PERFS consumer">
<java classname="restbridge.PerfConsumer" failonerror="no" fork="yes"
dir="${run.dir}">
<classpath path="${project.class.path}"/>
<jvmarg line="-DNbMsgPerRound=1000 -DTransacted=false -DimplicitAck=false" />
</java>
</target>
<!-- Runs the performance producer: send X messages on queue -->
<target name="perfs_prod_q" depends="simple_init"
description="--> Starts the PERFS producer">
<java classname="perfs.Producer" failonerror="no" fork="yes"
dir="${run.dir}">
<classpath path="${project.class.path}"/>
<jvmarg line="-DNbMsgPerRound=1000 -DRound=100 -DasyncSend=false -DTransacted=false -DMsgSize=100 -DMsgTransient=false -Dmps=150000" />
<arg line="queue"/>
</java>
</target>
<!-- Runs the performance sample consumer on queue -->
<target name="perfs_cons" depends="simple_init"
description="--> Starts the PERFS consumer">
/trunk/joram/samples/src/joram/rest/Producer.java
New file
0,0 → 1,70
package rest;
 
import java.net.URI;
import java.util.Set;
 
import javax.ws.rs.client.Client;
import javax.ws.rs.client.ClientBuilder;
import javax.ws.rs.client.Entity;
import javax.ws.rs.client.Invocation.Builder;
import javax.ws.rs.client.WebTarget;
import javax.ws.rs.core.Link;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
import javax.ws.rs.core.UriBuilder;
 
import org.glassfish.jersey.client.ClientConfig;
 
public class Producer {
 
public static void main(String[] args) {
ClientConfig config = new ClientConfig();
Client client = ClientBuilder.newClient(config);
WebTarget target = client.target(getBaseURI());
System.out.println(target.getUri());
 
// lookup the destination
Builder builder = target.path("jndi").path("queue").request();
Response response = builder.accept(MediaType.TEXT_PLAIN).head();
System.out.println("== lookup \"queue\" = " + response.getStatus());
print(response.getLinks());
URI uriCreateProd = client.target(response.getLink("create-producer"))
// .queryParam("name", "prod1")
.getUri();
 
// Create the producer
response = client.target(uriCreateProd)
.request()
.accept(MediaType.TEXT_PLAIN).post(null);
 
URI uriCloseProd = response.getLink("close-context").getUri();
URI uriSendNextMsg = response.getLink("send-next-message").getUri();
 
for (int i=0; i<10; i++) {
// Send next message
response = client.target(uriSendNextMsg).request()
.accept(MediaType.TEXT_PLAIN)
.post(Entity.entity("Test message#" + i, MediaType.TEXT_PLAIN));
 
System.out.println("== send-next-message = " + response.getStatus());
print(response.getLinks());
uriSendNextMsg = response.getLink("send-next-message").getUri();
}
// close the producer
response = client.target(uriCloseProd).request().accept(MediaType.TEXT_PLAIN).delete();
System.out.println("== close-producer = " + response.getStatus());
print(response.getLinks());
}
private static URI getBaseURI() {
return UriBuilder.fromUri("http://localhost:8989/joram/").build();
}
 
private static void print(Set<Link> links) {
System.out.println(" link :");
for (Link link : links)
System.out.println("\t" + link.getRel() + " : " + link.getUri());
}
}
Property changes:
Added: svn:mime-type
+ text/plain
/trunk/joram/samples/src/joram/rest/PerfConsumer.java
New file
0,0 → 1,119
package rest;
 
import java.net.URI;
import java.util.Set;
 
import javax.ws.rs.client.Client;
import javax.ws.rs.client.ClientBuilder;
import javax.ws.rs.client.Entity;
import javax.ws.rs.client.Invocation.Builder;
import javax.ws.rs.client.WebTarget;
import javax.ws.rs.core.Link;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
import javax.ws.rs.core.UriBuilder;
 
import org.glassfish.jersey.client.ClientConfig;
 
public class PerfConsumer implements Runnable {
static int NbClient = 1;
static int Round = 50;
static int NbMsgPerRound = 1000;
 
long travel = 0L;
 
long start = 0L;
long last = 0L;
 
long t1 = 0L;
 
public static void main(String[] args) {
NbClient = Integer.getInteger("NbClient", NbClient).intValue();
Round = Integer.getInteger("Round", Round).intValue();
NbMsgPerRound = Integer.getInteger("NbMsgPerRound", NbMsgPerRound).intValue();
 
System.out.println("NbMsg=" + (Round*NbMsgPerRound));
for (int i=0; i<NbClient; i++) {
new Thread(new PerfConsumer()).start();
}
}
 
public void run() {
ClientConfig config = new ClientConfig();
Client client = ClientBuilder.newClient(config);
WebTarget target = client.target(getBaseURI());
System.out.println(target.getUri());
 
// lookup the destination
Builder builder = target.path("jndi").path("queue").request();
Response response = builder.accept(MediaType.TEXT_PLAIN).head();
System.out.println("== lookup \"queue\" = " + response.getStatus());
print(response.getLinks());
 
URI uriCreateCons = client.target(response.getLink("create-consumer"))
// .queryParam("name", "cons1")
.queryParam("idle-timeout", "120000")
.getUri();
response = client.target(uriCreateCons)
.request()
.accept(MediaType.TEXT_PLAIN).post(null);
 
System.out.println("== create-consumer = " + response.getStatus());
print(response.getLinks());
 
URI uriCloseCons = response.getLink("close-context").getUri();
URI uriReceiveNextMsg = response.getLink("receive-next-message").getUri();
for (int i=0; i<(Round*NbMsgPerRound); i++) {
response = client.target(uriReceiveNextMsg)
.queryParam("timeout", "30000")
.request()
.accept(MediaType.TEXT_PLAIN)
.get();
String msg = response.readEntity(String.class);
 
last = System.currentTimeMillis();
// int index = msg.getIntProperty("index");
if (i == 0) start = t1 = last;
 
// long dt = (last - msg.getLongProperty("time"));
// travel += dt;
 
if ((i%NbMsgPerRound) == (NbMsgPerRound -1)) {
long x = (NbMsgPerRound * 1000L) / (last - t1);
t1 = last;
System.out.println("#" + ((i+1)/NbMsgPerRound) + " x " + NbMsgPerRound + " msg -> " + x + " msg/s " + (travel/i));
}
if (response.getStatus() == Response.Status.OK.getStatusCode() && msg != null) {
// System.out.println("== receive-next-message = " + response.getStatus() + ", msg = " + msg);
} else {
System.out.println("ERROR consume msg = " + msg + ", response = " + response);
}
}
 
long x = (Round * NbMsgPerRound * 1000L) / (last - start);
System.out.println("Moy -> " + x + " msg/s ");
response = client.target(uriCloseCons)
.request()
.accept(MediaType.TEXT_PLAIN)
.delete();
 
System.out.println("== close-consumer = " + response.getStatus());
print(response.getLinks());
}
private static URI getBaseURI() {
return UriBuilder.fromUri("http://localhost:8989/joram/").build();
}
 
private static void print(Set<Link> links) {
System.out.println(" link :");
for (Link link : links)
System.out.println("\t" + link.getRel() + " : " + link.getUri());
}
 
 
}
Property changes:
Added: svn:mime-type
+ text/plain
/trunk/joram/samples/src/joram/rest/Consumer.java
New file
0,0 → 1,80
package rest;
 
import java.net.URI;
import java.util.Set;
 
import javax.ws.rs.client.Client;
import javax.ws.rs.client.ClientBuilder;
import javax.ws.rs.client.Entity;
import javax.ws.rs.client.Invocation.Builder;
import javax.ws.rs.client.WebTarget;
import javax.ws.rs.core.Link;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
import javax.ws.rs.core.UriBuilder;
 
import org.glassfish.jersey.client.ClientConfig;
 
public class Consumer {
 
public static void main(String[] args) {
ClientConfig config = new ClientConfig();
Client client = ClientBuilder.newClient(config);
WebTarget target = client.target(getBaseURI());
System.out.println(target.getUri());
 
// lookup the destination
Builder builder = target.path("jndi").path("queue").request();
Response response = builder.accept(MediaType.TEXT_PLAIN).head();
System.out.println("== lookup \"queue\" = " + response.getStatus());
print(response.getLinks());
 
URI uriCreateCons = client.target(response.getLink("create-consumer"))
// .queryParam("name", "cons1")
.queryParam("idle-timeout", "120")
.getUri();
response = client.target(uriCreateCons)
.request()
.accept(MediaType.TEXT_PLAIN).post(null);
 
System.out.println("== create-consumer = " + response.getStatus());
print(response.getLinks());
 
URI uriCloseCons = response.getLink("close-context").getUri();
URI uriReceiveNextMsg = response.getLink("receive-next-message").getUri();
 
for (int i=0; i<10; i++) {
response = client.target(uriReceiveNextMsg)
.queryParam("timeout", "30000")
.request()
.accept(MediaType.TEXT_PLAIN)
.get();
 
String msg = response.readEntity(String.class);
if (response.getStatus() == Response.Status.OK.getStatusCode() && msg != null) {
System.out.println("== receive-next-message = " + response.getStatus() + ", msg = " + msg);
} else {
System.out.println("ERROR consume msg = " + msg + ", response = " + response);
}
}
 
response = client.target(uriCloseCons)
.request()
.accept(MediaType.TEXT_PLAIN)
.delete();
 
System.out.println("== close-consumer = " + response.getStatus());
print(response.getLinks());
}
private static URI getBaseURI() {
return UriBuilder.fromUri("http://localhost:8989/joram/").build();
}
 
private static void print(Set<Link> links) {
System.out.println(" link :");
for (Link link : links)
System.out.println("\t" + link.getRel() + " : " + link.getUri());
}
}
Property changes:
Added: svn:mime-type
+ text/plain
/trunk/joram/samples/src/joram/rest/PerfProducer.java
New file
0,0 → 1,133
package rest;
 
import java.net.URI;
import java.util.Set;
 
import javax.ws.rs.client.Client;
import javax.ws.rs.client.ClientBuilder;
import javax.ws.rs.client.Entity;
import javax.ws.rs.client.Invocation.Builder;
import javax.ws.rs.client.WebTarget;
import javax.ws.rs.core.Link;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
import javax.ws.rs.core.UriBuilder;
 
import org.glassfish.jersey.client.ClientConfig;
 
/**
* MessageProducer sending messages on queue or topic for performance statistics.
*/
public class PerfProducer implements Runnable {
static int NbClient = 1;
static int Round = 50;
static int NbMsgPerRound = 1000;
static int MsgSize = 1000;
static int mps = 10000;
 
static boolean MsgTransient = true;
static boolean SwapAllowed = false;
 
public static boolean getBoolean(String key, boolean def) {
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);
 
System.out.println("NbMsg=" + (Round*NbMsgPerRound) + ", MsgSize=" + MsgSize);
for (int i=0; i<NbClient; i++) {
new Thread(new PerfProducer()).start();
}
}
 
public void run() {
ClientConfig config = new ClientConfig();
Client client = ClientBuilder.newClient(config);
WebTarget target = client.target(getBaseURI());
System.out.println(target.getUri());
 
// lookup the destination
Builder builder = target.path("jndi").path("queue").request();
Response response = builder.accept(MediaType.TEXT_PLAIN).head();
System.out.println("== lookup \"queue\" = " + response.getStatus());
print(response.getLinks());
 
URI uriCreateProd = client.target(response.getLink("create-producer"))
// .queryParam("name", "prod1")
.getUri();
 
// Create the producer
response = client.target(uriCreateProd)
.request()
.accept(MediaType.TEXT_PLAIN).post(null);
 
URI uriCloseProd = response.getLink("close-context").getUri();
URI uriSendNextMsg = response.getLink("send-next-message").getUri();
 
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++) {
// Send next message
// msg.setLongProperty("time", System.currentTimeMillis());
// msg.setIntProperty("index", i);
response = client.target(uriSendNextMsg).request()
.accept(MediaType.TEXT_PLAIN)
.post(Entity.entity(new String(content), MediaType.TEXT_PLAIN));
uriSendNextMsg = response.getLink("send-next-message").getUri();
 
if ((i%NbMsgPerRound) == (NbMsgPerRound-1)) {
long dtx1 = (i * 1000L) / mps;
long dtx2 = System.currentTimeMillis() - start;
if (dtx1 > (dtx2 + 20)) {
dtx += (dtx1 - dtx2);
try {
Thread.sleep(dtx1 - dtx2);
} catch (InterruptedException exc) { }
}
if (dtx2 > 0)
System.out.println("sent=" + i + ", mps=" + ((((long) i) * 1000L)/dtx2));
else
System.out.println("sent=" + i);
}
}
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");
 
// close the producer
response = client.target(uriCloseProd).request().accept(MediaType.TEXT_PLAIN).delete();
System.out.println("== close-producer = " + response.getStatus());
print(response.getLinks());
}
private static URI getBaseURI() {
return UriBuilder.fromUri("http://localhost:8989/joram/").build();
}
 
private static void print(Set<Link> links) {
System.out.println(" link :");
for (Link link : links)
System.out.println("\t" + link.getRel() + " : " + link.getUri());
}
}
Property changes:
Added: svn:mime-type
+ text/plain