diff --git a/src/kademlia/KademliaNode.java b/src/kademlia/KademliaNode.java index b242701..5be97b1 100644 --- a/src/kademlia/KademliaNode.java +++ b/src/kademlia/KademliaNode.java @@ -273,8 +273,11 @@ public class KademliaNode * */ public synchronized final void bootstrap(Node n) throws IOException, RoutingException { + long startTime = System.currentTimeMillis() / 1000L; Operation op = new ConnectOperation(this.server, this, n, this.config); op.execute(); + long endTime = System.currentTimeMillis() / 1000L; + this.statistician.setBootstrapTime(endTime - startTime); } /** @@ -321,15 +324,20 @@ public class KademliaNode */ public StorageEntry get(GetParameter param) throws NoSuchElementException, IOException, ContentNotFoundException { + long startTime = System.currentTimeMillis() / 1000L; if (this.dht.contains(param)) { /* If the content exist in our own DHT, then return it. */ + long endTime = System.currentTimeMillis() / 1000L; + this.statistician.addContentLookupTime(endTime - startTime); return this.dht.get(param); } /* Seems like it doesn't exist in our DHT, get it from other Nodes */ ContentLookupOperation clo = new ContentLookupOperation(server, this, param, this.config); clo.execute(); + long endTime = System.currentTimeMillis() / 1000L; + this.statistician.addContentLookupTime(endTime - startTime); return clo.getContentFound(); } diff --git a/src/kademlia/Statistician.java b/src/kademlia/Statistician.java index b3430cd..21a63ec 100644 --- a/src/kademlia/Statistician.java +++ b/src/kademlia/Statistician.java @@ -14,10 +14,20 @@ public class Statistician /* How much data was sent and received by the server over the network */ private long totalDataSent, totalDataReceived; + /* Bootstrap timings */ + private long bootstrapTime; + + /* Content lookup operation timing */ + private int numContentLookups; + private long totalContentLookupTime; + { this.totalDataSent = 0; this.totalDataReceived = 0; + this.bootstrapTime = 0; + this.numContentLookups = 0; + this.totalContentLookupTime = 0; } /** @@ -55,4 +65,50 @@ public class Statistician { return this.totalDataReceived; } + + /** + * Sets the bootstrap time for this Kademlia Node + * + * @param time The bootstrap time in milliseconds + */ + public void setBootstrapTime(long time) + { + this.bootstrapTime = time; + } + + public long getBootstrapTime() + { + return this.bootstrapTime; + } + + /** + * Add the timing for a new content lookup operation that took place + * + * @param time The time the content lookup took in milliseconds + */ + public void addContentLookupTime(long time) + { + this.numContentLookups++; + this.totalContentLookupTime += time; + } + + public int numContentLookups() + { + return this.numContentLookups; + } + + public long totalContentLookupTime() + { + return this.totalContentLookupTime; + } + + /** + * Compute the average time a content lookup took + * + * @return The average time + */ + public long averageContentLookupTime() + { + return this.totalContentLookupTime / this.numContentLookups; + } } diff --git a/src/kademlia/core/DefaultConfiguration.java b/src/kademlia/core/DefaultConfiguration.java index ba11934..a2bdf57 100644 --- a/src/kademlia/core/DefaultConfiguration.java +++ b/src/kademlia/core/DefaultConfiguration.java @@ -10,7 +10,7 @@ import java.io.File; public class DefaultConfiguration implements KadConfiguration { - private final static long RESTORE_INTERVAL = 5 * 1000; // Default at 1 hour + private final static long RESTORE_INTERVAL = 60 * 1000; // Default at 1 hour private final static long RESPONSE_TIMEOUT = 1500; private final static long OPERATION_TIMEOUT = 3000; private final static int CONCURRENCY = 10;