[jboss-cvs] JBoss Messaging SVN: r3908 - in projects/network-benchmark: src/network and 1 other directory.
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Fri Mar 21 11:51:19 EDT 2008
Author: jmesnil
Date: 2008-03-21 11:51:19 -0400 (Fri, 21 Mar 2008)
New Revision: 3908
Modified:
projects/network-benchmark/build.xml
projects/network-benchmark/src/network/NetworkClientTest.java
Log:
* tweaks
Modified: projects/network-benchmark/build.xml
===================================================================
--- projects/network-benchmark/build.xml 2008-03-21 12:58:16 UTC (rev 3907)
+++ projects/network-benchmark/build.xml 2008-03-21 15:51:19 UTC (rev 3908)
@@ -7,6 +7,7 @@
<project name="network benchmark" default="help">
<path id="classpath">
+ <pathelement path="etc/ "/>
<pathelement path="build/ "/>
<pathelement location="lib/junit.jar"/>
<pathelement location="lib/mina-core-2.0.0-M2-20080317.150334-8.jar"/>
@@ -27,6 +28,7 @@
<mkdir dir="build"/>
<javac srcdir="src" destdir="build"
classpathref="classpath"
+ debug="true"
/>
</target>
@@ -50,7 +52,6 @@
</target>
<target name="test" depends="compile" description="-> Run the tests">
- <mkdir dir="output" />
<junit showoutput="true">
<classpath>
<path refid="classpath"/>
@@ -62,7 +63,6 @@
</target>
<target name="clean">
- <delete dir="ouput/" />
<delete dir="build/" />
</target>
Modified: projects/network-benchmark/src/network/NetworkClientTest.java
===================================================================
--- projects/network-benchmark/src/network/NetworkClientTest.java 2008-03-21 12:58:16 UTC (rev 3907)
+++ projects/network-benchmark/src/network/NetworkClientTest.java 2008-03-21 15:51:19 UTC (rev 3908)
@@ -48,7 +48,7 @@
static {
System.out.println("Duration: " + DURATION + " ms");
System.out.println("Message size: " + MESSAGE_SIZE + " bytes");
- System.out.println("RESPONSE size: " + RESPONSE_SIZE + " bytes");
+ System.out.println("Response size: " + RESPONSE_SIZE + " bytes");
System.out.println("TCP no delay: " + ENABLE_TCP_NO_DELAY);
try
{
@@ -133,6 +133,35 @@
// Private -------------------------------------------------------
+ private static Socket newConfiguredSocket(SocketAddress address)
+ throws SocketException, IOException
+ {
+ Socket clientSocket = new Socket();
+ clientSocket.setReuseAddress(false);
+ clientSocket.setTcpNoDelay(ENABLE_TCP_NO_DELAY);
+ if (TCP_BUFFER_SIZE != -1)
+ {
+ clientSocket.setSendBufferSize(TCP_BUFFER_SIZE);
+ clientSocket.setReceiveBufferSize(TCP_BUFFER_SIZE);
+ }
+ clientSocket.connect(address);
+ return clientSocket;
+ }
+
+ private static NioSocketConnector newConfiguredConnector()
+ {
+ NioSocketConnector client = new NioSocketConnector();
+ client.getSessionConfig().setTcpNoDelay(ENABLE_TCP_NO_DELAY);
+ if (TCP_BUFFER_SIZE != -1)
+ {
+ client.getSessionConfig().setSendBufferSize(TCP_BUFFER_SIZE);
+ client.getSessionConfig().setReceiveBufferSize(TCP_BUFFER_SIZE);
+ }
+ client.getSessionConfig().setReuseAddress(false);
+ client.getSessionConfig().setUseReadOperation(true);
+ return client;
+ }
+
private byte[] createMessage()
{
byte[] b = new byte[MESSAGE_SIZE];
@@ -156,17 +185,10 @@
private void startBlockingBioClient(SocketAddress address)
throws UnknownHostException, IOException
{
- Socket clientSocket = new Socket();
- clientSocket.setReuseAddress(false);
- clientSocket.setTcpNoDelay(ENABLE_TCP_NO_DELAY);
- if (TCP_BUFFER_SIZE != -1)
- {
- clientSocket.setSendBufferSize(TCP_BUFFER_SIZE);
- clientSocket.setReceiveBufferSize(TCP_BUFFER_SIZE);
- }
- clientSocket.connect(address);
+ Socket clientSocket = newConfiguredSocket(address);
OutputStream os = clientSocket.getOutputStream();
InputStream is = clientSocket.getInputStream();
+
long start = System.currentTimeMillis();
int count = 0;
byte[] message = createMessage();
@@ -191,18 +213,11 @@
private void startNonBlockingBioClient(SocketAddress address)
throws UnknownHostException, IOException, InterruptedException
{
- final Socket clientSocket = new Socket();
- clientSocket.setReuseAddress(false);
- clientSocket.setTcpNoDelay(ENABLE_TCP_NO_DELAY);
- if (TCP_BUFFER_SIZE != -1)
- {
- clientSocket.setSendBufferSize(TCP_BUFFER_SIZE);
- clientSocket.setReceiveBufferSize(TCP_BUFFER_SIZE);
- }
- clientSocket.connect(address);
+ final Socket clientSocket = newConfiguredSocket(address);
OutputStream os = clientSocket.getOutputStream();
final InputStream is = clientSocket.getInputStream();
- final AtomicLong count = new AtomicLong(0);
+
+ final AtomicLong receivedCount = new AtomicLong(0);
final CountDownLatch latch = new CountDownLatch(1);
Thread receiver = new Thread()
{
@@ -215,7 +230,9 @@
{
try
{
- is.read(b);
+ int size = is.read(b);
+ if (size != RESPONSE_SIZE)
+ throw new IllegalStateException("Wrong size: " + size);
if (b[0] == 99)
{
latch.countDown();
@@ -225,10 +242,11 @@
{
throw new IllegalStateException("Wrong byte");
}
- count.incrementAndGet();
+ receivedCount.incrementAndGet();
} catch (IOException e)
{
e.printStackTrace();
+ return;
}
}
}
@@ -236,42 +254,34 @@
receiver.start();
+ byte[] message = createMessage();
long start = System.currentTimeMillis();
-
- byte[] message = createMessage();
while (System.currentTimeMillis() - start < DURATION)
{
os.write(message);
}
os.write(lastMessage());
-
- latch.await();
+
+ assertTrue("did not receive all responses", latch.await(4 * DURATION, MILLISECONDS));
+ long periodInMs = System.currentTimeMillis() - start;
+
clientSocket.close();
- long periodInMs = System.currentTimeMillis() - start;
- display(count.longValue(), periodInMs);
+ display(receivedCount.longValue(), periodInMs);
}
private void startBlockingMINAClient(SocketAddress address)
{
- NioSocketConnector client = new NioSocketConnector();
- client.getSessionConfig().setTcpNoDelay(ENABLE_TCP_NO_DELAY);
- if (TCP_BUFFER_SIZE != -1)
- {
- client.getSessionConfig().setSendBufferSize(TCP_BUFFER_SIZE);
- client.getSessionConfig().setReceiveBufferSize(TCP_BUFFER_SIZE);
- }
- client.getSessionConfig().setReuseAddress(false);
- client.getSessionConfig().setUseReadOperation(true);
-
- final AtomicLong count = new AtomicLong(0);
+ NioSocketConnector client = newConfiguredConnector();
+
+ final AtomicLong receivedCount = new AtomicLong(0);
client.setHandler(new IoHandlerAdapter()
{
@Override
public void messageReceived(IoSession session, Object message)
throws Exception
{
- count.incrementAndGet();
+ receivedCount.incrementAndGet();
}
});
ConnectFuture future = client.connect(address).awaitUninterruptibly();
@@ -281,18 +291,21 @@
buffer.put(createMessage());
buffer.flip();
+ long sentCount = 0;
long start = System.currentTimeMillis();
while (System.currentTimeMillis() - start < DURATION)
{
session.write(buffer.duplicate());
+ sentCount++;
ReadFuture readFuture = session.read();
readFuture.awaitUninterruptibly();
readFuture.getMessage();
}
session.close().awaitUninterruptibly(DURATION, MILLISECONDS);
+ assertEquals(sentCount, receivedCount.longValue());
long periodInMs = System.currentTimeMillis() - start;
- display(count.longValue(), periodInMs);
+ display(receivedCount.longValue(), periodInMs);
client.dispose();
}
@@ -300,17 +313,9 @@
private void startNonBlockingMINAClient(SocketAddress address)
throws InterruptedException
{
- NioSocketConnector client = new NioSocketConnector();
- client.getSessionConfig().setTcpNoDelay(ENABLE_TCP_NO_DELAY);
- if (TCP_BUFFER_SIZE != -1)
- {
- client.getSessionConfig().setSendBufferSize(TCP_BUFFER_SIZE);
- client.getSessionConfig().setReceiveBufferSize(TCP_BUFFER_SIZE);
- }
- client.getSessionConfig().setReuseAddress(false);
- client.getSessionConfig().setUseReadOperation(true);
+ NioSocketConnector client = newConfiguredConnector();
- final AtomicLong count = new AtomicLong(0);
+ final AtomicLong receivedCount = new AtomicLong(0);
final CountDownLatch latch = new CountDownLatch(1);
client.setHandler(new IoHandlerAdapter()
@@ -336,22 +341,30 @@
buffer.put(createMessage());
buffer.flip();
+ long sentCount = 0;
long start = System.currentTimeMillis();
while (System.currentTimeMillis() - start < DURATION)
{
session.write(buffer.duplicate());
+ sentCount++;
}
buffer = IoBuffer.allocate(MESSAGE_SIZE);
buffer.put(lastMessage());
buffer.flip();
session.write(buffer).awaitUninterruptibly(DURATION, MILLISECONDS);
+ sentCount++;
- latch.await(2 * DURATION, MILLISECONDS);
- session.close().awaitUninterruptibly();
+ boolean receivedLastResponse = latch.await(4 * DURATION, MILLISECONDS);
+ if (!receivedLastResponse)
+ {
+ fail("received " + receivedCount.longValue() + " responses on " + sentCount + "expected");
+ }
+ session.close().awaitUninterruptibly(DURATION, MILLISECONDS);
+ assertEquals(sentCount, receivedCount.longValue());
long periodInMs = System.currentTimeMillis() - start;
- display(count.longValue(), periodInMs);
+ display(receivedCount.longValue(), periodInMs);
client.dispose();
}
More information about the jboss-cvs-commits
mailing list