1 package org.jgroups.tests; 2 3 import java.net.ServerSocket ; 4 import java.net.InetAddress ; 5 import java.net.Socket ; 6 import java.io.IOException ; 7 import java.io.OutputStream ; 8 import java.io.InputStream ; 9 10 14 public class LargeStateClient { 15 Socket sock; 16 InetAddress bind_addr, host_addr; 17 boolean looping=true; 18 19 20 private void start(String bind_addr, String host_addr, int chunk) throws Exception { 21 this.bind_addr=InetAddress.getByName(bind_addr); 22 this.host_addr=InetAddress.getByName(host_addr); 23 sock=new Socket (this.host_addr, 7500, this.bind_addr, 0); 24 sock.setReceiveBufferSize(chunk); 25 readLargeState(sock); 26 sock.close(); 27 } 28 29 private void readLargeState(Socket sock) throws IOException { 30 InputStream in=sock.getInputStream(); 31 long total=0, start=0, stop; 32 byte[] buf=new byte[sock.getReceiveBufferSize()]; 33 int num; 34 35 start=System.currentTimeMillis(); 36 while(looping) { 37 num=in.read(buf, 0, buf.length); 38 if(num == -1) 39 break; 40 41 total+=num; 42 if(total % 100000000 == 0) 43 System.out.println("-- read " + (total / 1000000) + " MB"); 44 } 45 stop=System.currentTimeMillis(); 46 System.out.println("- done, read " + (total / 1000000) + " MB in " + (stop-start) + "ms (" + 47 (total / 1000000) / ((stop-start) / 1000.0) + " MB/sec"); 48 } 49 50 51 public static void main(String [] args) throws Exception { 52 String bind_addr=null, host="localhost"; 53 int chunk=10000; 54 55 for(int i=0; i < args.length; i++) { 56 if(args[i].equals("-bind_addr")) { 57 bind_addr=args[++i]; 58 continue; 59 } 60 if(args[i].equals("-host")) { 61 host=args[++i]; 62 continue; 63 } 64 if(args[i].equals("-chunk")) { 65 chunk=Integer.parseInt(args[++i]); 66 continue; 67 } 68 System.out.println("LargeStateServer [-bind_addr <addr>] [-host <host address>][-chunk <chunk size (bytes)>]"); 69 return; 70 } 71 new LargeStateClient().start(bind_addr, host, chunk); 72 } 73 74 75 } 76 | Popular Tags |