From 202650b1dde8bd4ca0f4e2d70c977c4fcaf497be Mon Sep 17 00:00:00 2001 From: "Casper V. Kristensen" Date: Tue, 3 Dec 2019 14:54:11 +0100 Subject: [PATCH] Remove network simulation -- can just do it in Python. 50x benchmark speedup. --- pir/src/main/java/dk/au/pir/Driver.java | 31 +++++++------------ .../java/dk/au/pir/profilers/Profiler.java | 23 +------------- .../evenSimpler/EvenSimplerClient.java | 2 -- .../protocols/interpoly/InterPolyClient.java | 2 -- .../au/pir/protocols/simple/SimpleClient.java | 2 -- 5 files changed, 13 insertions(+), 47 deletions(-) diff --git a/pir/src/main/java/dk/au/pir/Driver.java b/pir/src/main/java/dk/au/pir/Driver.java index 53f4369..3753e3a 100644 --- a/pir/src/main/java/dk/au/pir/Driver.java +++ b/pir/src/main/java/dk/au/pir/Driver.java @@ -72,64 +72,57 @@ public class Driver { for (int numServers = 1; numServers <= 16; numServers = numServers*2) { for (int databaseSize = 2048; databaseSize <= 32_768; databaseSize = databaseSize*2) { for (int blockSize = 64; blockSize <= 16_384; blockSize = blockSize*2) { - for (int latency = 0; latency <= 500; latency = latency + 50) { - for (int bandwidth = 64; bandwidth <= 16_384; bandwidth = bandwidth*2) { // in kbit/s - for (int i = 0; i < 5; i++) { - runTest(numServers, databaseSize, blockSize, latency, bandwidth); - } - } + for (int i = 0; i < 5; i++) { + runTest(numServers, databaseSize, blockSize); } } } } } - private static void runTest(int numServers, int databaseSize, int blockSize, int latency, int bandwidth) { + private static void runTest(int numServers, int databaseSize, int blockSize) { PIRSettings settings = new PIRSettings(databaseSize*blockSize, numServers, blockSize); - int[] x = new int[databaseSize]; + int[] x = new int[databaseSize*blockSize]; for (int i = 0; i < x.length; i++) { x[i] = (int) (Math.random()*2); // 0 or 1 } Database database = new MemoryDatabase(settings, x); - Profiler profiler = new Profiler(latency, bandwidth/10, bandwidth); + Profiler profiler = new Profiler(); profiler.reset(); testEvenSimplerScheme(settings, database, profiler); - reportResult(numServers, databaseSize, blockSize, latency, bandwidth, profiler, "EvenSimplerScheme"); + reportResult(numServers, databaseSize, blockSize, profiler, "EvenSimplerScheme"); if (numServers == 2) { profiler.reset(); testSimpleScheme(settings, database, profiler); - reportResult(numServers, databaseSize, blockSize, latency, bandwidth, profiler, "SimpleScheme"); + reportResult(numServers, databaseSize, blockSize, profiler, "SimpleScheme"); profiler.reset(); testSimpleBlockScheme(settings, database, profiler); - reportResult(numServers, databaseSize, blockSize, latency, bandwidth, profiler, "SimpleBlockScheme"); + reportResult(numServers, databaseSize, blockSize, profiler, "SimpleBlockScheme"); } if (settings.getS() != 0 && numServers != 1) { profiler.reset(); testGeneralInterPolyScheme(settings, database, profiler); - reportResult(numServers, databaseSize, blockSize, latency, bandwidth, profiler, "GeneralInterPolyScheme"); + reportResult(numServers, databaseSize, blockSize, profiler, "GeneralInterPolyScheme"); profiler.reset(); testGeneralInterPolyBlockScheme(settings, database, profiler); - reportResult(numServers, databaseSize, blockSize, latency, bandwidth, profiler, "GeneralInterPolyBlockScheme"); + reportResult(numServers, databaseSize, blockSize, profiler, "GeneralInterPolyBlockScheme"); } } - private static void reportResult(int numServers, int databaseSize, int blockSize, int latency, int bandwidth, Profiler profiler, String protocolName) { + private static void reportResult(int numServers, int databaseSize, int blockSize, Profiler profiler, String protocolName) { System.out.println( numServers + " " + databaseSize + " " + blockSize + " " + - latency + " " + - bandwidth + " " + protocolName + " " + profiler.getTotalCPUTime() + " " + profiler.getSent() + " " + - profiler.getReceived() + " " + - profiler.getTotalNetworkTime() + profiler.getReceived() ); } diff --git a/pir/src/main/java/dk/au/pir/profilers/Profiler.java b/pir/src/main/java/dk/au/pir/profilers/Profiler.java index c74b630..cedd575 100644 --- a/pir/src/main/java/dk/au/pir/profilers/Profiler.java +++ b/pir/src/main/java/dk/au/pir/profilers/Profiler.java @@ -4,20 +4,12 @@ import dk.au.pir.utils.FieldElement; import dk.au.pir.utils.MathUtils; public class Profiler { - private final int latency; - private final int sendBandwidth; - private final int receiveBandwidth; - private int sent; private int received; - private int networkTime; private long startTime; private long stopTime; - public Profiler(int latency, int sendBandwidth, int receiveBandwidth) { - this.latency = latency; - this.sendBandwidth = sendBandwidth; - this.receiveBandwidth = receiveBandwidth; + public Profiler() { reset(); } @@ -33,19 +25,10 @@ public class Profiler { public void reset() { this.sent = 0; this.received = 0; - this.networkTime = 0; this.startTime = 0; this.stopTime = 0; } - public void addNetworkDelay() { - this.addNetworkDelay(1); - } - - public void addNetworkDelay(int n) { - this.networkTime += latency * n; - } - public int clientSend(int number) { this.sent += log2(number); return number; @@ -115,10 +98,6 @@ public class Profiler { return this.stopTime - this.startTime; } - public int getTotalNetworkTime() { - return networkTime + (this.sent/this.sendBandwidth) + (this.received/this.receiveBandwidth); - } - public int log2(int n) { if (n == 0) { return 1; // technically incorrect but for the sake of profiling, a 0-bit requires 1 bit of space diff --git a/pir/src/main/java/dk/au/pir/protocols/evenSimpler/EvenSimplerClient.java b/pir/src/main/java/dk/au/pir/protocols/evenSimpler/EvenSimplerClient.java index e66a981..2dc3cfa 100644 --- a/pir/src/main/java/dk/au/pir/protocols/evenSimpler/EvenSimplerClient.java +++ b/pir/src/main/java/dk/au/pir/protocols/evenSimpler/EvenSimplerClient.java @@ -15,14 +15,12 @@ public class EvenSimplerClient { } public int receiveBit(int index) { - this.profiler.addNetworkDelay(2); int[] data = this.profiler.clientReceive(this.servers[0].giveDatabase()); return data[index]; } public int[] receiveBits(int record) { int[] res = new int[settings.getBlocksize()]; - this.profiler.addNetworkDelay(); int[] data = this.profiler.clientReceive(this.servers[0].giveDatabase()); System.arraycopy(data, (record * settings.getBlocksize()), res, 0, settings.getBlocksize()); return res; diff --git a/pir/src/main/java/dk/au/pir/protocols/interpoly/InterPolyClient.java b/pir/src/main/java/dk/au/pir/protocols/interpoly/InterPolyClient.java index a0f9cf2..1ab9eb3 100644 --- a/pir/src/main/java/dk/au/pir/protocols/interpoly/InterPolyClient.java +++ b/pir/src/main/java/dk/au/pir/protocols/interpoly/InterPolyClient.java @@ -60,7 +60,6 @@ public class InterPolyClient { private int receiveBit(int index) { FieldElement[] randoms = this.getRandomFieldElements(); FieldElement[] Fs = new FieldElement[this.servers.length]; - this.profiler.addNetworkDelay(2); for (int z = 0; z < this.servers.length; z++) { Fs[z] = this.profiler.clientReceive(this.servers[z].F(this.profiler.clientSend(this.getGs(index, z+1, randoms)))); } @@ -84,7 +83,6 @@ public class InterPolyClient { /** * 1) Compute all the Gs for each server, s.t. the first index should be the blocksize and it should contain all the Gs for the given index */ - this.profiler.addNetworkDelay(2); for (int z = 0; z < this.servers.length; z++) { FieldElement[][] Gs = new FieldElement[settings.getBlocksize()][this.s]; for (int i = 0; i < settings.getBlocksize(); i++) { diff --git a/pir/src/main/java/dk/au/pir/protocols/simple/SimpleClient.java b/pir/src/main/java/dk/au/pir/protocols/simple/SimpleClient.java index 4236223..c0612c2 100644 --- a/pir/src/main/java/dk/au/pir/protocols/simple/SimpleClient.java +++ b/pir/src/main/java/dk/au/pir/protocols/simple/SimpleClient.java @@ -36,7 +36,6 @@ public class SimpleClient { S2[index] = 1; } - this.profiler.addNetworkDelay(2); int resBit1 = this.profiler.clientReceive(this.servers[0].computeBit(this.profiler.clientSend(S1))); int resBit2 = this.profiler.clientReceive(this.servers[1].computeBit(this.profiler.clientSend(S2))); @@ -61,7 +60,6 @@ public class SimpleClient { } } - this.profiler.addNetworkDelay(2); int[] resBit1 = this.profiler.clientReceive(this.servers[0].computeBits(this.profiler.clientSend(S1s))); int[] resBit2 = this.profiler.clientReceive(this.servers[1].computeBits(this.profiler.clientSend(S2s)));