[jboss-cvs] JBoss Messaging SVN: r3886 - in projects/network-benchmark: etc and 3 other directories.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Tue Mar 18 06:57:19 EDT 2008


Author: jmesnil
Date: 2008-03-18 06:57:18 -0400 (Tue, 18 Mar 2008)
New Revision: 3886

Added:
   projects/network-benchmark/.classpath
   projects/network-benchmark/.project
   projects/network-benchmark/etc/
   projects/network-benchmark/etc/log4j.xml
   projects/network-benchmark/lib/
   projects/network-benchmark/lib/log4j.jar
   projects/network-benchmark/lib/mina-core-2.0.0-M1.jar
   projects/network-benchmark/lib/mina-core-2.0.0-M2-20080317.150334-8.jar
   projects/network-benchmark/lib/slf4j-api-1.4.3.jar
   projects/network-benchmark/lib/slf4j-log4j12.jar
   projects/network-benchmark/src/
   projects/network-benchmark/src/network/
   projects/network-benchmark/src/network/BIOServer.java
   projects/network-benchmark/src/network/MINAServer.java
   projects/network-benchmark/src/network/NIOServer.java
   projects/network-benchmark/src/network/NetworkClientTest.java
Log:
Initial import.

Added: projects/network-benchmark/.classpath
===================================================================
--- projects/network-benchmark/.classpath	                        (rev 0)
+++ projects/network-benchmark/.classpath	2008-03-18 10:57:18 UTC (rev 3886)
@@ -0,0 +1,12 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<classpath>
+	<classpathentry kind="src" path="src"/>
+	<classpathentry kind="src" path="etc"/>
+	<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
+	<classpathentry kind="lib" path="lib/log4j.jar"/>
+	<classpathentry kind="lib" path="lib/slf4j-api-1.4.3.jar"/>
+	<classpathentry kind="lib" path="lib/slf4j-log4j12.jar"/>
+	<classpathentry kind="lib" path="lib/mina-core-2.0.0-M2-20080317.150334-8.jar"/>
+	<classpathentry kind="con" path="org.eclipse.jdt.junit.JUNIT_CONTAINER/3"/>
+	<classpathentry kind="output" path="bin"/>
+</classpath>

Added: projects/network-benchmark/.project
===================================================================
--- projects/network-benchmark/.project	                        (rev 0)
+++ projects/network-benchmark/.project	2008-03-18 10:57:18 UTC (rev 3886)
@@ -0,0 +1,17 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<projectDescription>
+	<name>network-benchmark</name>
+	<comment></comment>
+	<projects>
+	</projects>
+	<buildSpec>
+		<buildCommand>
+			<name>org.eclipse.jdt.core.javabuilder</name>
+			<arguments>
+			</arguments>
+		</buildCommand>
+	</buildSpec>
+	<natures>
+		<nature>org.eclipse.jdt.core.javanature</nature>
+	</natures>
+</projectDescription>

Added: projects/network-benchmark/etc/log4j.xml
===================================================================
--- projects/network-benchmark/etc/log4j.xml	                        (rev 0)
+++ projects/network-benchmark/etc/log4j.xml	2008-03-18 10:57:18 UTC (rev 3886)
@@ -0,0 +1,24 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE log4j:configuration SYSTEM "log4j.dtd">
+
+<!-- $Id: log4j.xml 1184 2006-08-03 18:52:12Z ovidiu.feodorov at jboss.com $ -->
+
+<log4j:configuration xmlns:log4j="http://jakarta.apache.org/log4j/" debug="false">
+
+   <appender name="CONSOLE" class="org.apache.log4j.ConsoleAppender">
+      <param name="Target" value="System.out"/>
+      <param name="Threshold" value="TRACE"/>
+      <layout class="org.apache.log4j.PatternLayout">
+         <param name="ConversionPattern" value="%t %d{ABSOLUTE} %-5p [%c{1}] %m%n"/>
+      </layout>
+   </appender>
+
+   <category name="org.apache">
+      <priority value="WARN"/>
+   </category>
+
+   <root>
+      <appender-ref ref="CONSOLE"/>
+   </root>
+
+</log4j:configuration>

Added: projects/network-benchmark/lib/log4j.jar
===================================================================
(Binary files differ)


Property changes on: projects/network-benchmark/lib/log4j.jar
___________________________________________________________________
Name: svn:mime-type
   + application/octet-stream

Added: projects/network-benchmark/lib/mina-core-2.0.0-M1.jar
===================================================================
(Binary files differ)


Property changes on: projects/network-benchmark/lib/mina-core-2.0.0-M1.jar
___________________________________________________________________
Name: svn:mime-type
   + application/octet-stream

Added: projects/network-benchmark/lib/mina-core-2.0.0-M2-20080317.150334-8.jar
===================================================================
(Binary files differ)


Property changes on: projects/network-benchmark/lib/mina-core-2.0.0-M2-20080317.150334-8.jar
___________________________________________________________________
Name: svn:mime-type
   + application/octet-stream

Added: projects/network-benchmark/lib/slf4j-api-1.4.3.jar
===================================================================
(Binary files differ)


Property changes on: projects/network-benchmark/lib/slf4j-api-1.4.3.jar
___________________________________________________________________
Name: svn:mime-type
   + application/octet-stream

Added: projects/network-benchmark/lib/slf4j-log4j12.jar
===================================================================
(Binary files differ)


Property changes on: projects/network-benchmark/lib/slf4j-log4j12.jar
___________________________________________________________________
Name: svn:mime-type
   + application/octet-stream

Added: projects/network-benchmark/src/network/BIOServer.java
===================================================================
--- projects/network-benchmark/src/network/BIOServer.java	                        (rev 0)
+++ projects/network-benchmark/src/network/BIOServer.java	2008-03-18 10:57:18 UTC (rev 3886)
@@ -0,0 +1,58 @@
+package network;
+import java.io.BufferedInputStream;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.net.ServerSocket;
+import java.net.Socket;
+
+public class BIOServer
+{
+   // Constants -----------------------------------------------------
+
+   // Attributes ----------------------------------------------------
+
+   // Static --------------------------------------------------------
+
+   // Constructors --------------------------------------------------
+
+   // Public --------------------------------------------------------
+
+   public static void main(String[] args) throws Exception
+   {
+      ServerSocket serverSocket = new ServerSocket();
+      serverSocket.bind(NetworkClientTest.BIO_ADDRESS);
+
+      System.out
+            .println("BIO Server bound to " + NetworkClientTest.BIO_ADDRESS);
+
+      byte[] b = new byte[NetworkClientTest.MESSAGE_SIZE];
+      
+      while (true)
+      {
+         Socket clientSocket = serverSocket.accept();
+         System.out.println("new client...");
+         OutputStream os = clientSocket.getOutputStream();
+
+         InputStream is = new BufferedInputStream(clientSocket.getInputStream());
+
+         while (is.read(b) != -1)
+         {
+            os.write(b);
+         }
+
+         os.close();
+
+         is.close();
+
+         clientSocket.close();
+      }
+   }
+
+   // Package protected ---------------------------------------------
+
+   // Protected -----------------------------------------------------
+
+   // Private -------------------------------------------------------
+
+   // Inner classes -------------------------------------------------
+}

Added: projects/network-benchmark/src/network/MINAServer.java
===================================================================
--- projects/network-benchmark/src/network/MINAServer.java	                        (rev 0)
+++ projects/network-benchmark/src/network/MINAServer.java	2008-03-18 10:57:18 UTC (rev 3886)
@@ -0,0 +1,53 @@
+package network;
+import org.apache.mina.common.IoBuffer;
+import org.apache.mina.common.IoHandlerAdapter;
+import org.apache.mina.common.IoSession;
+import org.apache.mina.transport.socket.nio.NioSocketAcceptor;
+
+public class MINAServer
+{
+   // Constants -----------------------------------------------------
+
+   // Attributes ----------------------------------------------------
+
+   // Static --------------------------------------------------------
+
+   // Constructors --------------------------------------------------
+
+   // Public --------------------------------------------------------
+
+   public static void main(String[] args) throws Exception
+   {
+      final NioSocketAcceptor server = new NioSocketAcceptor();
+      server.setCloseOnDeactivation(false);
+      server.setHandler(new IoHandlerAdapter()
+      {
+         public void messageReceived(IoSession session, Object message)
+               throws Exception
+         {
+            // System.out.print('S');
+            IoBuffer buffer = (IoBuffer) message;
+            session.write(buffer.duplicate());
+         }
+
+         @Override
+         public void sessionCreated(IoSession session) throws Exception
+         {
+            System.out.println("new client...");
+         }
+      });
+      server.bind(NetworkClientTest.MINA_ADDRESS);
+
+      System.out.println("MINA Server bound to "
+            + NetworkClientTest.MINA_ADDRESS);
+
+   }
+
+   // Package protected ---------------------------------------------
+
+   // Protected -----------------------------------------------------
+
+   // Private -------------------------------------------------------
+
+   // Inner classes -------------------------------------------------
+}

Added: projects/network-benchmark/src/network/NIOServer.java
===================================================================
--- projects/network-benchmark/src/network/NIOServer.java	                        (rev 0)
+++ projects/network-benchmark/src/network/NIOServer.java	2008-03-18 10:57:18 UTC (rev 3886)
@@ -0,0 +1,96 @@
+package network;
+import java.nio.ByteBuffer;
+import java.nio.channels.SelectionKey;
+import java.nio.channels.Selector;
+import java.nio.channels.ServerSocketChannel;
+import java.nio.channels.SocketChannel;
+import java.util.Iterator;
+import java.util.Set;
+
+public class NIOServer
+{
+   // Constants -----------------------------------------------------
+
+   // Attributes ----------------------------------------------------
+
+   // Static --------------------------------------------------------
+
+   // Constructors --------------------------------------------------
+
+   // Public --------------------------------------------------------
+
+   public static void main(String[] args) throws Exception
+   {
+      ServerSocketChannel server = ServerSocketChannel.open();
+      server.configureBlocking(false);
+      server.socket().bind(NetworkClientTest.NIO_ADDRESS);
+
+      System.out
+            .println("NIO Server bound to " + NetworkClientTest.NIO_ADDRESS);
+
+      Selector selector = Selector.open();
+      server.register(selector, SelectionKey.OP_ACCEPT);
+
+      // Wait for something of interest to happen
+      while (selector.select() > 0)
+      {
+         // Get set of ready objects
+         Set<SelectionKey> readyKeys = selector.selectedKeys();
+         Iterator<SelectionKey> readyItor = readyKeys.iterator();
+
+         // Walk through set
+         while (readyItor.hasNext())
+         {
+
+            // Get key from set
+            SelectionKey key = readyItor.next();
+
+            // Remove current entry
+            readyItor.remove();
+
+            if (key.isAcceptable())
+            {
+               // Get channel
+               ServerSocketChannel keyChannel = (ServerSocketChannel) key
+                     .channel();
+
+               // Accept request
+               SocketChannel socket = keyChannel.accept();
+               System.out.println("new client...");
+               socket.configureBlocking(false);
+               socket.register(selector, SelectionKey.OP_READ);
+            } else if (key.isReadable())
+            {
+               SocketChannel channel = (SocketChannel) key.channel();
+               ByteBuffer buf = ByteBuffer.allocate(NetworkClientTest.MESSAGE_SIZE);
+               int readBytes = channel.read(buf);
+               if (readBytes == 0)
+               {
+                  System.err.println("READ BUFFER UNDERRUN");
+               } else if (readBytes < 0)
+               {
+                  channel.close();
+                  key.cancel();
+                  // server.close();
+                  // selector.close();
+               } else
+               {
+                  buf.flip();
+                  if (channel.write(buf) == 0)
+                  {
+                     System.err.println("WRITE BUFFER FULL");
+                  }
+               }
+            }
+         }
+      }
+   }
+
+   // Package protected ---------------------------------------------
+
+   // Protected -----------------------------------------------------
+
+   // Private -------------------------------------------------------
+
+   // Inner classes -------------------------------------------------
+}

Added: projects/network-benchmark/src/network/NetworkClientTest.java
===================================================================
--- projects/network-benchmark/src/network/NetworkClientTest.java	                        (rev 0)
+++ projects/network-benchmark/src/network/NetworkClientTest.java	2008-03-18 10:57:18 UTC (rev 3886)
@@ -0,0 +1,320 @@
+package network;
+import static java.util.concurrent.TimeUnit.MILLISECONDS;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.net.InetSocketAddress;
+import java.net.Socket;
+import java.net.SocketAddress;
+import java.net.UnknownHostException;
+import java.util.concurrent.CountDownLatch;
+import java.util.concurrent.atomic.AtomicLong;
+
+import junit.framework.TestCase;
+
+import org.apache.mina.common.ConnectFuture;
+import org.apache.mina.common.IoBuffer;
+import org.apache.mina.common.IoHandlerAdapter;
+import org.apache.mina.common.IoSession;
+import org.apache.mina.common.ReadFuture;
+import org.apache.mina.transport.socket.nio.NioSocketConnector;
+
+public class NetworkClientTest extends TestCase
+{
+   // Constants -----------------------------------------------------
+
+   private static final String SERVER_HOST = "192.168.0.4";
+   public static final SocketAddress BIO_ADDRESS = new InetSocketAddress(
+         SERVER_HOST, 5555);
+   public static final SocketAddress NIO_ADDRESS = new InetSocketAddress(
+         SERVER_HOST, 6666);
+   public static final SocketAddress MINA_ADDRESS = new InetSocketAddress(
+         SERVER_HOST, 7777);
+
+   private static final long DURATION = 10000; // in ms   
+   public static final int MESSAGE_SIZE = 1000; // in bytes
+
+   // Attributes ----------------------------------------------------
+
+   // Static --------------------------------------------------------
+
+   static {
+      System.out.println("Duration: " + DURATION + " ms");
+      System.out.println("Message size: " + MESSAGE_SIZE + " bytes\n");
+   }
+
+   // Constructors --------------------------------------------------
+
+   // Public --------------------------------------------------------
+
+   
+   public void test_Blocking_BIOClient_To_BIOServer() throws Exception
+   {
+      startBlockingBioClient(BIO_ADDRESS);
+   }
+
+   public void test_NonBlocking_BIOClient_To_BIOServer() throws Exception
+   {
+      startNonBlockingBioClient(BIO_ADDRESS);
+   }
+
+   public void test_Blocking_BIOClient_To_NIOServer() throws Exception
+   {
+      startBlockingBioClient(NIO_ADDRESS);
+   }
+
+   public void test_NonBlocking_BIOClient_To_NIOServer() throws Exception
+   {
+      startNonBlockingBioClient(NIO_ADDRESS);
+   }
+
+   public void test_Blocking_BIOClient_To_MINAServer() throws Exception
+   {
+      startBlockingBioClient(MINA_ADDRESS);
+   }
+
+   public void test_NonBlocking_BIOClient_To_MINAServer() throws Exception
+   {
+      startNonBlockingBioClient(MINA_ADDRESS);
+   }
+
+   public void test_Blocking_MINAClient_To_BIOServer() throws Exception
+   {
+      startBlockingMINAClient(BIO_ADDRESS);
+   }
+
+   public void _test_NonBlocking_MINAClient_To_BIOServer() throws Exception
+   {
+      startNonBlockingMINAClient(BIO_ADDRESS);
+   }
+
+   public void test_Blocking_MINAClient_To_NIOServer() throws Exception
+   {
+      startBlockingMINAClient(NIO_ADDRESS);
+   }
+
+   public void _test_NonBlocking_MINAClient_To_NIOServer() throws Exception
+   {
+      startNonBlockingMINAClient(NIO_ADDRESS);
+   }
+
+   public void test_Blocking_MINAClient_To_MINAServer() throws Exception
+   {
+      startBlockingMINAClient(MINA_ADDRESS);
+   }
+
+   public void _test_NonBlocking_MINAClient_To_MINAServer() throws Exception
+   {
+      startNonBlockingMINAClient(MINA_ADDRESS);
+   }
+
+   // Package protected ---------------------------------------------
+
+   // Protected -----------------------------------------------------
+
+   // Private -------------------------------------------------------
+
+   private byte[] createMessage()
+   {
+      byte[] b = new byte[MESSAGE_SIZE];
+      for (int i = 0; i < b.length; i++)
+      {
+         b[i] = 66;
+      }
+      return b;
+   }
+   
+   private byte[] lastMessage()
+   {
+      byte[] b = new byte[MESSAGE_SIZE];
+      for (int i = 0; i < b.length; i++)
+      {
+         b[i] = 99;
+      }
+      return b;
+   }
+   
+   private void startBlockingBioClient(SocketAddress address)
+         throws UnknownHostException, IOException
+   {
+      Socket clientSocket = new Socket();
+      clientSocket.connect(address);
+      OutputStream os = clientSocket.getOutputStream();
+      InputStream is = clientSocket.getInputStream();
+      long start = System.currentTimeMillis();
+      int count = 0;
+      byte[] message = createMessage();
+      byte[] response = new byte[message.length];
+      while (System.currentTimeMillis() - start < DURATION)
+      {
+         os.write(message);
+         
+         int b = is.read(response);
+         if (b != MESSAGE_SIZE)
+         {
+            throw new IllegalStateException("Wrong byte");
+         }
+         count++;
+      }
+      clientSocket.close();
+
+      long periodInMs = System.currentTimeMillis() - start;
+      display(count, periodInMs);
+   }
+
+   private void startNonBlockingBioClient(SocketAddress address)
+         throws UnknownHostException, IOException, InterruptedException
+   {
+      final Socket clientSocket = new Socket();
+      clientSocket.connect(address);
+      OutputStream os = clientSocket.getOutputStream();
+      final InputStream is = clientSocket.getInputStream();
+      long start = System.currentTimeMillis();
+      final AtomicLong count = new AtomicLong(0);
+      final CountDownLatch latch = new CountDownLatch(1);
+      Thread receiver = new Thread()
+      {
+         @Override
+         public void run()
+         {
+            byte[] b = new byte[MESSAGE_SIZE];
+            
+            while (true)
+            {
+               try
+               {
+                  is.read(b);
+                  if (b[0] == 99)
+                  {
+                     latch.countDown();
+                     return;
+                  }
+                  if (b[0] != 66 && b[0] != 99)
+                  {
+                     throw new IllegalStateException("Wrong byte");
+                  }
+                  count.incrementAndGet();
+               } catch (IOException e)
+               {
+                  e.printStackTrace();
+               }
+            }
+         }
+      };
+
+      receiver.start();
+
+      byte[] message = createMessage();
+      while (System.currentTimeMillis() - start < DURATION)
+      {
+         os.write(message);
+      }
+      os.write(lastMessage());
+
+      latch.await();
+      clientSocket.close();
+
+      long periodInMs = System.currentTimeMillis() - start;
+      display(count.longValue(), periodInMs);
+   }
+
+   private void startBlockingMINAClient(SocketAddress address)
+   {
+      NioSocketConnector client = new NioSocketConnector();
+      client.getSessionConfig().setUseReadOperation(true);
+
+      final AtomicLong count = new AtomicLong(0);
+      client.setHandler(new IoHandlerAdapter()
+      {
+         @Override
+         public void messageReceived(IoSession session, Object message)
+               throws Exception
+         {
+            count.incrementAndGet();
+         }
+      });
+      ConnectFuture future = client.connect(address).awaitUninterruptibly();
+      IoSession session = future.getSession();
+
+      IoBuffer buffer = IoBuffer.allocate(MESSAGE_SIZE);
+      buffer.put(createMessage());
+      buffer.flip();
+
+      long start = System.currentTimeMillis();
+      while (System.currentTimeMillis() - start < DURATION)
+      {
+         session.write(buffer.duplicate());
+         ReadFuture readFuture = session.read();
+         readFuture.awaitUninterruptibly();
+         readFuture.getMessage();
+      }
+      session.close().awaitUninterruptibly(DURATION, MILLISECONDS);
+
+      long periodInMs = System.currentTimeMillis() - start;
+      display(count.longValue(), periodInMs);
+
+      client.dispose();
+   }
+
+   private void startNonBlockingMINAClient(SocketAddress address)
+         throws InterruptedException
+   {
+      NioSocketConnector client = new NioSocketConnector();
+      client.getSessionConfig().setUseReadOperation(true);
+
+      final AtomicLong count = new AtomicLong(0);
+      final CountDownLatch latch = new CountDownLatch(1);
+
+      client.setHandler(new IoHandlerAdapter()
+      {
+         byte[] b = new byte[MESSAGE_SIZE];
+         
+         @Override
+         public void messageReceived(IoSession session, Object message)
+               throws Exception
+         {
+            IoBuffer buffer = (IoBuffer) message;
+            buffer.get(b);
+            if (b[0] == 99)
+            {
+               latch.countDown();
+            }
+         }
+      });
+      ConnectFuture future = client.connect(address).awaitUninterruptibly();
+      IoSession session = future.getSession();
+
+      IoBuffer buffer = IoBuffer.allocate(MESSAGE_SIZE);
+      buffer.put(createMessage());
+      buffer.flip();
+
+      long start = System.currentTimeMillis();
+      while (System.currentTimeMillis() - start < DURATION)
+      {
+         session.write(buffer.duplicate());
+      }
+
+      buffer = IoBuffer.allocate(MESSAGE_SIZE);
+      buffer.put(lastMessage());
+      buffer.flip();
+      session.write(buffer).awaitUninterruptibly(DURATION, MILLISECONDS);
+
+      latch.await(2 * DURATION, MILLISECONDS);
+      session.close().awaitUninterruptibly();
+
+      long periodInMs = System.currentTimeMillis() - start;
+      display(count.longValue(), periodInMs);
+
+      client.dispose();
+   }
+
+   private void display(long count, long periodInMs)
+   {
+      String name = getName().replace("test_", "").replace('_', ' ');
+      double rate = 1000 * (double) count / periodInMs;
+      System.out.format("%-36s: %6.0f inv./s (%d inv. in %dms)\n", name, rate, count, periodInMs);
+   }
+
+   // Inner classes -------------------------------------------------
+}




More information about the jboss-cvs-commits mailing list