01: package org.jgroups.tests;
02:
03: import java.io.IOException;
04: import java.io.OutputStream;
05: import java.net.InetAddress;
06: import java.net.ServerSocket;
07: import java.net.Socket;
08:
09: /**
10: * @author Bela Ban
11: * @version $Id: LargeStateServer.java,v 1.1 2006/05/26 06:21:13 belaban Exp $
12: */
13: public class LargeStateServer {
14: ServerSocket srv_sock;
15: InetAddress bind_addr;
16:
17: private void start(String bind_addr, int chunk_size)
18: throws Exception {
19: this .bind_addr = InetAddress.getByName(bind_addr);
20: srv_sock = new ServerSocket(7500, 50, this .bind_addr);
21: while (true) {
22: System.out.println("-- waiting for clients to connect");
23: Socket sock = srv_sock.accept();
24: sock.setSendBufferSize(chunk_size);
25: sendLargeState(sock);
26: sock.close();
27: }
28: }
29:
30: private void sendLargeState(Socket sock) throws IOException {
31: long total = 0, start, stop;
32: OutputStream out = sock.getOutputStream();
33: start = System.currentTimeMillis();
34: for (int i = 0; i < 1000000; i++) {
35: byte[] buf = new byte[1000];
36: out.write(buf, 0, buf.length);
37: total += 1000;
38: if (total % 100000000 == 0)
39: System.out.println("-- sent " + (total / 1000000)
40: + " MB");
41: }
42: stop = System.currentTimeMillis();
43: out.close();
44: System.out.println("- done, wrote " + (total / 1000000)
45: + " MB in " + (stop - start) + "ms ("
46: + (total / 1000000) / ((stop - start) / 1000.0)
47: + " MB/sec");
48: }
49:
50: public static void main(String[] args) throws Exception {
51: String bind_addr = null;
52: int chunk = 10000;
53:
54: for (int i = 0; i < args.length; i++) {
55: if (args[i].equals("-bind_addr")) {
56: bind_addr = args[++i];
57: continue;
58: }
59: if (args[i].equals("-chunk")) {
60: chunk = Integer.parseInt(args[++i]);
61: continue;
62: }
63: System.out
64: .println("LargeStateServer [-bind_addr <addr>] [-chunk <size in bytes>]");
65: return;
66: }
67: new LargeStateServer().start(bind_addr, chunk);
68: }
69:
70: }
|