浏览代码

improved offline gc sending by sending multiple gtt per one write()

Boyoung- 8 年之前
父节点
当前提交
064cc62255

+ 2 - 0
ObliVMGC/com/oblivm/backend/gc/GCCompEnv.java

@@ -6,6 +6,8 @@ import com.oblivm.backend.flexsc.Party;
 import com.oblivm.backend.network.Network;
 
 public abstract class GCCompEnv extends CompEnv<GCSignal> {
+	protected int threshold = 100;
+
 	public GCCompEnv(Network channel, Party p, Mode mode) {
 		super(channel, p, mode);
 	}

+ 40 - 23
ObliVMGC/com/oblivm/backend/gc/regular/GCEva.java

@@ -1,6 +1,8 @@
 package com.oblivm.backend.gc.regular;
 
+import java.util.ArrayList;
 import java.util.Arrays;
+import java.util.List;
 
 import com.oblivm.backend.flexsc.Flag;
 import com.oblivm.backend.flexsc.Mode;
@@ -21,6 +23,7 @@ public class GCEva extends GCEvaComp {
 	Timer timer = null;
 	int p;
 	int m;
+	List<byte[]> msg = new ArrayList<byte[]>(threshold);
 
 	public GCEva(Network channel) {
 		super(channel, Mode.REAL);
@@ -49,6 +52,26 @@ public class GCEva extends GCEvaComp {
 		curr = this;
 	}
 
+	public void receiveLastSetGTT() {
+		int remainder = (int) (numOfAnds % threshold);
+		if (remainder > 0) {
+			msg = channel.sender.readObject();
+			for (int i = 0; i < remainder; i++) {
+				if (curr == null) {
+					curr = this;
+				} else {
+					curr.next = new GCEva(channel, timer, p, m);
+					curr = curr.next;
+				}
+				byte[] rows = msg.get(i);
+				curr.gtt[0][1].bytes = Arrays.copyOfRange(rows, 0, GCSignal.len);
+				curr.gtt[1][0].bytes = Arrays.copyOfRange(rows, GCSignal.len, GCSignal.len * 2);
+				curr.gtt[1][1].bytes = Arrays.copyOfRange(rows, GCSignal.len * 2, rows.length);
+			}
+			msg.clear();
+		}
+	}
+
 	private void receiveGTT() {
 		if (timer == null) {
 			try {
@@ -64,21 +87,22 @@ public class GCEva extends GCEvaComp {
 				System.exit(1);
 			}
 		} else {
-			timer.start(p, m);
-			byte[] rows = channel.sender.read();
-			timer.stop(p, m);
-
-			gtt[0][1].bytes = Arrays.copyOfRange(rows, 0, GCSignal.len);
-			gtt[1][0].bytes = Arrays.copyOfRange(rows, GCSignal.len, GCSignal.len * 2);
-			gtt[1][1].bytes = Arrays.copyOfRange(rows, GCSignal.len * 2, rows.length);
-
-			/*
-			 * timer.start(p, m); GCSignal[] rows = channel.sender.readObject();
-			 * timer.stop(p, m);
-			 * 
-			 * gtt[0][1].bytes = rows[0].bytes; gtt[1][0].bytes = rows[1].bytes;
-			 * gtt[1][1].bytes = rows[2].bytes;
-			 */
+			if (numOfAnds % threshold == 0) {
+				msg = channel.sender.readObject();
+				for (int i = 0; i < threshold; i++) {
+					if (curr == null) {
+						curr = this;
+					} else {
+						curr.next = new GCEva(channel, timer, p, m);
+						curr = curr.next;
+					}
+					byte[] rows = msg.get(i);
+					curr.gtt[0][1].bytes = Arrays.copyOfRange(rows, 0, GCSignal.len);
+					curr.gtt[1][0].bytes = Arrays.copyOfRange(rows, GCSignal.len, GCSignal.len * 2);
+					curr.gtt[1][1].bytes = Arrays.copyOfRange(rows, GCSignal.len * 2, rows.length);
+				}
+				msg.clear();
+			}
 		}
 	}
 
@@ -96,14 +120,7 @@ public class GCEva extends GCEvaComp {
 			res = new GCSignal(new byte[10]);
 			if (!evaluate) {
 				++numOfAnds;
-
-				if (curr == null) {
-					curr = this;
-				} else {
-					curr.next = new GCEva(channel, timer, p, m);
-					curr = curr.next;
-				}
-				curr.receiveGTT();
+				receiveGTT();
 			} else {
 				int i0 = a.getLSB();
 				int i1 = b.getLSB();

+ 20 - 11
ObliVMGC/com/oblivm/backend/gc/regular/GCGen.java

@@ -1,5 +1,8 @@
 package com.oblivm.backend.gc.regular;
 
+import java.util.ArrayList;
+import java.util.List;
+
 import com.oblivm.backend.flexsc.Flag;
 import com.oblivm.backend.flexsc.Mode;
 import com.oblivm.backend.gc.GCGenComp;
@@ -14,6 +17,7 @@ public class GCGen extends GCGenComp {
 	Timer timer = null;
 	int p;
 	int m;
+	List<byte[]> msg = new ArrayList<byte[]>(threshold);
 
 	public GCGen(Network channel) {
 		super(channel, Mode.REAL);
@@ -78,6 +82,15 @@ public class GCGen extends GCGenComp {
 		return GCSignal.newInstance(lb[0].bytes);
 	}
 
+	public void sendLastSetGTT() {
+		if (msg.size() > 0) {
+			timer.start(p, m);
+			channel.receiver.write(msg);
+			timer.stop(p, m);
+			msg.clear();
+		}
+	}
+
 	private void sendGTT() {
 		if (timer == null) {
 			try {
@@ -96,17 +109,13 @@ public class GCGen extends GCGenComp {
 			System.arraycopy(toSend[1][0].bytes, 0, rows, GCSignal.len, GCSignal.len);
 			System.arraycopy(toSend[1][1].bytes, 0, rows, GCSignal.len * 2, GCSignal.len);
 
-			timer.start(p, m);
-			channel.receiver.write(rows);
-			timer.stop(p, m);
-
-			/*
-			 * GCSignal[] rows = new GCSignal[3]; rows[0] = toSend[0][1];
-			 * rows[1] = toSend[1][0]; rows[2] = toSend[1][1];
-			 * 
-			 * timer.start(p, m); channel.receiver.write(rows); timer.stop(p,
-			 * m);
-			 */
+			msg.add(rows);
+			if (msg.size() == threshold) {
+				timer.start(p, m);
+				channel.receiver.write(msg);
+				timer.stop(p, m);
+				msg.clear();
+			}
 		}
 	}
 

+ 1 - 1
src/protocols/UpdateRoot.java

@@ -126,7 +126,7 @@ public class UpdateRoot extends Protocol {
 	public void run(Party party, Metadata md, Forest forest) {
 		Timer timer = new Timer();
 
-		for (int i = 0; i < 20; i++) {
+		for (int i = 0; i < 100; i++) {
 
 			System.out.println("i=" + i);
 

+ 2 - 0
src/protocols/precomputation/PreEviction.java

@@ -74,6 +74,7 @@ public class PreEviction extends Protocol {
 		CompEnv<GCSignal> gen = new GCGen(channel, timer, pid, M.offline_write);
 		GCSignal[][][] outZeroKeys = new GCRoute<GCSignal>(gen, d, w).routing(LiZeroKeys, E_feZeroKeys, C_feZeroKeys,
 				E_labelZeroKeys, C_labelZeroKeys, deltaZeroKeys);
+		((GCGen) gen).sendLastSetGTT();
 
 		predata.evict_tiOutKeyHashes = new byte[d][][];
 		predata.evict_targetOutKeyPairs = new GCSignal[d][][];
@@ -159,6 +160,7 @@ public class PreEviction extends Protocol {
 		predata.evict_gcroute = new GCRoute<GCSignal>(eva, d, w);
 		predata.evict_gcroute.routing(LiZeroKeys, E_feZeroKeys, C_feZeroKeys, E_labelZeroKeys, C_labelZeroKeys,
 				deltaZeroKeys);
+		((GCEva) eva).receiveLastSetGTT();
 		eva.setEvaluate();
 
 		timer.start(pid, M.offline_read);

+ 2 - 0
src/protocols/precomputation/PreUpdateRoot.java

@@ -56,6 +56,7 @@ public class PreUpdateRoot extends Protocol {
 		CompEnv<GCSignal> gen = new GCGen(channel, timer, pid, M.offline_write);
 		GCSignal[][] outZeroKeys = new GCUpdateRoot<GCSignal>(gen, lBits + 1, sw).rootFindDeepestAndEmpty(j1ZeroKeys,
 				LiZeroKeys, E_feZeroKeys, C_feZeroKeys, E_labelZeroKeys, C_labelZeroKeys);
+		((GCGen) gen).sendLastSetGTT();
 
 		predata.ur_outKeyHashes = new byte[outZeroKeys.length][][];
 		for (int i = 0; i < outZeroKeys.length; i++)
@@ -96,6 +97,7 @@ public class PreUpdateRoot extends Protocol {
 		predata.ur_gcur = new GCUpdateRoot<GCSignal>(eva, lBits + 1, sw);
 		predata.ur_gcur.rootFindDeepestAndEmpty(j1ZeroKeys, LiZeroKeys, E_feZeroKeys, C_feZeroKeys, E_labelZeroKeys,
 				C_labelZeroKeys);
+		((GCEva) eva).receiveLastSetGTT();
 		eva.setEvaluate();
 
 		timer.start(pid, M.offline_read);