Merge branch 'master' of gitfub.space:Pownie/alex-retrieval
This commit is contained in:
commit
85cd701f32
|
@ -20,7 +20,7 @@ public class Driver {
|
||||||
}
|
}
|
||||||
EvenSimplerClient client = new EvenSimplerClient(settings, servers, profiler);
|
EvenSimplerClient client = new EvenSimplerClient(settings, servers, profiler);
|
||||||
profiler.start();
|
profiler.start();
|
||||||
client.receiveBits(1);
|
client.receiveBits(0);
|
||||||
profiler.stop();
|
profiler.stop();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -31,7 +31,7 @@ public class Driver {
|
||||||
}
|
}
|
||||||
SimpleClient client = new SimpleClient(settings, servers, profiler);
|
SimpleClient client = new SimpleClient(settings, servers, profiler);
|
||||||
profiler.start();
|
profiler.start();
|
||||||
client.receiveBit(1);
|
client.receiveBit(0);
|
||||||
profiler.stop();
|
profiler.stop();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -42,7 +42,7 @@ public class Driver {
|
||||||
}
|
}
|
||||||
SimpleClient client = new SimpleClient(settings, servers, profiler);
|
SimpleClient client = new SimpleClient(settings, servers, profiler);
|
||||||
profiler.start();
|
profiler.start();
|
||||||
client.receiveBits(1);
|
client.receiveBits(0);
|
||||||
profiler.stop();
|
profiler.stop();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -53,7 +53,7 @@ public class Driver {
|
||||||
}
|
}
|
||||||
InterPolyClient client = new InterPolyClient(settings, servers, profiler);
|
InterPolyClient client = new InterPolyClient(settings, servers, profiler);
|
||||||
profiler.start();
|
profiler.start();
|
||||||
client.receive(1);
|
client.receive(0);
|
||||||
profiler.stop();
|
profiler.stop();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -64,78 +64,69 @@ public class Driver {
|
||||||
}
|
}
|
||||||
InterPolyClient client = new InterPolyClient(settings, servers, profiler);
|
InterPolyClient client = new InterPolyClient(settings, servers, profiler);
|
||||||
profiler.start();
|
profiler.start();
|
||||||
client.receiveBlock(1);
|
client.receiveBlock(0);
|
||||||
profiler.stop();
|
profiler.stop();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void runTests() {
|
private static void runTests() {
|
||||||
for (int numServers = 1; numServers <= 8; numServers = numServers*2) {
|
for (int numServers = 1; numServers <= 16; numServers = numServers*2) {
|
||||||
for (int databaseSize = 2; databaseSize <= 4096; databaseSize = databaseSize*2) {
|
for (int databaseSize = 2048; databaseSize <= 32_768; databaseSize = databaseSize*2) {
|
||||||
for (int blockSize = 1; blockSize <= Math.min(512, databaseSize); blockSize = blockSize*2) {
|
for (int blockSize = 64; blockSize <= 16_384; blockSize = blockSize*2) {
|
||||||
for (int latency = 0; latency <= 50; latency = latency + 10) {
|
for (int i = 0; i < 5; i++) {
|
||||||
for (int bandwidth = 1024; bandwidth <= 2048; bandwidth = bandwidth*2) {
|
runTest(numServers, databaseSize, blockSize);
|
||||||
runTest(numServers, databaseSize, blockSize, latency, bandwidth);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public 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, numServers, 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++) {
|
for (int i = 0; i < x.length; i++) {
|
||||||
x[i] = (int) (Math.random()*2); // 0 or 1
|
x[i] = (int) (Math.random()*2); // 0 or 1
|
||||||
}
|
}
|
||||||
Database database = new MemoryDatabase(settings, x);
|
Database database = new MemoryDatabase(settings, x);
|
||||||
Profiler profiler = new Profiler(latency, bandwidth/10, bandwidth);
|
Profiler profiler = new Profiler();
|
||||||
|
|
||||||
profiler.reset();
|
profiler.reset();
|
||||||
testEvenSimplerScheme(settings, database, profiler);
|
testEvenSimplerScheme(settings, database, profiler);
|
||||||
reportResult(numServers, databaseSize, blockSize, latency, bandwidth, profiler, "EvenSimplerScheme");
|
reportResult(numServers, databaseSize, blockSize, profiler, "EvenSimplerScheme");
|
||||||
|
|
||||||
|
|
||||||
if (numServers == 2) {
|
if (numServers == 2) {
|
||||||
profiler.reset();
|
profiler.reset();
|
||||||
testSimpleScheme(settings, database, profiler);
|
testSimpleScheme(settings, database, profiler);
|
||||||
reportResult(numServers, databaseSize, blockSize, latency, bandwidth, profiler, "SimpleScheme");
|
reportResult(numServers, databaseSize, blockSize, profiler, "SimpleScheme");
|
||||||
|
|
||||||
profiler.reset();
|
profiler.reset();
|
||||||
testSimpleBlockScheme(settings, database, profiler);
|
testSimpleBlockScheme(settings, database, profiler);
|
||||||
reportResult(numServers, databaseSize, blockSize, latency, bandwidth, profiler, "SimpleBlockScheme");
|
reportResult(numServers, databaseSize, blockSize, profiler, "SimpleBlockScheme");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (settings.getS() != 0 && numServers != 1) {
|
if (settings.getS() != 0 && numServers != 1) {
|
||||||
profiler.reset();
|
profiler.reset();
|
||||||
testGeneralInterPolyScheme(settings, database, profiler);
|
testGeneralInterPolyScheme(settings, database, profiler);
|
||||||
reportResult(numServers, databaseSize, blockSize, latency, bandwidth, profiler, "GeneralInterPolyScheme");
|
reportResult(numServers, databaseSize, blockSize, profiler, "GeneralInterPolyScheme");
|
||||||
|
|
||||||
profiler.reset();
|
profiler.reset();
|
||||||
testGeneralInterPolyBlockScheme(settings, database, profiler);
|
testGeneralInterPolyBlockScheme(settings, database, profiler);
|
||||||
reportResult(numServers, databaseSize, blockSize, latency, bandwidth, profiler, "GeneralInterPolyBlockScheme");
|
reportResult(numServers, databaseSize, blockSize, profiler, "GeneralInterPolyBlockScheme");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public 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(
|
System.out.println(
|
||||||
numServers + " " +
|
numServers + " " +
|
||||||
databaseSize + " " +
|
databaseSize + " " +
|
||||||
blockSize + " " +
|
blockSize + " " +
|
||||||
latency + " " +
|
|
||||||
bandwidth + " " +
|
|
||||||
protocolName + " " +
|
protocolName + " " +
|
||||||
profiler.getTotalCPUTime() + " " +
|
profiler.getTotalCPUTime() + " " +
|
||||||
profiler.getSent() + " " +
|
profiler.getSent() + " " +
|
||||||
profiler.getReceived() + " " +
|
profiler.getReceived()
|
||||||
profiler.getTotalNetworkTime() + " "
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
runTests(); // warm-up
|
|
||||||
System.out.println("================");
|
|
||||||
runTests();
|
runTests();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,20 +4,12 @@ import dk.au.pir.utils.FieldElement;
|
||||||
import dk.au.pir.utils.MathUtils;
|
import dk.au.pir.utils.MathUtils;
|
||||||
|
|
||||||
public class Profiler {
|
public class Profiler {
|
||||||
private final int latency;
|
|
||||||
private final int sendBandwidth;
|
|
||||||
private final int receiveBandwidth;
|
|
||||||
|
|
||||||
private int sent;
|
private int sent;
|
||||||
private int received;
|
private int received;
|
||||||
private int networkTime;
|
|
||||||
private long startTime;
|
private long startTime;
|
||||||
private long stopTime;
|
private long stopTime;
|
||||||
|
|
||||||
public Profiler(int latency, int sendBandwidth, int receiveBandwidth) {
|
public Profiler() {
|
||||||
this.latency = latency;
|
|
||||||
this.sendBandwidth = sendBandwidth;
|
|
||||||
this.receiveBandwidth = receiveBandwidth;
|
|
||||||
reset();
|
reset();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -33,19 +25,10 @@ public class Profiler {
|
||||||
public void reset() {
|
public void reset() {
|
||||||
this.sent = 0;
|
this.sent = 0;
|
||||||
this.received = 0;
|
this.received = 0;
|
||||||
this.networkTime = 0;
|
|
||||||
this.startTime = 0;
|
this.startTime = 0;
|
||||||
this.stopTime = 0;
|
this.stopTime = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void addNetworkDelay() {
|
|
||||||
this.addNetworkDelay(1);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void addNetworkDelay(int n) {
|
|
||||||
this.networkTime += latency * n;
|
|
||||||
}
|
|
||||||
|
|
||||||
public int clientSend(int number) {
|
public int clientSend(int number) {
|
||||||
this.sent += log2(number);
|
this.sent += log2(number);
|
||||||
return number;
|
return number;
|
||||||
|
@ -115,10 +98,6 @@ public class Profiler {
|
||||||
return this.stopTime - this.startTime;
|
return this.stopTime - this.startTime;
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getTotalNetworkTime() {
|
|
||||||
return networkTime + (this.sent/this.sendBandwidth) + (this.received/this.receiveBandwidth);
|
|
||||||
}
|
|
||||||
|
|
||||||
public int log2(int n) {
|
public int log2(int n) {
|
||||||
if (n == 0) {
|
if (n == 0) {
|
||||||
return 1; // technically incorrect but for the sake of profiling, a 0-bit requires 1 bit of space
|
return 1; // technically incorrect but for the sake of profiling, a 0-bit requires 1 bit of space
|
||||||
|
|
|
@ -15,14 +15,12 @@ public class EvenSimplerClient {
|
||||||
}
|
}
|
||||||
|
|
||||||
public int receiveBit(int index) {
|
public int receiveBit(int index) {
|
||||||
this.profiler.addNetworkDelay(2);
|
|
||||||
int[] data = this.profiler.clientReceive(this.servers[0].giveDatabase());
|
int[] data = this.profiler.clientReceive(this.servers[0].giveDatabase());
|
||||||
return data[index];
|
return data[index];
|
||||||
}
|
}
|
||||||
|
|
||||||
public int[] receiveBits(int record) {
|
public int[] receiveBits(int record) {
|
||||||
int[] res = new int[settings.getBlocksize()];
|
int[] res = new int[settings.getBlocksize()];
|
||||||
this.profiler.addNetworkDelay();
|
|
||||||
int[] data = this.profiler.clientReceive(this.servers[0].giveDatabase());
|
int[] data = this.profiler.clientReceive(this.servers[0].giveDatabase());
|
||||||
System.arraycopy(data, (record * settings.getBlocksize()), res, 0, settings.getBlocksize());
|
System.arraycopy(data, (record * settings.getBlocksize()), res, 0, settings.getBlocksize());
|
||||||
return res;
|
return res;
|
||||||
|
|
|
@ -60,7 +60,6 @@ public class InterPolyClient {
|
||||||
private int receiveBit(int index) {
|
private int receiveBit(int index) {
|
||||||
FieldElement[] randoms = this.getRandomFieldElements();
|
FieldElement[] randoms = this.getRandomFieldElements();
|
||||||
FieldElement[] Fs = new FieldElement[this.servers.length];
|
FieldElement[] Fs = new FieldElement[this.servers.length];
|
||||||
this.profiler.addNetworkDelay(2);
|
|
||||||
for (int z = 0; z < this.servers.length; z++) {
|
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))));
|
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
|
* 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++) {
|
for (int z = 0; z < this.servers.length; z++) {
|
||||||
FieldElement[][] Gs = new FieldElement[settings.getBlocksize()][this.s];
|
FieldElement[][] Gs = new FieldElement[settings.getBlocksize()][this.s];
|
||||||
for (int i = 0; i < settings.getBlocksize(); i++) {
|
for (int i = 0; i < settings.getBlocksize(); i++) {
|
||||||
|
|
|
@ -36,7 +36,6 @@ public class SimpleClient {
|
||||||
S2[index] = 1;
|
S2[index] = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
this.profiler.addNetworkDelay(2);
|
|
||||||
int resBit1 = this.profiler.clientReceive(this.servers[0].computeBit(this.profiler.clientSend(S1)));
|
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)));
|
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[] 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)));
|
int[] resBit2 = this.profiler.clientReceive(this.servers[1].computeBits(this.profiler.clientSend(S2s)));
|
||||||
|
|
||||||
|
|
|
@ -23,7 +23,6 @@ public class PIRSettings {
|
||||||
this.s = calculateS(numServers, databaseSize);
|
this.s = calculateS(numServers, databaseSize);
|
||||||
this.sequences = ProtocolUtils.createSequences(s, numServers, databaseSize);
|
this.sequences = ProtocolUtils.createSequences(s, numServers, databaseSize);
|
||||||
} catch (IllegalArgumentException error) {
|
} catch (IllegalArgumentException error) {
|
||||||
System.out.println("pls");
|
|
||||||
this.s = 0;
|
this.s = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user