Author: fhanik Date: Thu Jul 6 06:52:19 2006 New Revision: 419553 URL: http://svn.apache.org/viewvc?rev=419553&view=rev Log: More tests to track down an NIO send problem that only happens on linux
Added: tomcat/container/tc5.5.x/modules/groupcom/test/java/org/apache/catalina/tribes/test/transport/SocketNioValidateSend.java tomcat/container/tc5.5.x/modules/groupcom/test/java/org/apache/catalina/tribes/test/transport/SocketTribesReceive.java tomcat/container/tc5.5.x/modules/groupcom/test/java/org/apache/catalina/tribes/test/transport/SocketValidateReceive.java Modified: tomcat/container/tc5.5.x/modules/groupcom/test/java/org/apache/catalina/tribes/test/transport/SocketNioReceive.java tomcat/container/tc5.5.x/modules/groupcom/test/java/org/apache/catalina/tribes/test/transport/SocketNioSend.java tomcat/container/tc5.5.x/modules/groupcom/test/java/org/apache/catalina/tribes/test/transport/SocketReceive.java tomcat/container/tc5.5.x/modules/groupcom/test/java/org/apache/catalina/tribes/test/transport/SocketSend.java Modified: tomcat/container/tc5.5.x/modules/groupcom/test/java/org/apache/catalina/tribes/test/transport/SocketNioReceive.java URL: http://svn.apache.org/viewvc/tomcat/container/tc5.5.x/modules/groupcom/test/java/org/apache/catalina/tribes/test/transport/SocketNioReceive.java?rev=419553&r1=419552&r2=419553&view=diff ============================================================================== --- tomcat/container/tc5.5.x/modules/groupcom/test/java/org/apache/catalina/tribes/test/transport/SocketNioReceive.java (original) +++ tomcat/container/tc5.5.x/modules/groupcom/test/java/org/apache/catalina/tribes/test/transport/SocketNioReceive.java Thu Jul 6 06:52:19 2006 @@ -40,7 +40,7 @@ synchronized (mutex) { mutex.wait(5000); if ( start != 0 ) { - System.out.println("Throughput " + df.format(mb / seconds) + " MB/seconds, messages "+count+" accepts "+accept); + System.out.println("Throughput " + df.format(mb / seconds) + " MB/seconds, messages "+count+" accepts "+accept+", total "+mb+" MB."); } } }catch (Throwable x) { @@ -63,7 +63,7 @@ if ( ( (count) % 10000) == 0) { long time = System.currentTimeMillis(); seconds = ( (double) (time - start)) / 1000; - System.out.println("Throughput " + df.format(mb / seconds) + " MB/seconds, messages "+count); + System.out.println("Throughput " + df.format(mb / seconds) + " MB/seconds, messages "+count+", total "+mb+" MB."); } } Modified: tomcat/container/tc5.5.x/modules/groupcom/test/java/org/apache/catalina/tribes/test/transport/SocketNioSend.java URL: http://svn.apache.org/viewvc/tomcat/container/tc5.5.x/modules/groupcom/test/java/org/apache/catalina/tribes/test/transport/SocketNioSend.java?rev=419553&r1=419552&r2=419553&view=diff ============================================================================== --- tomcat/container/tc5.5.x/modules/groupcom/test/java/org/apache/catalina/tribes/test/transport/SocketNioSend.java (original) +++ tomcat/container/tc5.5.x/modules/groupcom/test/java/org/apache/catalina/tribes/test/transport/SocketNioSend.java Thu Jul 6 06:52:19 2006 @@ -12,6 +12,7 @@ import java.util.Iterator; import org.apache.catalina.tribes.Channel; import org.apache.catalina.tribes.io.ChannelData; +import java.math.BigDecimal; public class SocketNioSend { @@ -25,6 +26,8 @@ data.setMessage(new XByteBuffer(buf,false)); buf = XByteBuffer.createDataPackage(data); int len = buf.length; + BigDecimal total = new BigDecimal((double)0); + BigDecimal bytes = new BigDecimal((double)len); NioSender sender = new NioSender(); sender.setDestination(mbr); sender.setDirectBuffer(true); @@ -63,13 +66,14 @@ int readyOps = sk.readyOps(); sk.interestOps(sk.interestOps() & ~readyOps); if (sender.process(sk, false)) { + total = total.add(bytes); sender.reset(); sender.setMessage(buf); mb += ( (double) len) / 1024 / 1024; if ( ( (++count) % 10000) == 0) { long time = System.currentTimeMillis(); double seconds = ( (double) (time - start)) / 1000; - System.out.println("Throughput " + df.format(mb / seconds) + " MB/seconds"); + System.out.println("Throughput " + df.format(mb / seconds) + " MB/seconds, total "+mb+" MB, total "+total+" bytes."); } } @@ -79,5 +83,7 @@ } } } + System.out.println("Complete, sleeping 15 seconds"); + Thread.sleep(15000); } } Added: tomcat/container/tc5.5.x/modules/groupcom/test/java/org/apache/catalina/tribes/test/transport/SocketNioValidateSend.java URL: http://svn.apache.org/viewvc/tomcat/container/tc5.5.x/modules/groupcom/test/java/org/apache/catalina/tribes/test/transport/SocketNioValidateSend.java?rev=419553&view=auto ============================================================================== --- tomcat/container/tc5.5.x/modules/groupcom/test/java/org/apache/catalina/tribes/test/transport/SocketNioValidateSend.java (added) +++ tomcat/container/tc5.5.x/modules/groupcom/test/java/org/apache/catalina/tribes/test/transport/SocketNioValidateSend.java Thu Jul 6 06:52:19 2006 @@ -0,0 +1,90 @@ +package org.apache.catalina.tribes.test.transport; + +import java.io.OutputStream; +import java.net.Socket; +import java.text.DecimalFormat; +import org.apache.catalina.tribes.transport.nio.NioSender; +import org.apache.catalina.tribes.membership.MemberImpl; +import java.nio.channels.Selector; +import org.apache.catalina.tribes.io.XByteBuffer; +import org.apache.catalina.tribes.Member; +import java.nio.channels.SelectionKey; +import java.util.Iterator; +import org.apache.catalina.tribes.Channel; +import org.apache.catalina.tribes.io.ChannelData; +import java.math.BigDecimal; +import java.util.Arrays; + +public class SocketNioValidateSend { + + public static void main(String[] args) throws Exception { + Selector selector = Selector.open(); + Member mbr = new MemberImpl("localhost", 9999, 0); + byte seq = 0; + byte[] buf = new byte[50000]; + Arrays.fill(buf,seq); + int len = buf.length; + BigDecimal total = new BigDecimal((double)0); + BigDecimal bytes = new BigDecimal((double)len); + NioSender sender = new NioSender(); + sender.setDestination(mbr); + sender.setDirectBuffer(true); + sender.setSelector(selector); + sender.connect(); + sender.setMessage(buf); + System.out.println("Writing to 9999"); + long start = 0; + double mb = 0; + boolean first = true; + int count = 0; + + DecimalFormat df = new DecimalFormat("##.00"); + while (count<100000) { + if (first) { + first = false; + start = System.currentTimeMillis(); + } + sender.setMessage(buf); + int selectedKeys = 0; + try { + selectedKeys = selector.select(0); + } catch (Exception e) { + e.printStackTrace(); + continue; + } + + if (selectedKeys == 0) { + continue; + } + + Iterator it = selector.selectedKeys().iterator(); + while (it.hasNext()) { + SelectionKey sk = (SelectionKey) it.next(); + it.remove(); + try { + int readyOps = sk.readyOps(); + sk.interestOps(sk.interestOps() & ~readyOps); + if (sender.process(sk, false)) { + total = total.add(bytes); + sender.reset(); + seq++; + Arrays.fill(buf,seq); + sender.setMessage(buf); + mb += ( (double) len) / 1024 / 1024; + if ( ( (++count) % 10000) == 0) { + long time = System.currentTimeMillis(); + double seconds = ( (double) (time - start)) / 1000; + System.out.println("Throughput " + df.format(mb / seconds) + " MB/seconds, total "+mb+" MB, total "+total+" bytes."); + } + } + + } catch (Throwable t) { + t.printStackTrace(); + return; + } + } + } + System.out.println("Complete, sleeping 15 seconds"); + Thread.sleep(15000); + } +} Modified: tomcat/container/tc5.5.x/modules/groupcom/test/java/org/apache/catalina/tribes/test/transport/SocketReceive.java URL: http://svn.apache.org/viewvc/tomcat/container/tc5.5.x/modules/groupcom/test/java/org/apache/catalina/tribes/test/transport/SocketReceive.java?rev=419553&r1=419552&r2=419553&view=diff ============================================================================== --- tomcat/container/tc5.5.x/modules/groupcom/test/java/org/apache/catalina/tribes/test/transport/SocketReceive.java (original) +++ tomcat/container/tc5.5.x/modules/groupcom/test/java/org/apache/catalina/tribes/test/transport/SocketReceive.java Thu Jul 6 06:52:19 2006 @@ -4,32 +4,59 @@ import java.net.Socket; import java.io.InputStream; import java.text.DecimalFormat; +import java.math.BigDecimal; public class SocketReceive { + static long start = 0; + static double mb = 0; + static byte[] buf = new byte[8192 * 4]; + static boolean first = true; + static int count = 0; + static DecimalFormat df = new DecimalFormat("##.00"); + static BigDecimal total = new BigDecimal(0); + static BigDecimal bytes = new BigDecimal(32871); + public static void main(String[] args) throws Exception { ServerSocket srvSocket = new ServerSocket(9999); System.out.println("Listening on 9999"); Socket socket = srvSocket.accept(); + socket.setReceiveBufferSize(43800); InputStream in = socket.getInputStream(); - long start = 0; - double mb = 0; - byte[] buf = new byte[8192 * 4]; - boolean first = true; - int count = 0; - DecimalFormat df = new DecimalFormat("##.00"); + Thread t = new Thread() { + public void run() { + while ( true ) { + try { + Thread.sleep(1000); + printStats(start, mb, count, df, total); + }catch ( Exception x ) {} + } + } + }; + t.setDaemon(true); + t.start(); + while ( true ) { if ( first ) { first = false; start = System.currentTimeMillis();} int len = in.read(buf); - if ( len == -1 ) System.exit(1); + if ( len == -1 ) { + printStats(start, mb, count, df, total); + System.exit(1); + } + if ( bytes.intValue() != len ) bytes = new BigDecimal((double)len); + total = total.add(bytes); mb += ( (double) len) / 1024 / 1024; if ( ((++count) % 10000) == 0 ) { - long time = System.currentTimeMillis(); - double seconds = ((double)(time-start))/1000; - System.out.println("Throughput "+df.format(mb/seconds)+" MB/seconds"); + printStats(start, mb, count, df, total); } } + } + + private static void printStats(long start, double mb, int count, DecimalFormat df, BigDecimal total) { + long time = System.currentTimeMillis(); + double seconds = ((double)(time-start))/1000; + System.out.println("Throughput "+df.format(mb/seconds)+" MB/seconds messages "+count+", total "+mb+" MB, total "+total+" bytes."); } } Modified: tomcat/container/tc5.5.x/modules/groupcom/test/java/org/apache/catalina/tribes/test/transport/SocketSend.java URL: http://svn.apache.org/viewvc/tomcat/container/tc5.5.x/modules/groupcom/test/java/org/apache/catalina/tribes/test/transport/SocketSend.java?rev=419553&r1=419552&r2=419553&view=diff ============================================================================== --- tomcat/container/tc5.5.x/modules/groupcom/test/java/org/apache/catalina/tribes/test/transport/SocketSend.java (original) +++ tomcat/container/tc5.5.x/modules/groupcom/test/java/org/apache/catalina/tribes/test/transport/SocketSend.java Thu Jul 6 06:52:19 2006 @@ -8,10 +8,13 @@ import org.apache.catalina.tribes.Member; import org.apache.catalina.tribes.io.ChannelData; import org.apache.catalina.tribes.Channel; +import java.math.BigDecimal; public class SocketSend { public static void main(String[] args) throws Exception { + + Member mbr = new MemberImpl("localhost", 9999, 0); ChannelData data = new ChannelData(); data.setOptions(Channel.SEND_OPTIONS_BYTE_MESSAGE); @@ -20,7 +23,9 @@ data.setMessage(new XByteBuffer(buf,false)); buf = XByteBuffer.createDataPackage(data); int len = buf.length; - + System.out.println("Message size:"+len+" bytes"); + BigDecimal total = new BigDecimal((double)0); + BigDecimal bytes = new BigDecimal((double)len); Socket socket = new Socket("localhost",9999); System.out.println("Writing to 9999"); OutputStream out = socket.getOutputStream(); @@ -31,14 +36,18 @@ DecimalFormat df = new DecimalFormat("##.00"); while ( count<100000 ) { if ( first ) { first = false; start = System.currentTimeMillis();} - out.write(buf); + out.write(buf,0,buf.length); mb += ( (double) buf.length) / 1024 / 1024; + total = total.add(bytes); if ( ((++count) % 10000) == 0 ) { long time = System.currentTimeMillis(); double seconds = ((double)(time-start))/1000; - System.out.println("Throughput "+df.format(mb/seconds)+" MB/seconds messages "+count); + System.out.println("Throughput "+df.format(mb/seconds)+" MB/seconds messages "+count+", total "+mb+" MB, total "+total+" bytes."); } } + out.flush(); + System.out.println("Complete, sleeping 5 seconds"); + Thread.sleep(5000); } } Added: tomcat/container/tc5.5.x/modules/groupcom/test/java/org/apache/catalina/tribes/test/transport/SocketTribesReceive.java URL: http://svn.apache.org/viewvc/tomcat/container/tc5.5.x/modules/groupcom/test/java/org/apache/catalina/tribes/test/transport/SocketTribesReceive.java?rev=419553&view=auto ============================================================================== --- tomcat/container/tc5.5.x/modules/groupcom/test/java/org/apache/catalina/tribes/test/transport/SocketTribesReceive.java (added) +++ tomcat/container/tc5.5.x/modules/groupcom/test/java/org/apache/catalina/tribes/test/transport/SocketTribesReceive.java Thu Jul 6 06:52:19 2006 @@ -0,0 +1,69 @@ +package org.apache.catalina.tribes.test.transport; + +import java.net.ServerSocket; +import java.net.Socket; +import java.io.InputStream; +import java.text.DecimalFormat; +import java.math.BigDecimal; +import org.apache.catalina.tribes.io.XByteBuffer; + +public class SocketTribesReceive { + static long start = 0; + static double mb = 0; + //static byte[] buf = new byte[32871]; + static byte[] buf = new byte[1024]; + static boolean first = true; + static int count = 0; + static DecimalFormat df = new DecimalFormat("##.00"); + static BigDecimal total = new BigDecimal(0); + static BigDecimal bytes = new BigDecimal(32871); + + + public static void main(String[] args) throws Exception { + XByteBuffer xbuf = new XByteBuffer(43800,true); + ServerSocket srvSocket = new ServerSocket(9999); + System.out.println("Listening on 9999"); + Socket socket = srvSocket.accept(); + socket.setReceiveBufferSize(43800); + InputStream in = socket.getInputStream(); + Thread t = new Thread() { + public void run() { + while ( true ) { + try { + Thread.sleep(1000); + printStats(start, mb, count, df, total); + }catch ( Exception x ) {} + } + } + }; + t.setDaemon(true); + t.start(); + + while ( true ) { + if ( first ) { first = false; start = System.currentTimeMillis();} + int len = in.read(buf); + if ( len == -1 ) { + printStats(start, mb, count, df, total); + System.exit(1); + } + xbuf.append(buf,0,len); + if ( bytes.intValue() != len ) bytes = new BigDecimal((double)len); + total = total.add(bytes); + while ( xbuf.countPackages(true) > 0 ) { + xbuf.extractPackage(true); + count++; + } + mb += ( (double) len) / 1024 / 1024; + if ( ((count) % 10000) == 0 ) { + printStats(start, mb, count, df, total); + } + } + + } + + private static void printStats(long start, double mb, int count, DecimalFormat df, BigDecimal total) { + long time = System.currentTimeMillis(); + double seconds = ((double)(time-start))/1000; + System.out.println("Throughput "+df.format(mb/seconds)+" MB/seconds messages "+count+", total "+mb+" MB, total "+total+" bytes."); + } +} \ No newline at end of file Added: tomcat/container/tc5.5.x/modules/groupcom/test/java/org/apache/catalina/tribes/test/transport/SocketValidateReceive.java URL: http://svn.apache.org/viewvc/tomcat/container/tc5.5.x/modules/groupcom/test/java/org/apache/catalina/tribes/test/transport/SocketValidateReceive.java?rev=419553&view=auto ============================================================================== --- tomcat/container/tc5.5.x/modules/groupcom/test/java/org/apache/catalina/tribes/test/transport/SocketValidateReceive.java (added) +++ tomcat/container/tc5.5.x/modules/groupcom/test/java/org/apache/catalina/tribes/test/transport/SocketValidateReceive.java Thu Jul 6 06:52:19 2006 @@ -0,0 +1,89 @@ +package org.apache.catalina.tribes.test.transport; + +import java.net.ServerSocket; +import java.net.Socket; +import java.io.InputStream; +import java.text.DecimalFormat; +import java.math.BigDecimal; + +public class SocketValidateReceive { + static long start = 0; + static double mb = 0; + static byte[] buf = new byte[8192 * 4]; + static boolean first = true; + static int count = 0; + static DecimalFormat df = new DecimalFormat("##.00"); + static BigDecimal total = new BigDecimal(0); + static BigDecimal bytes = new BigDecimal(32871); + + + public static void main(String[] args) throws Exception { + + ServerSocket srvSocket = new ServerSocket(9999); + System.out.println("Listening on 9999"); + Socket socket = srvSocket.accept(); + socket.setReceiveBufferSize(43800); + InputStream in = socket.getInputStream(); + MyDataReader reader = new MyDataReader(50000); + Thread t = new Thread() { + public void run() { + while ( true ) { + try { + Thread.sleep(1000); + printStats(start, mb, count, df, total); + }catch ( Exception x ) {} + } + } + }; + t.setDaemon(true); + t.start(); + + while ( true ) { + if ( first ) { first = false; start = System.currentTimeMillis();} + int len = in.read(buf); + if ( len == -1 ) { + printStats(start, mb, count, df, total); + System.exit(1); + } + count += reader.append(buf,0,len); + + if ( bytes.intValue() != len ) bytes = new BigDecimal((double)len); + total = total.add(bytes); + mb += ( (double) len) / 1024 / 1024; + if ( ((count) % 10000) == 0 ) { + printStats(start, mb, count, df, total); + } + } + + } + + private static void printStats(long start, double mb, int count, DecimalFormat df, BigDecimal total) { + long time = System.currentTimeMillis(); + double seconds = ((double)(time-start))/1000; + System.out.println("Throughput "+df.format(mb/seconds)+" MB/seconds messages "+count+", total "+mb+" MB, total "+total+" bytes."); + } + + public static class MyDataReader { + byte[] data = new byte[43800]; + int length = 10; + int cur = 0; + byte seq = 0; + public MyDataReader(int len) { + length = len; + } + + public int append(byte[] b, int off, int len) throws Exception { + int packages = 0; + for ( int i=off; i<len; i++ ) { + if ( cur == length ) { + cur = 0; + seq++; + packages++; + } + if ( b[i] != seq ) throw new Exception("mismatch on seq:"+seq+" and byte nr:"+cur+" count:"+count+" packages:"+packages); + cur++; + } + return packages; + } + } +} \ No newline at end of file --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]