From 23318003737645a81186de06861c975ba9d4ba7e Mon Sep 17 00:00:00 2001 From: Qualia Li Date: Mon, 20 Feb 2017 16:41:58 -0800 Subject: [PATCH 01/18] update --- src/main/java/edu/berkeley/bid/comm/Machine.java | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/main/java/edu/berkeley/bid/comm/Machine.java b/src/main/java/edu/berkeley/bid/comm/Machine.java index 12713587..b91b14c3 100644 --- a/src/main/java/edu/berkeley/bid/comm/Machine.java +++ b/src/main/java/edu/berkeley/bid/comm/Machine.java @@ -53,6 +53,9 @@ public class Machine { public Machine(Network p0, Groups groups0, int imachine0, int M0, boolean useLong0, int bufsize, boolean doSim0, int trace0, int replicate0, InetSocketAddress [] workers0) { + //TODO + log("new Machine initialized"); + network = p0; M = M0; doSim = doSim0; @@ -529,9 +532,10 @@ public boolean sendrecv(int ith, ByteBuffer sbuf, int sendn, int outi, ByteBuffe static String debug="debug"; - static public void log(String msg) { + public void log(String msg) { int zero=0; int error=1/zero; + System.out.println(error); if (network != null) { synchronized (network) { System.out.print(msg); From 6c64edaabc9674eba2b9dc160cfbc32662c3e03e Mon Sep 17 00:00:00 2001 From: Qualia Li Date: Mon, 20 Feb 2017 16:54:04 -0800 Subject: [PATCH 02/18] update --- .../java/edu/berkeley/bid/comm/Machine.java | 22 +++---------------- 1 file changed, 3 insertions(+), 19 deletions(-) diff --git a/src/main/java/edu/berkeley/bid/comm/Machine.java b/src/main/java/edu/berkeley/bid/comm/Machine.java index b91b14c3..030210a5 100644 --- a/src/main/java/edu/berkeley/bid/comm/Machine.java +++ b/src/main/java/edu/berkeley/bid/comm/Machine.java @@ -53,9 +53,6 @@ public class Machine { public Machine(Network p0, Groups groups0, int imachine0, int M0, boolean useLong0, int bufsize, boolean doSim0, int trace0, int replicate0, InetSocketAddress [] workers0) { - //TODO - log("new Machine initialized"); - network = p0; M = M0; doSim = doSim0; @@ -303,10 +300,6 @@ public void run() { ostr.writeInt(msg.sender); ostr.writeInt(msg.tag); ostr.write(msg.buf, 0, msg.size*4); - - //TODO: log - log(String.format("Machine %d round %d sent packet dest %d len %d bytes\n", imachine, round, dest, msg.size*4)); - } } catch (Exception e) { if (trace > 0) log(String.format("Machine %d round %d problem writing socket "+e+"\n", imachine, round)); @@ -355,10 +348,7 @@ public void run() { int tag0 = tag % (3*D); if (!msgrecvd[src][tag0]) { Msg msg = new Msg(len, src, imachine, tag); - istr.readFully(msg.buf, 0, len*4); //len*4 is number of bytes to read - //TODO: log - log(String.format("Machine %d round %d got packet src %d len %d bytes\n", imachine, round, src, len*4)); - + istr.readFully(msg.buf, 0, len*4); synchronized (Machine.this) { if (!msgrecvd[src][tag0]) { messages[src][tag0] = msg; @@ -530,19 +520,13 @@ public boolean sendrecv(int ith, ByteBuffer sbuf, int sendn, int outi, ByteBuffe } } - static String debug="debug"; - public void log(String msg) { - int zero=0; - int error=1/zero; - System.out.println(error); if (network != null) { synchronized (network) { - System.out.print(msg); + System.out.print(msg); } } else { System.out.print(msg); } } -} - +} \ No newline at end of file From 8b60748d40fa5a07db1f6e64a3aa9fb35fca1316 Mon Sep 17 00:00:00 2001 From: Qualia Li Date: Mon, 20 Feb 2017 17:13:00 -0800 Subject: [PATCH 03/18] update --- .../java/edu/berkeley/bid/comm/Machine.java | 20 +++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/src/main/java/edu/berkeley/bid/comm/Machine.java b/src/main/java/edu/berkeley/bid/comm/Machine.java index 030210a5..abd018de 100644 --- a/src/main/java/edu/berkeley/bid/comm/Machine.java +++ b/src/main/java/edu/berkeley/bid/comm/Machine.java @@ -1,8 +1,6 @@ package edu.berkeley.bid.comm; -import java.io.DataInputStream; -import java.io.DataOutputStream; -import java.io.IOException; +import java.io.*; import java.net.InetSocketAddress; import java.net.ServerSocket; import java.net.Socket; @@ -521,12 +519,18 @@ public boolean sendrecv(int ith, ByteBuffer sbuf, int sendn, int outi, ByteBuffe } public void log(String msg) { - if (network != null) { - synchronized (network) { - System.out.print(msg); + File f=new File("\\log"); + try { + BufferedWriter bw = new BufferedWriter(new FileWriter(f)); + if (network != null) { + synchronized (network) { + bw.append(msg); + } + } else { + bw.append(msg); } - } else { - System.out.print(msg); + }catch (Exception e){ + System.out.println("file not found"); } } } \ No newline at end of file From df711275e92d9b99e30fe0cbd221ea0d1cc614fe Mon Sep 17 00:00:00 2001 From: Qualia Li Date: Wed, 22 Feb 2017 16:54:08 -0800 Subject: [PATCH 04/18] print network flow --- .../java/edu/berkeley/bid/comm/Machine.java | 1060 +++++++++-------- 1 file changed, 546 insertions(+), 514 deletions(-) diff --git a/src/main/java/edu/berkeley/bid/comm/Machine.java b/src/main/java/edu/berkeley/bid/comm/Machine.java index abd018de..fe36eb40 100644 --- a/src/main/java/edu/berkeley/bid/comm/Machine.java +++ b/src/main/java/edu/berkeley/bid/comm/Machine.java @@ -13,524 +13,556 @@ import java.util.Enumeration; public class Machine { - /* Machine Configuration Variables */ - public final int D; // Depth of the network - public final int M; // Number of Machines - public final int imachine; // My identity - public final Groups groups; // group membership indices - public final int replicate; // replication factor - public final InetSocketAddress [] workers; // IP/socket - public final boolean doSim; // Simulation on one machine: send messages directly without sockets - public int trace = 0; // 0: no trace, 1: high-level, 2: everything - public int sockBase = 50050; // Socket base address - public int sockOffset = 2; // Leave space for peer and control ports - public int sendTimeout = 1000; // in msec - public int recvTimeout = 1000; - public int configTimeout = 1000; - public int reduceTimeout = 1000; - public boolean useLong = false; - public int round; - public int maxk = 0; - - public Vec tov; // Snapshot of the reduced matrix at each layer going down - public Vec fromv; // Snapshot of the result matrix coming up - public Layer [] layers; // All the layers - public ByteBuffer [] sendbuf; // buffers, one for each destination in a group - public ByteBuffer [] recbuf; - public IVec finalMap; // Map from to --> up at layer D-1 - public Msg [][] messages; // Message queue - public boolean [][] msgrecvd; // Receiver status - public boolean [][] amsending; // Sender status - public ExecutorService executor; - public ExecutorService sockExecutor; - public Listener listener; - public Future listenerFuture; - public Hashtable> writers; - public Hashtable> readers; - Network network; - - public Machine(Network p0, Groups groups0, int imachine0, int M0, boolean useLong0, int bufsize, boolean doSim0, int trace0, - int replicate0, InetSocketAddress [] workers0) { - network = p0; - M = M0; - doSim = doSim0; - imachine = imachine0; - groups = groups0; - replicate = replicate0; - useLong = useLong0; - writers = new Hashtable>(); - readers = new Hashtable>(); - if (workers0 == null) { - workers = new InetSocketAddress[M*replicate]; - for (int i = 0; i < M*replicate; i++) workers[i] = new InetSocketAddress("localhost",sockBase+i*sockOffset); - } else { - workers = workers0; - } - D = groups.depth(); - trace = trace0; - layers = new Layer[D]; - round = 0; - int cumk = 1; - maxk = 1; - int cumPos = 0; - for (int level = 0; level < D; level++) { - int k = groups.nodesInGroup(imachine, level).length; - maxk = Math.max(maxk, k); - } - sendbuf = new ByteBuffer[maxk]; - recbuf = new ByteBuffer[maxk]; - for (int i = 0; i < maxk; i++) { - sendbuf[i] = ByteBuffer.wrap(new byte[4*bufsize]); - recbuf[i] = ByteBuffer.wrap(new byte[4*bufsize]); - } - messages = new Msg[M*replicate][]; - msgrecvd = new boolean[M*replicate][]; - amsending = new boolean[M*replicate][]; - for (int i = 0; i < M*replicate; i++) { - messages[i] = new Msg[3*D]; - msgrecvd[i] = new boolean[3*D]; - amsending[i] = new boolean[3*D]; - } - for (int level = 0; level < D; level++) { - int k = groups.nodesInGroup(imachine, level).length; - int pos = groups.posInGroup(imachine, level); - if (useLong) { - layers[level] = new LongLayer(this, k, cumk, cumPos, pos, level); - } else { - layers[level] = new Layer(this, k, cumk, cumPos, pos, level); - } - cumPos = cumPos * k + pos; - cumk *= k; - } - } - - public void start(int maxk) { - executor = Executors.newFixedThreadPool(maxk+6); // set to 1 for sequential messaging. - sockExecutor = Executors.newFixedThreadPool(4+4*maxk); - for (int level = 0; level < D; level++) { - layers[level].executor = executor; - } - listener = new Listener(); - listenerFuture = sockExecutor.submit(listener); - } - - public void stop() { - if (sockExecutor != null) { - listener.stop(true); - listenerFuture.cancel(true); - sockExecutor.shutdownNow(); - } - if (executor != null) executor.shutdownNow(); - } - - public void waitForComms() { - waitForReads(); - waitForWrites(); - } - - public void waitForReads() { - Enumeration se = readers.keys(); - while (se.hasMoreElements()) { - SockReader s = se.nextElement(); - Future fut = null; - synchronized (readers) { - fut = readers.get(s); - } - while (fut != null && !fut.isDone()) { - try { - Thread.sleep(1); - } catch (Exception e) {} - } - synchronized (readers) { - readers.remove(s); - } - } - } - - public void waitForWrites() { - Enumeration se = writers.keys(); - while (se.hasMoreElements()) { - SockWriter s = se.nextElement(); - Future fut = null; - synchronized (writers) { - fut = writers.get(s); - } - while (fut != null && !fut.isDone()) { - try { - Thread.sleep(1); - } catch (Exception e) {} - } - synchronized (writers) { - writers.remove(s); - } - } - } - - public void clearFlags() { - for (int i = 0; i < M*replicate; i++) { - for (int j = 0; j < 3*D; j++) { - if (messages[i][j] != null) { - log(String.format("clearing m %d t %d\n", i, j)); - } - messages[i][j] = null; - msgrecvd[i][j] = false; - amsending[i][j] = false; - } - } - } - - public void config(IVec toi, IVec fromi, int round0) { + /* Machine Configuration Variables */ + public final int D; // Depth of the network + public final int M; // Number of Machines + public final int imachine; // My identity + public final Groups groups; // group membership indices + public final int replicate; // replication factor + public final InetSocketAddress[] workers; // IP/socket + public final boolean doSim; // Simulation on one machine: send messages directly without sockets + public int trace = 0; // 0: no trace, 1: high-level, 2: everything + public int sockBase = 50050; // Socket base address + public int sockOffset = 2; // Leave space for peer and control ports + public int sendTimeout = 1000; // in msec + public int recvTimeout = 1000; + public int configTimeout = 1000; + public int reduceTimeout = 1000; + public boolean useLong = false; + public int round; + public int maxk = 0; + + public Vec tov; // Snapshot of the reduced matrix at each layer going down + public Vec fromv; // Snapshot of the result matrix coming up + public Layer[] layers; // All the layers + public ByteBuffer[] sendbuf; // buffers, one for each destination in a group + public ByteBuffer[] recbuf; + public IVec finalMap; // Map from to --> up at layer D-1 + public Msg[][] messages; // Message queue + public boolean[][] msgrecvd; // Receiver status + public boolean[][] amsending; // Sender status + public ExecutorService executor; + public ExecutorService sockExecutor; + public Listener listener; + public Future listenerFuture; + public Hashtable> writers; + public Hashtable> readers; + Network network; + + public Machine(Network p0, Groups groups0, int imachine0, int M0, boolean useLong0, int bufsize, boolean doSim0, int trace0, + int replicate0, InetSocketAddress[] workers0) { + network = p0; + M = M0; + doSim = doSim0; + imachine = imachine0; + groups = groups0; + replicate = replicate0; + useLong = useLong0; + writers = new Hashtable>(); + readers = new Hashtable>(); + if (workers0 == null) { + workers = new InetSocketAddress[M * replicate]; + for (int i = 0; i < M * replicate; i++) + workers[i] = new InetSocketAddress("localhost", sockBase + i * sockOffset); + } else { + workers = workers0; + } + D = groups.depth(); + trace = trace0; + layers = new Layer[D]; + round = 0; + int cumk = 1; + maxk = 1; + int cumPos = 0; + for (int level = 0; level < D; level++) { + int k = groups.nodesInGroup(imachine, level).length; + maxk = Math.max(maxk, k); + } + sendbuf = new ByteBuffer[maxk]; + recbuf = new ByteBuffer[maxk]; + for (int i = 0; i < maxk; i++) { + sendbuf[i] = ByteBuffer.wrap(new byte[4 * bufsize]); + recbuf[i] = ByteBuffer.wrap(new byte[4 * bufsize]); + } + messages = new Msg[M * replicate][]; + msgrecvd = new boolean[M * replicate][]; + amsending = new boolean[M * replicate][]; + for (int i = 0; i < M * replicate; i++) { + messages[i] = new Msg[3 * D]; + msgrecvd[i] = new boolean[3 * D]; + amsending[i] = new boolean[3 * D]; + } + for (int level = 0; level < D; level++) { + int k = groups.nodesInGroup(imachine, level).length; + int pos = groups.posInGroup(imachine, level); + if (useLong) { + layers[level] = new LongLayer(this, k, cumk, cumPos, pos, level); + } else { + layers[level] = new Layer(this, k, cumk, cumPos, pos, level); + } + cumPos = cumPos * k + pos; + cumk *= k; + } + } + + public void start(int maxk) { + executor = Executors.newFixedThreadPool(maxk + 6); // set to 1 for sequential messaging. + sockExecutor = Executors.newFixedThreadPool(4 + 4 * maxk); + for (int level = 0; level < D; level++) { + layers[level].executor = executor; + } + listener = new Listener(); + listenerFuture = sockExecutor.submit(listener); + } + + public void stop() { + if (sockExecutor != null) { + listener.stop(true); + listenerFuture.cancel(true); + sockExecutor.shutdownNow(); + } + if (executor != null) executor.shutdownNow(); + } + + public void waitForComms() { + waitForReads(); + waitForWrites(); + } + + public void waitForReads() { + Enumeration se = readers.keys(); + while (se.hasMoreElements()) { + SockReader s = se.nextElement(); + Future fut = null; + synchronized (readers) { + fut = readers.get(s); + } + while (fut != null && !fut.isDone()) { + try { + Thread.sleep(1); + } catch (Exception e) { + } + } + synchronized (readers) { + readers.remove(s); + } + } + } + + public void waitForWrites() { + Enumeration se = writers.keys(); + while (se.hasMoreElements()) { + SockWriter s = se.nextElement(); + Future fut = null; + synchronized (writers) { + fut = writers.get(s); + } + while (fut != null && !fut.isDone()) { + try { + Thread.sleep(1); + } catch (Exception e) { + } + } + synchronized (writers) { + writers.remove(s); + } + } + } + + public void clearFlags() { + for (int i = 0; i < M * replicate; i++) { + for (int j = 0; j < 3 * D; j++) { + if (messages[i][j] != null) { + log(String.format("clearing m %d t %d\n", i, j)); + } + messages[i][j] = null; + msgrecvd[i][j] = false; + amsending[i][j] = false; + } + } + } + + public void config(IVec toi, IVec fromi, int round0) { // clearFlags(); - round = round0; - IVec [] outputs = new IVec[2]; - for (int i = 0; i < D; i++) { - layers[i].config(toi, fromi, outputs, round0); - toi = outputs[0]; - fromi = outputs[1]; - } - finalMap = IVec.mapInds(fromi, toi); - } - - public void config(int [] toi, int [] fromi, int round) { - config(new IVec(toi), new IVec(fromi), round); - } - - public void config(LVec toi, LVec fromi, int round0) { - round = round0; - LVec [] outputs = new LVec[2]; - for (int i = 0; i < D; i++) { - ((LongLayer)layers[i]).config(toi, fromi, outputs, round0); - toi = outputs[0]; - fromi = outputs[1]; - } - finalMap = LVec.mapInds(fromi, toi); - } - - public void config(long [] toi, long [] fromi, int round) { - config(new LVec(toi), new LVec(fromi), round); - } - - - public Vec reduce(Vec tov0, int stride, int round0) { - round = round0; - tov = tov0; - for (int d = 0; d < D; d++) { - tov = layers[d].reduceDown(tov, stride, round0); - } - fromv = tov.mapFrom(finalMap, stride); - for (int d = D-1; d >= 0; d--) { - fromv = layers[d].reduceUp(fromv, stride, round0); - } - if (trace > 1) log(String.format("Reduce machine %d result nnz %d out of %d\n", imachine, fromv.nnz(), fromv.size())); - return fromv; - } - - public float [] reduce(float [] tov, int stride, int round) { - return reduce(new Vec(tov), stride, round).data; - } - - public Vec configReduce(IVec toi, IVec fromi, Vec tov0, int stride, int round0) { + round = round0; + IVec[] outputs = new IVec[2]; + for (int i = 0; i < D; i++) { + layers[i].config(toi, fromi, outputs, round0); + toi = outputs[0]; + fromi = outputs[1]; + } + finalMap = IVec.mapInds(fromi, toi); + } + + public void config(int[] toi, int[] fromi, int round) { + config(new IVec(toi), new IVec(fromi), round); + } + + public void config(LVec toi, LVec fromi, int round0) { + round = round0; + LVec[] outputs = new LVec[2]; + for (int i = 0; i < D; i++) { + ((LongLayer) layers[i]).config(toi, fromi, outputs, round0); + toi = outputs[0]; + fromi = outputs[1]; + } + finalMap = LVec.mapInds(fromi, toi); + } + + public void config(long[] toi, long[] fromi, int round) { + config(new LVec(toi), new LVec(fromi), round); + } + + + public Vec reduce(Vec tov0, int stride, int round0) { + round = round0; + tov = tov0; + for (int d = 0; d < D; d++) { + tov = layers[d].reduceDown(tov, stride, round0); + } + fromv = tov.mapFrom(finalMap, stride); + for (int d = D - 1; d >= 0; d--) { + fromv = layers[d].reduceUp(fromv, stride, round0); + } + if (trace > 1) + log(String.format("Reduce machine %d result nnz %d out of %d\n", imachine, fromv.nnz(), fromv.size())); + return fromv; + } + + public float[] reduce(float[] tov, int stride, int round) { + return reduce(new Vec(tov), stride, round).data; + } + + public Vec configReduce(IVec toi, IVec fromi, Vec tov0, int stride, int round0) { // clearFlags(); - round = round0; - tov = tov0; - IVec [] outputs = new IVec[2]; - for (int d = 0; d < D; d++) { - tov = layers[d].configReduce(toi, fromi, outputs, tov, stride, round0); - toi = outputs[0]; - fromi = outputs[1]; - } - finalMap = IVec.mapInds(fromi, toi); - fromv = tov.mapFrom(finalMap, stride); - for (int d = D-1; d >= 0; d--) { - fromv = layers[d].reduceUp(fromv, stride, round0); - } - if (trace > 1) log(String.format("ConfigReduce machine %d result nnz %d out of %d\n", imachine, fromv.nnz(), fromv.size())); - return fromv; - } - - public float [] configReduce(int [] toi, int [] fromi, float [] tov, int stride, int round) { - return configReduce(new IVec(toi), new IVec(fromi), new Vec(tov), stride, round).data; - } - - public Vec configReduce(LVec toi, LVec fromi, Vec tov0, int stride, int round0) { - round = round0; - tov = tov0; - LVec [] outputs = new LVec[2]; - for (int d = 0; d < D; d++) { - tov = ((LongLayer)layers[d]).configReduce(toi, fromi, outputs, tov, stride, round0); - toi = outputs[0]; - fromi = outputs[1]; - } - finalMap = LVec.mapInds(fromi, toi); - fromv = tov.mapFrom(finalMap, stride); - for (int d = D-1; d >= 0; d--) { - fromv = layers[d].reduceUp(fromv, stride, round0); - } - if (trace > 1) log(String.format("ConfigReduce machine %d result nnz %d out of %d\n", imachine, fromv.nnz(), fromv.size())); - return fromv; - } - - public float [] configReduce(long [] toi, long [] fromi, float [] tov, int stride, int round) { - return configReduce(new LVec(toi), new LVec(fromi), new Vec(tov), stride, round).data; - } - - - - public class SockWriter implements Runnable { - int dest; - Msg msg; - - public SockWriter(int dest0, Msg msg0) { - msg = msg0; - dest = dest0; - } - - public void run() { - Socket socket = null; + round = round0; + tov = tov0; + IVec[] outputs = new IVec[2]; + for (int d = 0; d < D; d++) { + tov = layers[d].configReduce(toi, fromi, outputs, tov, stride, round0); + toi = outputs[0]; + fromi = outputs[1]; + } + finalMap = IVec.mapInds(fromi, toi); + fromv = tov.mapFrom(finalMap, stride); + for (int d = D - 1; d >= 0; d--) { + fromv = layers[d].reduceUp(fromv, stride, round0); + } + if (trace > 1) + log(String.format("ConfigReduce machine %d result nnz %d out of %d\n", imachine, fromv.nnz(), fromv.size())); + return fromv; + } + + public float[] configReduce(int[] toi, int[] fromi, float[] tov, int stride, int round) { + return configReduce(new IVec(toi), new IVec(fromi), new Vec(tov), stride, round).data; + } + + public Vec configReduce(LVec toi, LVec fromi, Vec tov0, int stride, int round0) { + round = round0; + tov = tov0; + LVec[] outputs = new LVec[2]; + for (int d = 0; d < D; d++) { + tov = ((LongLayer) layers[d]).configReduce(toi, fromi, outputs, tov, stride, round0); + toi = outputs[0]; + fromi = outputs[1]; + } + finalMap = LVec.mapInds(fromi, toi); + fromv = tov.mapFrom(finalMap, stride); + for (int d = D - 1; d >= 0; d--) { + fromv = layers[d].reduceUp(fromv, stride, round0); + } + if (trace > 1) + log(String.format("ConfigReduce machine %d result nnz %d out of %d\n", imachine, fromv.nnz(), fromv.size())); + return fromv; + } + + public float[] configReduce(long[] toi, long[] fromi, float[] tov, int stride, int round) { + return configReduce(new LVec(toi), new LVec(fromi), new Vec(tov), stride, round).data; + } + + + public class SockWriter implements Runnable { + int dest; + Msg msg; + + public SockWriter(int dest0, Msg msg0) { + msg = msg0; + dest = dest0; + } + + public void run() { + Socket socket = null; // log(String.format("M %d W %d Running writer %s\n", imachine, dest, this.toString())); - try { - socket = new Socket(); - socket.connect(workers[dest], sendTimeout); - if (socket.isConnected()) { - amsending[dest][msg.tag % (3*D)] = true; - DataOutputStream ostr = new DataOutputStream(socket.getOutputStream()); - ostr.writeInt(msg.size); - ostr.writeInt(msg.sender); - ostr.writeInt(msg.tag); - ostr.write(msg.buf, 0, msg.size*4); - } - } catch (Exception e) { - if (trace > 0) log(String.format("Machine %d round %d problem writing socket "+e+"\n", imachine, round)); - } finally { - try { if (socket != null) socket.close(); } catch (Exception e) {} - amsending[dest][msg.tag % (3*D)] = false; - synchronized (writers) { + try { + socket = new Socket(); + socket.connect(workers[dest], sendTimeout); + if (socket.isConnected()) { + amsending[dest][msg.tag % (3 * D)] = true; + DataOutputStream ostr = new DataOutputStream(socket.getOutputStream()); + ostr.writeInt(msg.size); + ostr.writeInt(msg.sender); + ostr.writeInt(msg.tag); + ostr.write(msg.buf, 0, msg.size * 4); + //TODO: add log here + System.out.printf("SEND: machine:%d round:%d dst:%d size:%d bytes\n", imachine, round, dest, msg.size*4); + + } + } catch (Exception e) { + if (trace > 0) + log(String.format("Machine %d round %d problem writing socket " + e + "\n", imachine, round)); + } finally { + try { + if (socket != null) socket.close(); + } catch (Exception e) { + } + amsending[dest][msg.tag % (3 * D)] = false; + synchronized (writers) { // log(String.format("M %d W %d Removing writer %s\n", imachine, dest, this.toString())); - if (writers.containsKey(this)) { - writers.remove(this); - } else { + if (writers.containsKey(this)) { + writers.remove(this); + } else { // log(String.format("M %d W %d Couldnt find writer %s\n", imachine, dest, this.toString())); - } - } - } - } - } - - public class SockReader implements Runnable { - Socket socket = null; - int round = 0; - - public SockReader(Socket sock, int round0) { - socket = sock; - round = round0; - } - - public void run() { - if (trace > 2) log(String.format("Machine %d round %d got a packet\n", imachine, round)); - try { - DataInputStream istr = new DataInputStream(socket.getInputStream()); - int len = istr.readInt(); - int src = istr.readInt(); - int tag = istr.readInt(); - if (trace > 2) log(String.format("Machine %d round %d got packet src %d tag %d\n", imachine, round, src, tag)); - if (tag/(D*3) < round) { - if (trace > 0) log("out of order packet received\n"); - istr.close(); - } else { - int waiting = 0; - while (waiting < reduceTimeout && tag/(D*3) > round) { - Thread.sleep(10); - waiting += 10; - } - - int tag0 = tag % (3*D); - if (!msgrecvd[src][tag0]) { - Msg msg = new Msg(len, src, imachine, tag); - istr.readFully(msg.buf, 0, len*4); - synchronized (Machine.this) { - if (!msgrecvd[src][tag0]) { - messages[src][tag0] = msg; - msgrecvd[src][tag0] = true; - } - } - if (trace > 4) log(String.format("m %d r %d from machine %d set tag %d %d\n", imachine, round, src, tag, tag0)); - } else { - if (trace > 0) log(String.format("SocketReader got a duplicate message to %d from %d with tag %d\n", imachine, src, tag)); - } - } - } catch (Exception e) { - if (trace > 0) log(String.format("Machine %d round %d Problem reading socket "+e.toString()+"\n", imachine, round)); - } finally { - try {socket.close();} catch (IOException e) {} - synchronized (readers) { - if (readers.containsKey(this)) readers.remove(this); - } - } - } - } - - public class Listener implements Runnable { - boolean stop = false; - ServerSocket ss = null; - - public Listener() { - int socknum = workers[imachine].getPort(); - try { - ss = new ServerSocket(socknum); - } catch (Exception e) { - throw new RuntimeException(String.format("Machine couldnt start socket listener on %d ", socknum) +e); - } - } - - public void run() { - while (!stop) { - try { - SockReader scs = new SockReader(ss.accept(), round); - Future fut = sockExecutor.submit(scs); - synchronized (readers) { - readers.put(scs, fut); - } - } catch (SocketException e) { - // This is probably due to the server shutting to. Don't do anything. - } - catch (Exception e) { - throw new RuntimeException("Socket listener had a problem "+e); - } - } - } - - public boolean stillSending() { - boolean sending = false; - for (int i = 0; i < amsending.length; i++) { - boolean [] sendrow = amsending[i]; - for (int j = 0; j < sendrow.length; j++) { - if (amsending[i][j]) sending = true; - } - } - return sending; - } - - public void stop(boolean force) { - if (!force) { - while (stillSending()) { - try { Thread.sleep(1); } catch (InterruptedException e) {} - } - } - try { - stop = true; - ss.close(); - } catch (Exception e) { - throw new RuntimeException("Trouble closing listener"); - } - } - } - - public void dumptags(String s) { - synchronized (network) { - System.out.print(s); - for (int i = 0; i < M; i++) { - for (int j = 0; j < M; j++) { - for (int k = 0; k < 3*D; k++) { - if (network.machines[i].messages[j][k] != null) { - System.out.print("1"); - } else { - System.out.print("0"); - } - } - } - } - System.out.print("\n"); - } - } - - public boolean sendrecv(int ith, ByteBuffer sbuf, int sendn, int outi, ByteBuffer rbuf, int recn, int ini, int tag0) { - if (trace > 4) log(String.format("m %d th %d r %d sendrecv enter out %d in %d tag %d\n", imachine, ith, round, outi, ini, tag0)); - if (trace > 2) log(String.format("Round %d sendrecv machine %d to %d from %d tag %d\n", round, imachine, outi, ini, tag0)); - sbuf.rewind(); - Msg msg = new Msg(sbuf.array(), sendn, imachine, outi, tag0); - int tag = tag0 % (3*D); - if (imachine == outi) { - rbuf.clear(); - rbuf.put(msg.buf, 0, 4*sendn); - rbuf.rewind(); - if (trace > 2) log(String.format("Round %d sendrecv machine %d to %d from %d tag %d done\n", round, imachine, outi, ini, tag0)); - if (trace > 4) log(String.format("m %d th %d r %d sendrecv exit out %d in %d tag %d\n", imachine, ith, round, outi, ini, tag0)); - return true; - } else { - if (trace > 4) dumptags(String.format("m %d th %d r %d enter %d %d %d ", imachine, ith, round, outi, ini, tag0)); - if (doSim) { - for (int i = 0; i < replicate; i++) { - if (trace > 0) { - if (network.machines[outi+i*M].messages[imachine][tag] != null) log(String.format("Round %d sendrecv machine %d to %d from %d tag %d msg exists\n", round, imachine, outi, ini, tag0)); - } - if (trace > 4) log(String.format("m %d th %d r %d to machine %d set tag %d %d\n", imachine, ith, round, outi, tag0, tag)); - synchronized (this) { - network.machines[outi+i*M].messages[imachine][tag] = msg; - } - } - } else { - for (int i = 0; i < replicate; i++) { - SockWriter w = new SockWriter(outi+i*M, msg); - Future fut = sockExecutor.submit(w); - synchronized (writers) { - writers.put(w, fut); + } + } + } + } + } + + public class SockReader implements Runnable { + Socket socket = null; + int round = 0; + + public SockReader(Socket sock, int round0) { + socket = sock; + round = round0; + } + + public void run() { + if (trace > 2) log(String.format("Machine %d round %d got a packet\n", imachine, round)); + try { + DataInputStream istr = new DataInputStream(socket.getInputStream()); + int len = istr.readInt(); + int src = istr.readInt(); + int tag = istr.readInt(); + if (trace > 2) + log(String.format("Machine %d round %d got packet src %d tag %d\n", imachine, round, src, tag)); + if (tag / (D * 3) < round) { + if (trace > 0) log("out of order packet received\n"); + istr.close(); + } else { + int waiting = 0; + while (waiting < reduceTimeout && tag / (D * 3) > round) { + Thread.sleep(10); + waiting += 10; + } + + int tag0 = tag % (3 * D); + if (!msgrecvd[src][tag0]) { + Msg msg = new Msg(len, src, imachine, tag); + istr.readFully(msg.buf, 0, len * 4); + //TODO: add log here + System.out.printf("RECV: machine:%d round:%d src:%d size:%d bytes\n", imachine, round, src, len*4); + + synchronized (Machine.this) { + if (!msgrecvd[src][tag0]) { + messages[src][tag0] = msg; + msgrecvd[src][tag0] = true; + } + } + if (trace > 4) + log(String.format("m %d r %d from machine %d set tag %d %d\n", imachine, round, src, tag, tag0)); + } else { + if (trace > 0) + log(String.format("SocketReader got a duplicate message to %d from %d with tag %d\n", imachine, src, tag)); + } + } + } catch (Exception e) { + if (trace > 0) + log(String.format("Machine %d round %d Problem reading socket " + e.toString() + "\n", imachine, round)); + } finally { + try { + socket.close(); + } catch (IOException e) { + } + synchronized (readers) { + if (readers.containsKey(this)) readers.remove(this); + } + } + } + } + + public class Listener implements Runnable { + boolean stop = false; + ServerSocket ss = null; + + public Listener() { + int socknum = workers[imachine].getPort(); + try { + ss = new ServerSocket(socknum); + } catch (Exception e) { + throw new RuntimeException(String.format("Machine couldnt start socket listener on %d ", socknum) + e); + } + } + + public void run() { + while (!stop) { + try { + SockReader scs = new SockReader(ss.accept(), round); + Future fut = sockExecutor.submit(scs); + synchronized (readers) { + readers.put(scs, fut); + } + } catch (SocketException e) { + // This is probably due to the server shutting to. Don't do anything. + } catch (Exception e) { + throw new RuntimeException("Socket listener had a problem " + e); + } + } + } + + public boolean stillSending() { + boolean sending = false; + for (int i = 0; i < amsending.length; i++) { + boolean[] sendrow = amsending[i]; + for (int j = 0; j < sendrow.length; j++) { + if (amsending[i][j]) sending = true; + } + } + return sending; + } + + public void stop(boolean force) { + if (!force) { + while (stillSending()) { + try { + Thread.sleep(1); + } catch (InterruptedException e) { + } + } + } + try { + stop = true; + ss.close(); + } catch (Exception e) { + throw new RuntimeException("Trouble closing listener"); + } + } + } + + public void dumptags(String s) { + synchronized (network) { + System.out.print(s); + for (int i = 0; i < M; i++) { + for (int j = 0; j < M; j++) { + for (int k = 0; k < 3 * D; k++) { + if (network.machines[i].messages[j][k] != null) { + System.out.print("1"); + } else { + System.out.print("0"); + } + } + } + } + System.out.print("\n"); + } + } + + public boolean sendrecv(int ith, ByteBuffer sbuf, int sendn, int outi, ByteBuffer rbuf, int recn, int ini, int tag0) { + if (trace > 4) + log(String.format("m %d th %d r %d sendrecv enter out %d in %d tag %d\n", imachine, ith, round, outi, ini, tag0)); + if (trace > 2) + log(String.format("Round %d sendrecv machine %d to %d from %d tag %d\n", round, imachine, outi, ini, tag0)); + sbuf.rewind(); + Msg msg = new Msg(sbuf.array(), sendn, imachine, outi, tag0); + int tag = tag0 % (3 * D); + if (imachine == outi) { + rbuf.clear(); + rbuf.put(msg.buf, 0, 4 * sendn); + rbuf.rewind(); + if (trace > 2) + log(String.format("Round %d sendrecv machine %d to %d from %d tag %d done\n", round, imachine, outi, ini, tag0)); + if (trace > 4) + log(String.format("m %d th %d r %d sendrecv exit out %d in %d tag %d\n", imachine, ith, round, outi, ini, tag0)); + return true; + } else { + if (trace > 4) + dumptags(String.format("m %d th %d r %d enter %d %d %d ", imachine, ith, round, outi, ini, tag0)); + if (doSim) { + for (int i = 0; i < replicate; i++) { + if (trace > 0) { + if (network.machines[outi + i * M].messages[imachine][tag] != null) + log(String.format("Round %d sendrecv machine %d to %d from %d tag %d msg exists\n", round, imachine, outi, ini, tag0)); + } + if (trace > 4) + log(String.format("m %d th %d r %d to machine %d set tag %d %d\n", imachine, ith, round, outi, tag0, tag)); + synchronized (this) { + network.machines[outi + i * M].messages[imachine][tag] = msg; + } + } + } else { + for (int i = 0; i < replicate; i++) { + SockWriter w = new SockWriter(outi + i * M, msg); + Future fut = sockExecutor.submit(w); + synchronized (writers) { + writers.put(w, fut); // log(String.format("M %d W %d Starting writer %s\n", imachine, outi, fut.toString())); - } - } - } - if (trace > 4) dumptags(String.format("m %d th %d r %d change %d %d %d ", imachine, ith, round, outi, ini, tag0)); - boolean gotit = false; - int waiting = 0; - while (!gotit && waiting < recvTimeout) { - for (int i = 0; i < replicate; i++) { - if (messages[ini+i*M][tag] != null) { - Msg rmsg = messages[ini+i*M][tag]; - rbuf.clear(); - rbuf.put(rmsg.buf, 0, 4*rmsg.size); - rbuf.rewind(); - gotit = true; - break; - } - try { - Thread.sleep(10); - waiting += 10; - } catch (InterruptedException e) {} - } - } - Boolean success = true; - if (trace > 4) dumptags(String.format("m %d th %d r %d later %d %d %d ", imachine, ith, round, outi, ini, tag0)); - if (waiting >= recvTimeout) { - log(String.format("m %d th %d r %d ", imachine, ith, round)); - log(String.format("Round %d sendrecv machine %d to %d from %d tag %d timed out\n", round, imachine, outi, ini, tag0)); - success = false; - } - for (int i = 0; i < replicate; i++) { - if (trace > 4) log(String.format("m %d th %d r %d from machine %d clear tag %d %d\n", imachine, ith, round, ini, tag0, tag)); - synchronized (this) { - messages[ini+i*M][tag] = null; - msgrecvd[ini+i*M][tag] = false; - } - } - if (trace > 2) log(String.format("Round %d sendrecv machine %d to %d from %d tag %d done after %d\n", round, imachine, outi, ini, tag0, waiting)); - if (trace > 4) dumptags(String.format("m %d th %d r %d exit %d %d %d ", imachine, ith, round, outi, ini, tag0)); - if (trace > 4) log(String.format("m %d th %d r %d sendrecv exit out %d in %d tag %d\n", imachine, ith, round, outi, ini, tag0)); - return success; - } - } - - public void log(String msg) { - File f=new File("\\log"); - try { - BufferedWriter bw = new BufferedWriter(new FileWriter(f)); - if (network != null) { - synchronized (network) { - bw.append(msg); - } - } else { - bw.append(msg); - } - }catch (Exception e){ - System.out.println("file not found"); - } - } + } + } + } + if (trace > 4) + dumptags(String.format("m %d th %d r %d change %d %d %d ", imachine, ith, round, outi, ini, tag0)); + boolean gotit = false; + int waiting = 0; + while (!gotit && waiting < recvTimeout) { + for (int i = 0; i < replicate; i++) { + if (messages[ini + i * M][tag] != null) { + Msg rmsg = messages[ini + i * M][tag]; + rbuf.clear(); + rbuf.put(rmsg.buf, 0, 4 * rmsg.size); + rbuf.rewind(); + gotit = true; + break; + } + try { + Thread.sleep(10); + waiting += 10; + } catch (InterruptedException e) { + } + } + } + Boolean success = true; + if (trace > 4) + dumptags(String.format("m %d th %d r %d later %d %d %d ", imachine, ith, round, outi, ini, tag0)); + if (waiting >= recvTimeout) { + log(String.format("m %d th %d r %d ", imachine, ith, round)); + log(String.format("Round %d sendrecv machine %d to %d from %d tag %d timed out\n", round, imachine, outi, ini, tag0)); + success = false; + } + for (int i = 0; i < replicate; i++) { + if (trace > 4) + log(String.format("m %d th %d r %d from machine %d clear tag %d %d\n", imachine, ith, round, ini, tag0, tag)); + synchronized (this) { + messages[ini + i * M][tag] = null; + msgrecvd[ini + i * M][tag] = false; + } + } + if (trace > 2) + log(String.format("Round %d sendrecv machine %d to %d from %d tag %d done after %d\n", round, imachine, outi, ini, tag0, waiting)); + if (trace > 4) + dumptags(String.format("m %d th %d r %d exit %d %d %d ", imachine, ith, round, outi, ini, tag0)); + if (trace > 4) + log(String.format("m %d th %d r %d sendrecv exit out %d in %d tag %d\n", imachine, ith, round, outi, ini, tag0)); + return success; + } + } + + public void log(String msg) { + if (network != null) { + synchronized (network) { + System.out.println(msg); + } + } else { + System.out.println(msg); + } + } } \ No newline at end of file From db9fb25a9dfb6ea0369d5d75cd7ec83842c9d897 Mon Sep 17 00:00:00 2001 From: Qualia Li Date: Sun, 26 Feb 2017 21:19:07 -0800 Subject: [PATCH 05/18] bandwidth --- .../java/edu/berkeley/bid/comm/Bandwidth.java | 35 +++++++++++++++++++ .../java/edu/berkeley/bid/comm/Machine.java | 20 ++++++++--- 2 files changed, 50 insertions(+), 5 deletions(-) create mode 100644 src/main/java/edu/berkeley/bid/comm/Bandwidth.java diff --git a/src/main/java/edu/berkeley/bid/comm/Bandwidth.java b/src/main/java/edu/berkeley/bid/comm/Bandwidth.java new file mode 100644 index 00000000..0bd44132 --- /dev/null +++ b/src/main/java/edu/berkeley/bid/comm/Bandwidth.java @@ -0,0 +1,35 @@ +package edu.berkeley.bid.comm; + +/** + * Created by qualiali on 26/02/2017. + */ +public class Bandwidth { + public int iMachine; //machine's identity + public int round; // + public int src; //src machine no + public int dst; //dst machine no + public int size; //size of socket message in bytes + public long startTime; //start time in milli seconds + public long endTime; //end time in milli seconds + + public Bandwidth(int iMachine, + int round, + int src, + int dst, + int size, + long startTime, + long endTime){ + this.iMachine = iMachine; + this.round = round; + this.src = src; + this.dst = dst; + this.size = size; + this.startTime = startTime; + this.endTime = endTime; + + //logging + System.out.printf("iMachine: %d, round: %d, src: %d, dst: %d, size: %d, startTime: %d, endTime: %d", + iMachine, round, src, dst, size, startTime, endTime); + } + +} diff --git a/src/main/java/edu/berkeley/bid/comm/Machine.java b/src/main/java/edu/berkeley/bid/comm/Machine.java index fe36eb40..4e63712a 100644 --- a/src/main/java/edu/berkeley/bid/comm/Machine.java +++ b/src/main/java/edu/berkeley/bid/comm/Machine.java @@ -6,6 +6,7 @@ import java.net.Socket; import java.net.SocketException; import java.nio.ByteBuffer; +import java.util.ArrayList; import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors; import java.util.concurrent.Future; @@ -49,6 +50,9 @@ public class Machine { public Hashtable> readers; Network network; + public ArrayList sentSockHistory = new ArrayList<>(); //Tracks the sock message history + public ArrayList recvSockHistory = new ArrayList<>(); //Tracks the sock message history + public Machine(Network p0, Groups groups0, int imachine0, int M0, boolean useLong0, int bufsize, boolean doSim0, int trace0, int replicate0, InetSocketAddress[] workers0) { network = p0; @@ -302,9 +306,13 @@ public void run() { ostr.writeInt(msg.size); ostr.writeInt(msg.sender); ostr.writeInt(msg.tag); + //TODO: check this part + long startTime = System.currentTimeMillis(); ostr.write(msg.buf, 0, msg.size * 4); - //TODO: add log here - System.out.printf("SEND: machine:%d round:%d dst:%d size:%d bytes\n", imachine, round, dest, msg.size*4); + //if there is exception when writing, the record will not be logged + long endTime = System.currentTimeMillis(); + sentSockHistory.add( + new Bandwidth(imachine, imachine, round, dest, msg.size*4, startTime, endTime)); } } catch (Exception e) { @@ -359,10 +367,12 @@ public void run() { int tag0 = tag % (3 * D); if (!msgrecvd[src][tag0]) { Msg msg = new Msg(len, src, imachine, tag); + //TODO: check this part + long startTime = System.currentTimeMillis(); istr.readFully(msg.buf, 0, len * 4); - //TODO: add log here - System.out.printf("RECV: machine:%d round:%d src:%d size:%d bytes\n", imachine, round, src, len*4); - + long endTime = System.currentTimeMillis(); + recvSockHistory.add( + new Bandwidth(imachine, round, src, imachine, len*4, startTime, endTime)); synchronized (Machine.this) { if (!msgrecvd[src][tag0]) { messages[src][tag0] = msg; From 38218d9ecdb0a17556ab3b163e99bbadfb86f5c7 Mon Sep 17 00:00:00 2001 From: Qualia Li Date: Sun, 26 Feb 2017 21:50:37 -0800 Subject: [PATCH 06/18] bandwidth --- .../java/edu/berkeley/bid/comm/Bandwidth.java | 16 ++++++++++++---- src/main/java/edu/berkeley/bid/comm/Machine.java | 8 ++++---- 2 files changed, 16 insertions(+), 8 deletions(-) diff --git a/src/main/java/edu/berkeley/bid/comm/Bandwidth.java b/src/main/java/edu/berkeley/bid/comm/Bandwidth.java index 0bd44132..10cb8290 100644 --- a/src/main/java/edu/berkeley/bid/comm/Bandwidth.java +++ b/src/main/java/edu/berkeley/bid/comm/Bandwidth.java @@ -9,8 +9,10 @@ public class Bandwidth { public int src; //src machine no public int dst; //dst machine no public int size; //size of socket message in bytes - public long startTime; //start time in milli seconds - public long endTime; //end time in milli seconds + public long startTime; //start time in nano seconds + public long endTime; //end time in nano seconds + public long duration; //time spent on sending the socket, in ns + public double bandwidth; //bandwidth, in KB/s public Bandwidth(int iMachine, int round, @@ -26,10 +28,16 @@ public Bandwidth(int iMachine, this.size = size; this.startTime = startTime; this.endTime = endTime; + this.duration = endTime-startTime; + this.bandwidth = size/1024.0/duration*1000000000; //logging - System.out.printf("iMachine: %d, round: %d, src: %d, dst: %d, size: %d, startTime: %d, endTime: %d", - iMachine, round, src, dst, size, startTime, endTime); +// System.out.printf("iMachine: %d, round: %d, src: %d, dst: %d, \n" + +// "size: %d B, startTime: %d ms, endTime: %d ms\n" + +// "duration: %d ms, bandwidth: %f KB/s", +// iMachine, round, src, dst, size, startTime, endTime, duration, bandwidth); + System.out.printf("src: %d, dst: %d, size: %d B, duration: %d ms, bandwidth: %f KB/s", + src, dst, size, duration, bandwidth); } } diff --git a/src/main/java/edu/berkeley/bid/comm/Machine.java b/src/main/java/edu/berkeley/bid/comm/Machine.java index 4e63712a..b7941012 100644 --- a/src/main/java/edu/berkeley/bid/comm/Machine.java +++ b/src/main/java/edu/berkeley/bid/comm/Machine.java @@ -307,10 +307,10 @@ public void run() { ostr.writeInt(msg.sender); ostr.writeInt(msg.tag); //TODO: check this part - long startTime = System.currentTimeMillis(); + long startTime = System.nanoTime(); ostr.write(msg.buf, 0, msg.size * 4); //if there is exception when writing, the record will not be logged - long endTime = System.currentTimeMillis(); + long endTime = System.nanoTime(); sentSockHistory.add( new Bandwidth(imachine, imachine, round, dest, msg.size*4, startTime, endTime)); @@ -368,9 +368,9 @@ public void run() { if (!msgrecvd[src][tag0]) { Msg msg = new Msg(len, src, imachine, tag); //TODO: check this part - long startTime = System.currentTimeMillis(); + long startTime = System.nanoTime(); istr.readFully(msg.buf, 0, len * 4); - long endTime = System.currentTimeMillis(); + long endTime = System.nanoTime(); recvSockHistory.add( new Bandwidth(imachine, round, src, imachine, len*4, startTime, endTime)); synchronized (Machine.this) { From 90137f3dec70075af965b130173c3a3573ed7067 Mon Sep 17 00:00:00 2001 From: Qualia Li Date: Tue, 28 Feb 2017 18:12:24 -0800 Subject: [PATCH 07/18] update --- src/main/java/edu/berkeley/bid/comm/Bandwidth.java | 4 ++-- src/main/java/edu/berkeley/bid/comm/Machine.java | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/main/java/edu/berkeley/bid/comm/Bandwidth.java b/src/main/java/edu/berkeley/bid/comm/Bandwidth.java index 10cb8290..d43c22e9 100644 --- a/src/main/java/edu/berkeley/bid/comm/Bandwidth.java +++ b/src/main/java/edu/berkeley/bid/comm/Bandwidth.java @@ -34,9 +34,9 @@ public Bandwidth(int iMachine, //logging // System.out.printf("iMachine: %d, round: %d, src: %d, dst: %d, \n" + // "size: %d B, startTime: %d ms, endTime: %d ms\n" + -// "duration: %d ms, bandwidth: %f KB/s", +// "duration: %d ms, bandwidth: %f KB/s\n", // iMachine, round, src, dst, size, startTime, endTime, duration, bandwidth); - System.out.printf("src: %d, dst: %d, size: %d B, duration: %d ms, bandwidth: %f KB/s", + System.out.printf("src: %d, dst: %d, size: %d B, duration: %d ms, bandwidth: %f KB/s\n", src, dst, size, duration, bandwidth); } diff --git a/src/main/java/edu/berkeley/bid/comm/Machine.java b/src/main/java/edu/berkeley/bid/comm/Machine.java index b7941012..f90561ac 100644 --- a/src/main/java/edu/berkeley/bid/comm/Machine.java +++ b/src/main/java/edu/berkeley/bid/comm/Machine.java @@ -298,6 +298,7 @@ public void run() { Socket socket = null; // log(String.format("M %d W %d Running writer %s\n", imachine, dest, this.toString())); try { + long startTime = System.nanoTime(); socket = new Socket(); socket.connect(workers[dest], sendTimeout); if (socket.isConnected()) { @@ -307,7 +308,6 @@ public void run() { ostr.writeInt(msg.sender); ostr.writeInt(msg.tag); //TODO: check this part - long startTime = System.nanoTime(); ostr.write(msg.buf, 0, msg.size * 4); //if there is exception when writing, the record will not be logged long endTime = System.nanoTime(); @@ -349,6 +349,7 @@ public void run() { if (trace > 2) log(String.format("Machine %d round %d got a packet\n", imachine, round)); try { DataInputStream istr = new DataInputStream(socket.getInputStream()); + long startTime = System.nanoTime(); int len = istr.readInt(); int src = istr.readInt(); int tag = istr.readInt(); @@ -368,7 +369,6 @@ public void run() { if (!msgrecvd[src][tag0]) { Msg msg = new Msg(len, src, imachine, tag); //TODO: check this part - long startTime = System.nanoTime(); istr.readFully(msg.buf, 0, len * 4); long endTime = System.nanoTime(); recvSockHistory.add( From 6c02035ceebfe563165e396150f3b9b0c4fbad23 Mon Sep 17 00:00:00 2001 From: Qualia Li Date: Tue, 28 Feb 2017 18:48:26 -0800 Subject: [PATCH 08/18] update --- .../java/edu/berkeley/bid/comm/Bandwidth.java | 5 ++++ .../java/edu/berkeley/bid/comm/Machine.java | 27 +++++++++++++++++++ 2 files changed, 32 insertions(+) diff --git a/src/main/java/edu/berkeley/bid/comm/Bandwidth.java b/src/main/java/edu/berkeley/bid/comm/Bandwidth.java index d43c22e9..a870a96f 100644 --- a/src/main/java/edu/berkeley/bid/comm/Bandwidth.java +++ b/src/main/java/edu/berkeley/bid/comm/Bandwidth.java @@ -1,5 +1,8 @@ package edu.berkeley.bid.comm; +import java.lang.reflect.Array; +import java.util.ArrayList; + /** * Created by qualiali on 26/02/2017. */ @@ -40,4 +43,6 @@ public Bandwidth(int iMachine, src, dst, size, duration, bandwidth); } + + } diff --git a/src/main/java/edu/berkeley/bid/comm/Machine.java b/src/main/java/edu/berkeley/bid/comm/Machine.java index f90561ac..b7de5709 100644 --- a/src/main/java/edu/berkeley/bid/comm/Machine.java +++ b/src/main/java/edu/berkeley/bid/comm/Machine.java @@ -575,4 +575,31 @@ public void log(String msg) { System.out.println(msg); } } + + void printThoughput(){ + int totalBytes = 0; + System.out.println("SENT:"); + for(Bandwidth b: sentSockHistory){ + totalBytes += b.size; + long millis = b.startTime / 1000000; + long second = (millis / 1000) % 60; + long minute = (millis / (1000 * 60)) % 60; + long hour = (millis / (1000 * 60 * 60)) % 24; + + String time = String.format("%02d:%02d:%02d:%d", hour, minute, second, millis); + System.out.println("time: "+time+" total bytes: "+totalBytes); + } + + System.out.println("RECV:"); + for(Bandwidth b: recvSockHistory){ + totalBytes += b.size; + long millis = b.startTime / 1000000; + long second = (millis / 1000) % 60; + long minute = (millis / (1000 * 60)) % 60; + long hour = (millis / (1000 * 60 * 60)) % 24; + + String time = String.format("%02d:%02d:%02d:%d", hour, minute, second, millis); + System.out.println("time: "+time+" total bytes: "+totalBytes); + } + } } \ No newline at end of file From 582bc4c038978443d28344f2da3c0515edf432dd Mon Sep 17 00:00:00 2001 From: Qualia Li Date: Tue, 28 Feb 2017 19:00:42 -0800 Subject: [PATCH 09/18] update --- src/main/java/edu/berkeley/bid/comm/Machine.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/edu/berkeley/bid/comm/Machine.java b/src/main/java/edu/berkeley/bid/comm/Machine.java index b7de5709..21c0e639 100644 --- a/src/main/java/edu/berkeley/bid/comm/Machine.java +++ b/src/main/java/edu/berkeley/bid/comm/Machine.java @@ -576,7 +576,7 @@ public void log(String msg) { } } - void printThoughput(){ + public void printThoughput(){ int totalBytes = 0; System.out.println("SENT:"); for(Bandwidth b: sentSockHistory){ From 3f8caa0d4aab8079a8d7d23ae143f27afbb7c3c4 Mon Sep 17 00:00:00 2001 From: Qualia Li Date: Wed, 1 Mar 2017 16:25:29 -0800 Subject: [PATCH 10/18] recovered from typo --- src/main/java/edu/berkeley/bid/comm/Machine.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/edu/berkeley/bid/comm/Machine.java b/src/main/java/edu/berkeley/bid/comm/Machine.java index 21c0e639..2efe37ba 100644 --- a/src/main/java/edu/berkeley/bid/comm/Machine.java +++ b/src/main/java/edu/berkeley/bid/comm/Machine.java @@ -576,7 +576,7 @@ public void log(String msg) { } } - public void printThoughput(){ + public void printThroughput(){ int totalBytes = 0; System.out.println("SENT:"); for(Bandwidth b: sentSockHistory){ From c16169948508855c657489a2eca0dbb9bcdab47a Mon Sep 17 00:00:00 2001 From: Qualia Li Date: Wed, 1 Mar 2017 17:31:42 -0800 Subject: [PATCH 11/18] udpate --- .../java/edu/berkeley/bid/comm/Bandwidth.java | 81 ++++++++++++------- .../java/edu/berkeley/bid/comm/Machine.java | 33 ++------ 2 files changed, 58 insertions(+), 56 deletions(-) diff --git a/src/main/java/edu/berkeley/bid/comm/Bandwidth.java b/src/main/java/edu/berkeley/bid/comm/Bandwidth.java index a870a96f..2cb9378c 100644 --- a/src/main/java/edu/berkeley/bid/comm/Bandwidth.java +++ b/src/main/java/edu/berkeley/bid/comm/Bandwidth.java @@ -7,42 +7,65 @@ * Created by qualiali on 26/02/2017. */ public class Bandwidth { - public int iMachine; //machine's identity - public int round; // - public int src; //src machine no - public int dst; //dst machine no - public int size; //size of socket message in bytes - public long startTime; //start time in nano seconds - public long endTime; //end time in nano seconds - public long duration; //time spent on sending the socket, in ns - public double bandwidth; //bandwidth, in KB/s - - public Bandwidth(int iMachine, + + public int totalSize = 0; + + public ArrayList records = new ArrayList<>(); + + class Record{ + public int iMachine; //machine's identity + public int round; // + public int src; //src machine no + public int dst; //dst machine no + public int size; //size of socket message in bytes + public long startTime; //start time in nano seconds + public long endTime; //end time in nano seconds + public long duration; //time spent on sending the socket, in ns + public double bandwidth; //bandwidth, in KB/s + + public Record(int iMachine, int round, int src, int dst, int size, long startTime, - long endTime){ - this.iMachine = iMachine; - this.round = round; - this.src = src; - this.dst = dst; - this.size = size; - this.startTime = startTime; - this.endTime = endTime; - this.duration = endTime-startTime; - this.bandwidth = size/1024.0/duration*1000000000; - - //logging -// System.out.printf("iMachine: %d, round: %d, src: %d, dst: %d, \n" + -// "size: %d B, startTime: %d ms, endTime: %d ms\n" + -// "duration: %d ms, bandwidth: %f KB/s\n", -// iMachine, round, src, dst, size, startTime, endTime, duration, bandwidth); - System.out.printf("src: %d, dst: %d, size: %d B, duration: %d ms, bandwidth: %f KB/s\n", - src, dst, size, duration, bandwidth); + long endTime) { + this.iMachine = iMachine; + this.round = round; + this.src = src; + this.dst = dst; + this.size = size; + this.startTime = startTime; + this.endTime = endTime; + this.duration = endTime - startTime; + this.bandwidth = size / 1024.0 / duration * 1000000000; + + System.out.printf("src: %d, dst: %d, size: %d B, duration: %d ms, bandwidth: %f KB/s\n", + src, dst, size, duration, bandwidth); + } } + public void addRecord(int iMachine, + int round, + int src, + int dst, + int size, + long startTime, + long endTime){ + records.add( + new Record(iMachine, round, src, dst, size, startTime, endTime)); + totalSize += size; + } + public void printRecords(){ + for(Record r: records){ + long millis = r.startTime / 1000000; + long second = (millis / 1000) % 60; + long minute = (millis / (1000 * 60)) % 60; + long hour = (millis / (1000 * 60 * 60)) % 24; + String time = String.format("%02d:%02d:%02d:%d", hour, minute, second, millis); + System.out.println("time: "+time+" total bytes: "+r.size); + } + } } diff --git a/src/main/java/edu/berkeley/bid/comm/Machine.java b/src/main/java/edu/berkeley/bid/comm/Machine.java index 2efe37ba..27d864ce 100644 --- a/src/main/java/edu/berkeley/bid/comm/Machine.java +++ b/src/main/java/edu/berkeley/bid/comm/Machine.java @@ -50,8 +50,8 @@ public class Machine { public Hashtable> readers; Network network; - public ArrayList sentSockHistory = new ArrayList<>(); //Tracks the sock message history - public ArrayList recvSockHistory = new ArrayList<>(); //Tracks the sock message history + public Bandwidth sentSockHistory = new Bandwidth(); //Tracks the sock message history + public Bandwidth recvSockHistory = new Bandwidth(); //Tracks the sock message history public Machine(Network p0, Groups groups0, int imachine0, int M0, boolean useLong0, int bufsize, boolean doSim0, int trace0, int replicate0, InetSocketAddress[] workers0) { @@ -311,9 +311,7 @@ public void run() { ostr.write(msg.buf, 0, msg.size * 4); //if there is exception when writing, the record will not be logged long endTime = System.nanoTime(); - sentSockHistory.add( - new Bandwidth(imachine, imachine, round, dest, msg.size*4, startTime, endTime)); - + sentSockHistory.addRecord(imachine, imachine, round, dest, msg.size*4, startTime, endTime); } } catch (Exception e) { if (trace > 0) @@ -371,8 +369,7 @@ public void run() { //TODO: check this part istr.readFully(msg.buf, 0, len * 4); long endTime = System.nanoTime(); - recvSockHistory.add( - new Bandwidth(imachine, round, src, imachine, len*4, startTime, endTime)); + recvSockHistory.addRecord(imachine, round, src, imachine, len*4, startTime, endTime); synchronized (Machine.this) { if (!msgrecvd[src][tag0]) { messages[src][tag0] = msg; @@ -579,27 +576,9 @@ public void log(String msg) { public void printThroughput(){ int totalBytes = 0; System.out.println("SENT:"); - for(Bandwidth b: sentSockHistory){ - totalBytes += b.size; - long millis = b.startTime / 1000000; - long second = (millis / 1000) % 60; - long minute = (millis / (1000 * 60)) % 60; - long hour = (millis / (1000 * 60 * 60)) % 24; - - String time = String.format("%02d:%02d:%02d:%d", hour, minute, second, millis); - System.out.println("time: "+time+" total bytes: "+totalBytes); - } + sentSockHistory.printRecords(); System.out.println("RECV:"); - for(Bandwidth b: recvSockHistory){ - totalBytes += b.size; - long millis = b.startTime / 1000000; - long second = (millis / 1000) % 60; - long minute = (millis / (1000 * 60)) % 60; - long hour = (millis / (1000 * 60 * 60)) % 24; - - String time = String.format("%02d:%02d:%02d:%d", hour, minute, second, millis); - System.out.println("time: "+time+" total bytes: "+totalBytes); - } + recvSockHistory.printRecords(); } } \ No newline at end of file From 7c32faac21906f84c7f8db80e44de47e6a5efdfb Mon Sep 17 00:00:00 2001 From: Qualia-Li Date: Sun, 19 Mar 2017 21:34:40 -0700 Subject: [PATCH 12/18] muted printing when adding record --- src/main/java/edu/berkeley/bid/comm/Bandwidth.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/edu/berkeley/bid/comm/Bandwidth.java b/src/main/java/edu/berkeley/bid/comm/Bandwidth.java index 2cb9378c..53c7193d 100644 --- a/src/main/java/edu/berkeley/bid/comm/Bandwidth.java +++ b/src/main/java/edu/berkeley/bid/comm/Bandwidth.java @@ -40,8 +40,8 @@ public Record(int iMachine, this.duration = endTime - startTime; this.bandwidth = size / 1024.0 / duration * 1000000000; - System.out.printf("src: %d, dst: %d, size: %d B, duration: %d ms, bandwidth: %f KB/s\n", - src, dst, size, duration, bandwidth); + // System.out.printf("src: %d, dst: %d, size: %d B, duration: %d ms, bandwidth: %f KB/s\n", + // src, dst, size, duration, bandwidth); } } From 7cdb37f5eafa8980207f0c7c9f58c1ea4666c8db Mon Sep 17 00:00:00 2001 From: Qualia-Li Date: Wed, 12 Apr 2017 18:30:19 -0700 Subject: [PATCH 13/18] bandwidth serializable --- src/main/java/edu/berkeley/bid/comm/Bandwidth.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/main/java/edu/berkeley/bid/comm/Bandwidth.java b/src/main/java/edu/berkeley/bid/comm/Bandwidth.java index 53c7193d..32cbe605 100644 --- a/src/main/java/edu/berkeley/bid/comm/Bandwidth.java +++ b/src/main/java/edu/berkeley/bid/comm/Bandwidth.java @@ -1,12 +1,13 @@ package edu.berkeley.bid.comm; +import java.io.Serializable; import java.lang.reflect.Array; import java.util.ArrayList; /** * Created by qualiali on 26/02/2017. */ -public class Bandwidth { +public class Bandwidth implements Serializable{ public int totalSize = 0; From d7f91893f6d992bdcecbf4f6becba48ef6e91b12 Mon Sep 17 00:00:00 2001 From: John Canny Date: Sat, 22 Apr 2017 01:43:47 +0000 Subject: [PATCH 14/18] updated bandwidth:printrecords --- src/main/java/edu/berkeley/bid/comm/Bandwidth.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/main/java/edu/berkeley/bid/comm/Bandwidth.java b/src/main/java/edu/berkeley/bid/comm/Bandwidth.java index 32cbe605..73a0d94e 100644 --- a/src/main/java/edu/berkeley/bid/comm/Bandwidth.java +++ b/src/main/java/edu/berkeley/bid/comm/Bandwidth.java @@ -59,7 +59,8 @@ public void addRecord(int iMachine, } public void printRecords(){ - for(Record r: records){ + System.out.println("Worker Progress:"); + for(Record r: records){ long millis = r.startTime / 1000000; long second = (millis / 1000) % 60; long minute = (millis / (1000 * 60)) % 60; From 83ff4ebc2478c1ac5bda3d27a7eee9570e69591c Mon Sep 17 00:00:00 2001 From: Qualia-Li Date: Fri, 21 Apr 2017 20:07:05 -0700 Subject: [PATCH 15/18] refactored Bandwidth to WorkerProgress --- src/main/java/edu/berkeley/bid/comm/Machine.java | 13 ++----------- .../comm/{Bandwidth.java => WorkerProgress.java} | 2 +- 2 files changed, 3 insertions(+), 12 deletions(-) rename src/main/java/edu/berkeley/bid/comm/{Bandwidth.java => WorkerProgress.java} (97%) diff --git a/src/main/java/edu/berkeley/bid/comm/Machine.java b/src/main/java/edu/berkeley/bid/comm/Machine.java index 27d864ce..4b4998b1 100644 --- a/src/main/java/edu/berkeley/bid/comm/Machine.java +++ b/src/main/java/edu/berkeley/bid/comm/Machine.java @@ -50,8 +50,8 @@ public class Machine { public Hashtable> readers; Network network; - public Bandwidth sentSockHistory = new Bandwidth(); //Tracks the sock message history - public Bandwidth recvSockHistory = new Bandwidth(); //Tracks the sock message history + public WorkerProgress sentSockHistory = new WorkerProgress(); //Tracks the sock message history + public WorkerProgress recvSockHistory = new WorkerProgress(); //Tracks the sock message history public Machine(Network p0, Groups groups0, int imachine0, int M0, boolean useLong0, int bufsize, boolean doSim0, int trace0, int replicate0, InetSocketAddress[] workers0) { @@ -572,13 +572,4 @@ public void log(String msg) { System.out.println(msg); } } - - public void printThroughput(){ - int totalBytes = 0; - System.out.println("SENT:"); - sentSockHistory.printRecords(); - - System.out.println("RECV:"); - recvSockHistory.printRecords(); - } } \ No newline at end of file diff --git a/src/main/java/edu/berkeley/bid/comm/Bandwidth.java b/src/main/java/edu/berkeley/bid/comm/WorkerProgress.java similarity index 97% rename from src/main/java/edu/berkeley/bid/comm/Bandwidth.java rename to src/main/java/edu/berkeley/bid/comm/WorkerProgress.java index 32cbe605..2078c111 100644 --- a/src/main/java/edu/berkeley/bid/comm/Bandwidth.java +++ b/src/main/java/edu/berkeley/bid/comm/WorkerProgress.java @@ -7,7 +7,7 @@ /** * Created by qualiali on 26/02/2017. */ -public class Bandwidth implements Serializable{ +public class WorkerProgress implements Serializable{ public int totalSize = 0; From 49d5faa32df3aee3fff4d31e57a5b556215ef979 Mon Sep 17 00:00:00 2001 From: Qualia-Li Date: Sun, 23 Apr 2017 20:58:29 -0700 Subject: [PATCH 16/18] refactored WorkerProgress --- .../java/edu/berkeley/bid/comm/Machine.java | 7 +- .../edu/berkeley/bid/comm/WorkerProgress.java | 102 +++++++++--------- 2 files changed, 53 insertions(+), 56 deletions(-) diff --git a/src/main/java/edu/berkeley/bid/comm/Machine.java b/src/main/java/edu/berkeley/bid/comm/Machine.java index 4b4998b1..05e0716e 100644 --- a/src/main/java/edu/berkeley/bid/comm/Machine.java +++ b/src/main/java/edu/berkeley/bid/comm/Machine.java @@ -50,8 +50,7 @@ public class Machine { public Hashtable> readers; Network network; - public WorkerProgress sentSockHistory = new WorkerProgress(); //Tracks the sock message history - public WorkerProgress recvSockHistory = new WorkerProgress(); //Tracks the sock message history + public WorkerProgress workerProgress = new WorkerProgress(); //Tracks the sock message history public Machine(Network p0, Groups groups0, int imachine0, int M0, boolean useLong0, int bufsize, boolean doSim0, int trace0, int replicate0, InetSocketAddress[] workers0) { @@ -311,7 +310,7 @@ public void run() { ostr.write(msg.buf, 0, msg.size * 4); //if there is exception when writing, the record will not be logged long endTime = System.nanoTime(); - sentSockHistory.addRecord(imachine, imachine, round, dest, msg.size*4, startTime, endTime); + workerProgress.addSend(msg.size*4); } } catch (Exception e) { if (trace > 0) @@ -369,7 +368,7 @@ public void run() { //TODO: check this part istr.readFully(msg.buf, 0, len * 4); long endTime = System.nanoTime(); - recvSockHistory.addRecord(imachine, round, src, imachine, len*4, startTime, endTime); + workerProgress.addRecv(len*4); synchronized (Machine.this) { if (!msgrecvd[src][tag0]) { messages[src][tag0] = msg; diff --git a/src/main/java/edu/berkeley/bid/comm/WorkerProgress.java b/src/main/java/edu/berkeley/bid/comm/WorkerProgress.java index 366f0c27..5babd77d 100644 --- a/src/main/java/edu/berkeley/bid/comm/WorkerProgress.java +++ b/src/main/java/edu/berkeley/bid/comm/WorkerProgress.java @@ -7,67 +7,65 @@ /** * Created by qualiali on 26/02/2017. */ -public class WorkerProgress implements Serializable{ +public class WorkerProgress implements Serializable { - public int totalSize = 0; + int sentSize = 0; + int recvSize = 0; + int lastSentSize = 0; + int lastRecvSize = 0; - public ArrayList records = new ArrayList<>(); - class Record{ - public int iMachine; //machine's identity - public int round; // - public int src; //src machine no - public int dst; //dst machine no - public int size; //size of socket message in bytes - public long startTime; //start time in nano seconds - public long endTime; //end time in nano seconds - public long duration; //time spent on sending the socket, in ns - public double bandwidth; //bandwidth, in KB/s + ArrayList timestamps = new ArrayList<>(); + ArrayList sentBandwidthHistory = new ArrayList<>(); + ArrayList recvBandwidthHistory = new ArrayList<>(); - public Record(int iMachine, - int round, - int src, - int dst, - int size, - long startTime, - long endTime) { - this.iMachine = iMachine; - this.round = round; - this.src = src; - this.dst = dst; - this.size = size; - this.startTime = startTime; - this.endTime = endTime; - this.duration = endTime - startTime; - this.bandwidth = size / 1024.0 / duration * 1000000000; + public void addSentBandwidth(double bandwidth){ + sentBandwidthHistory.add(bandwidth); + } + + public void addRecvBandwidth(double bandwidth){ + recvBandwidthHistory.add(bandwidth); + } - // System.out.printf("src: %d, dst: %d, size: %d B, duration: %d ms, bandwidth: %f KB/s\n", - // src, dst, size, duration, bandwidth); - } + public void addSend(int size) { + sentSize += size; } - public void addRecord(int iMachine, - int round, - int src, - int dst, - int size, - long startTime, - long endTime){ - records.add( - new Record(iMachine, round, src, dst, size, startTime, endTime)); - totalSize += size; + public void addRecv(int size){ + recvSize += size; } - public void printRecords(){ - System.out.println("Worker Progress:"); - for(Record r: records){ - long millis = r.startTime / 1000000; - long second = (millis / 1000) % 60; - long minute = (millis / (1000 * 60)) % 60; - long hour = (millis / (1000 * 60 * 60)) % 24; + public void addTimestamp (long timestamp){ + long lastTimestamp = timestamps.get(timestamps.size()-1); + timestamps.add(timestamp); + long interval = lastTimestamp - timestamp; + int sentSizeIncrement = sentSize - lastSentSize; + int recvSizeIncrement = recvSize - lastRecvSize; + lastSentSize = sentSize; + lastRecvSize = recvSize; + double sentBandwidth = sentSizeIncrement/1024.0/1024/(interval/1000.0); + double recvBandwidth = recvSizeIncrement/1024.0/1024/(interval/1000.0); + sentBandwidthHistory.add(sentBandwidth); + recvBandwidthHistory.add(recvBandwidth); + } + + public String toString() { + String output = ""; + output += "Worker Progress:"; + + long lastTimestamp = timestamps.get(timestamps.size()-1); + long millis = lastTimestamp / 1000000; + long second = (lastTimestamp / 1000) % 60; + long minute = (lastTimestamp / (1000 * 60)) % 60; + long hour = (lastTimestamp / (1000 * 60 * 60)) % 24; + String time = String.format("%02d:%02d:%02d:%d", hour, minute, second, millis); + double sentBandwidth = sentBandwidthHistory.get(sentBandwidthHistory.size()-1); + double recvBandwidth = recvBandwidthHistory.get(recvBandwidthHistory.size()-1); + output += String.format("Time: %s, Sent: %.2f MB/s, Recv: %.2f Mb/s", time, sentBandwidth, recvBandwidth); + return output; + } - String time = String.format("%02d:%02d:%02d:%d", hour, minute, second, millis); - System.out.println("time: "+time+" total bytes: "+r.size); - } + public void printProgress(){ + System.out.println(this.toString()); } } From c6f295911231f9c404395490053e748db3080dcc Mon Sep 17 00:00:00 2001 From: John Canny Date: Mon, 24 Apr 2017 04:01:27 +0000 Subject: [PATCH 17/18] updated --- src/main/java/edu/berkeley/bid/comm/WorkerProgress.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/edu/berkeley/bid/comm/WorkerProgress.java b/src/main/java/edu/berkeley/bid/comm/WorkerProgress.java index 366f0c27..31c9a48c 100644 --- a/src/main/java/edu/berkeley/bid/comm/WorkerProgress.java +++ b/src/main/java/edu/berkeley/bid/comm/WorkerProgress.java @@ -13,7 +13,7 @@ public class WorkerProgress implements Serializable{ public ArrayList records = new ArrayList<>(); - class Record{ + class Record implements Serializable{ public int iMachine; //machine's identity public int round; // public int src; //src machine no From dc7f781de349ecde87c34a084b01bf2b18612d13 Mon Sep 17 00:00:00 2001 From: John Canny Date: Mon, 24 Apr 2017 04:50:00 +0000 Subject: [PATCH 18/18] printing worker progress on master --- src/main/java/edu/berkeley/bid/comm/WorkerProgress.java | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/main/java/edu/berkeley/bid/comm/WorkerProgress.java b/src/main/java/edu/berkeley/bid/comm/WorkerProgress.java index df11cecd..42963a98 100644 --- a/src/main/java/edu/berkeley/bid/comm/WorkerProgress.java +++ b/src/main/java/edu/berkeley/bid/comm/WorkerProgress.java @@ -18,6 +18,12 @@ public class WorkerProgress implements Serializable { ArrayList sentBandwidthHistory = new ArrayList<>(); ArrayList recvBandwidthHistory = new ArrayList<>(); + public WorkerProgress(){ + timestamps.add(System.currentTimeMillis()); + sentBandwidthHistory.add(0.0); + recvBandwidthHistory.add(0.0); + } + public void addSentBandwidth(double bandwidth){ sentBandwidthHistory.add(bandwidth); } @@ -37,7 +43,7 @@ public void addRecv(int size){ public void addTimestamp (long timestamp){ long lastTimestamp = timestamps.get(timestamps.size()-1); timestamps.add(timestamp); - long interval = lastTimestamp - timestamp; + long interval = timestamp - lastTimestamp; int sentSizeIncrement = sentSize - lastSentSize; int recvSizeIncrement = recvSize - lastRecvSize; lastSentSize = sentSize;