diff options
author | Marc Laukien <marc@zeroc.com> | 2003-08-04 21:05:32 +0000 |
---|---|---|
committer | Marc Laukien <marc@zeroc.com> | 2003-08-04 21:05:32 +0000 |
commit | f1fb23e7893a725708a6d1c5862ca61c61c3a4a7 (patch) | |
tree | 4830244ab9efe05d027b516dcde401aca1044b5d /java/demo/Ice/throughput/Client.java | |
parent | using eval strategy for user & core types (diff) | |
download | ice-f1fb23e7893a725708a6d1c5862ca61c61c3a4a7.tar.bz2 ice-f1fb23e7893a725708a6d1c5862ca61c61c3a4a7.tar.xz ice-f1fb23e7893a725708a6d1c5862ca61c61c3a4a7.zip |
throughput demo
Diffstat (limited to 'java/demo/Ice/throughput/Client.java')
-rw-r--r-- | java/demo/Ice/throughput/Client.java | 145 |
1 files changed, 132 insertions, 13 deletions
diff --git a/java/demo/Ice/throughput/Client.java b/java/demo/Ice/throughput/Client.java index 9a6fdc7a192..62495e1990a 100644 --- a/java/demo/Ice/throughput/Client.java +++ b/java/demo/Ice/throughput/Client.java @@ -14,6 +14,19 @@ public class Client { + private static void + menu() + { + System.out.println( + "usage:\n" + + "s: send byte sequence\n" + + "o: send byte sequence as oneway\n" + + "r: receive byte sequence\n" + + "e: echo (send and receive) byte sequence\n" + + "x: exit\n" + + "?: help\n"); + } + private static int run(String[] args, Ice.Communicator communicator) { @@ -33,26 +46,132 @@ public class Client System.err.println("invalid proxy"); return 1; } + ThroughputPrx throughputOneway = ThroughputPrxHelper.uncheckedCast(throughput.ice_oneway()); - // Initial ping to setup the connection. - throughput.ice_ping(); + byte[] seq = new byte[seqSize.value]; - long tmsec = System.currentTimeMillis(); + menu(); - final int repetitions = 100; + java.io.BufferedReader in = new java.io.BufferedReader(new java.io.InputStreamReader(System.in)); - System.out.println("sending and receiving " + repetitions + " sequences of size " + seqSize.value + - " (this may take a while)"); - byte[] seq = new byte[seqSize.value]; - for(int i = 0; i < repetitions; i++) + String line = null; + do { - throughput.echoByteSeq(seq); - } + try + { + System.out.print("==> "); + System.out.flush(); + line = in.readLine(); + if(line == null) + { + break; + } + + // Initial ping to setup the connection. + throughput.ice_ping(); + + long tmsec = System.currentTimeMillis(); + final int repetitions = 100; + + if(line.equals("s") || line.equals("o") || line.equals("r") || line.equals("e")) + { + char c = line.charAt(0); - double dmsec = System.currentTimeMillis() - tmsec; + switch(c) + { + case 's': + case 'o': + { + System.out.print("sending"); + break; + } + + case 'r': + { + System.out.print("receiving"); + break; + } + + case 'e': + { + System.out.print("sending and receiving"); + break; + } + } + + System.out.print(" " + repetitions + " sequences of size " + seqSize.value); + + if(c == 'o') + { + System.out.print(" as oneway"); + } + + System.out.println("..."); + + for(int i = 0; i < repetitions; ++i) + { + switch(c) + { + case 's': + { + throughput.sendByteSeq(seq); + break; + } + + case 'o': + { + throughputOneway.sendByteSeq(seq); + break; + } + + case 'r': + { + throughput.recvByteSeq(); + break; + } + + case 'e': + { + throughput.echoByteSeq(seq); + break; + } + } + } - System.out.println("time for " + repetitions + " sequences: " + dmsec + "ms"); - System.out.println("time per sequence: " + (dmsec / repetitions) + "ms"); + double dmsec = System.currentTimeMillis() - tmsec; + System.out.println("time for " + repetitions + " sequences: " + dmsec + "ms"); + System.out.println("time per sequence: " + dmsec / repetitions + "ms"); + double mbit = repetitions * seqSize.value * 8.0 / dmsec / 1000.0; + if(c == 'e') + { + mbit *= 2; + } + System.out.println("throughput: " + mbit + " MBit/s"); + } + else if(line.equals("x")) + { + // Nothing to do + } + else if(line.equals("?")) + { + menu(); + } + else + { + System.out.println("unknown command `" + line + "'"); + menu(); + } + } + catch(java.io.IOException ex) + { + ex.printStackTrace(); + } + catch(Ice.LocalException ex) + { + ex.printStackTrace(); + } + } + while(!line.equals("x")); return 0; } |