01: package org.jgroups.tests;
02:
03: import java.net.ServerSocket;
04: import java.net.InetAddress;
05: import java.net.Socket;
06: import java.io.IOException;
07: import java.io.OutputStream;
08: import java.io.InputStream;
09:
10: /**
11: * @author Bela Ban
12: * @version $Id: LargeStateClient.java,v 1.1 2006/05/26 06:21:13 belaban Exp $
13: */
14: public class LargeStateClient {
15: Socket sock;
16: InetAddress bind_addr, host_addr;
17: boolean looping = true;
18:
19: private void start(String bind_addr, String host_addr, int chunk)
20: 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)
44: + " MB");
45: }
46: stop = System.currentTimeMillis();
47: System.out.println("- done, read " + (total / 1000000)
48: + " MB in " + (stop - start) + "ms ("
49: + (total / 1000000) / ((stop - start) / 1000.0)
50: + " MB/sec");
51: }
52:
53: public static void main(String[] args) throws Exception {
54: String bind_addr = null, host = "localhost";
55: int chunk = 10000;
56:
57: for (int i = 0; i < args.length; i++) {
58: if (args[i].equals("-bind_addr")) {
59: bind_addr = args[++i];
60: continue;
61: }
62: if (args[i].equals("-host")) {
63: host = args[++i];
64: continue;
65: }
66: if (args[i].equals("-chunk")) {
67: chunk = Integer.parseInt(args[++i]);
68: continue;
69: }
70: System.out
71: .println("LargeStateServer [-bind_addr <addr>] [-host <host address>][-chunk <chunk size (bytes)>]");
72: return;
73: }
74: new LargeStateClient().start(bind_addr, host, chunk);
75: }
76:
77: }
|