[jboss-cvs] JBoss Messaging SVN: r3891 - projects/network-benchmark/src/network.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Wed Mar 19 04:31:04 EDT 2008


Author: jmesnil
Date: 2008-03-19 04:31:04 -0400 (Wed, 19 Mar 2008)
New Revision: 3891

Modified:
   projects/network-benchmark/src/network/NetworkClientTest.java
Log:
* set TCP send buffer size only TCP_SEND_BUFFER_SIZE != -1

Modified: projects/network-benchmark/src/network/NetworkClientTest.java
===================================================================
--- projects/network-benchmark/src/network/NetworkClientTest.java	2008-03-18 13:05:52 UTC (rev 3890)
+++ projects/network-benchmark/src/network/NetworkClientTest.java	2008-03-19 08:31:04 UTC (rev 3891)
@@ -1,4 +1,5 @@
 package network;
+
 import static java.util.concurrent.TimeUnit.MILLISECONDS;
 
 import java.io.IOException;
@@ -7,6 +8,7 @@
 import java.net.InetSocketAddress;
 import java.net.Socket;
 import java.net.SocketAddress;
+import java.net.SocketException;
 import java.net.UnknownHostException;
 import java.util.concurrent.CountDownLatch;
 import java.util.concurrent.atomic.AtomicLong;
@@ -24,11 +26,11 @@
 {
    // Configurable properties:
    private static final String SERVER_HOST = "192.168.0.4";
-   private static final long DURATION = 10000; // in ms   
+   private static final long DURATION = 10000; // in ms
    public static final int MESSAGE_SIZE = 1000; // in bytes
-   private static final boolean  ENABLE_TCP_NO_DELAY = false;
-   private static final int TCP_SEND_BUFFER_SIZE = 8192; //16258; // 8192 by default on Linux, 131070 on Mac OS X
-   
+   private static final boolean ENABLE_TCP_NO_DELAY = false;
+   private static final int TCP_SEND_BUFFER_SIZE = -1; // -1 to not set it
+
    // Constants -----------------------------------------------------
 
    public static final SocketAddress BIO_ADDRESS = new InetSocketAddress(
@@ -46,7 +48,15 @@
       System.out.println("Duration: " + DURATION + " ms");
       System.out.println("Message size: " + MESSAGE_SIZE + " bytes");
       System.out.println("TCP no delay: " + ENABLE_TCP_NO_DELAY);
-      System.out.println("TCP send buffer size: " + TCP_SEND_BUFFER_SIZE + " bytes\n");
+      try
+      {
+         System.out.println("TCP send buffer size: " + TCP_SEND_BUFFER_SIZE
+               + " (default hint: " + (new Socket()).getSendBufferSize()
+               + ")\n");
+      } catch (SocketException e)
+      {
+         e.printStackTrace();
+      }
    }
 
    // Constructors --------------------------------------------------
@@ -145,7 +155,8 @@
    {
       Socket clientSocket = new Socket();
       clientSocket.setTcpNoDelay(ENABLE_TCP_NO_DELAY);
-      clientSocket.setSendBufferSize(TCP_SEND_BUFFER_SIZE);
+      if (TCP_SEND_BUFFER_SIZE != -1)
+         clientSocket.setSendBufferSize(TCP_SEND_BUFFER_SIZE);
       clientSocket.connect(address);
       OutputStream os = clientSocket.getOutputStream();
       InputStream is = clientSocket.getInputStream();
@@ -174,12 +185,13 @@
          throws UnknownHostException, IOException, InterruptedException
    {
       final Socket clientSocket = new Socket();
+      clientSocket.setReuseAddress(false);
       clientSocket.setTcpNoDelay(ENABLE_TCP_NO_DELAY);
-      clientSocket.setSendBufferSize(TCP_SEND_BUFFER_SIZE);
+      if (TCP_SEND_BUFFER_SIZE != -1)
+         clientSocket.setSendBufferSize(TCP_SEND_BUFFER_SIZE);
       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()
@@ -214,6 +226,8 @@
 
       receiver.start();
 
+      long start = System.currentTimeMillis();
+
       byte[] message = createMessage();
       while (System.currentTimeMillis() - start < DURATION)
       {
@@ -232,7 +246,9 @@
    {
       NioSocketConnector client = new NioSocketConnector();
       client.getSessionConfig().setTcpNoDelay(ENABLE_TCP_NO_DELAY);
-      client.getSessionConfig().setSendBufferSize(TCP_SEND_BUFFER_SIZE);
+      if (TCP_SEND_BUFFER_SIZE != -1)
+         client.getSessionConfig().setSendBufferSize(TCP_SEND_BUFFER_SIZE);
+      client.getSessionConfig().setReuseAddress(false);
       client.getSessionConfig().setUseReadOperation(true);
 
       final AtomicLong count = new AtomicLong(0);
@@ -273,7 +289,9 @@
    {
       NioSocketConnector client = new NioSocketConnector();
       client.getSessionConfig().setTcpNoDelay(ENABLE_TCP_NO_DELAY);
-      client.getSessionConfig().setSendBufferSize(TCP_SEND_BUFFER_SIZE);
+      if (TCP_SEND_BUFFER_SIZE != -1)
+         client.getSessionConfig().setSendBufferSize(TCP_SEND_BUFFER_SIZE);
+      client.getSessionConfig().setReuseAddress(false);
       client.getSessionConfig().setUseReadOperation(true);
 
       final AtomicLong count = new AtomicLong(0);




More information about the jboss-cvs-commits mailing list