Statistician

- Added measuring the route Length (Hop Length) of content lookup operation
This commit is contained in:
Joshua Kissoon 2014-05-07 09:26:29 +05:30
parent 92ce527c0c
commit b90a87b149
3 changed files with 24 additions and 5 deletions

View File

@ -329,7 +329,7 @@ public class KademliaNode
{
/* If the content exist in our own DHT, then return it. */
long endTime = System.nanoTime();
this.statistician.addContentLookupTime(endTime - startTime);
this.statistician.addContentLookup(endTime - startTime, 0);
return this.dht.get(param);
}
@ -337,7 +337,7 @@ public class KademliaNode
ContentLookupOperation clo = new ContentLookupOperation(server, this, param, this.config);
clo.execute();
long endTime = System.nanoTime();
this.statistician.addContentLookupTime(endTime - startTime);
this.statistician.addContentLookup(endTime - startTime, clo.routeLength());
return clo.getContentFound();
}

View File

@ -17,9 +17,10 @@ public class Statistician
/* Bootstrap timings */
private long bootstrapTime;
/* Content lookup operation timing */
/* Content lookup operation timing & route length */
private int numContentLookups;
private long totalContentLookupTime;
private long totalRouteLength;
{
@ -28,6 +29,7 @@ public class Statistician
this.bootstrapTime = 0;
this.numContentLookups = 0;
this.totalContentLookupTime = 0;
this.totalRouteLength = 0;
}
/**
@ -85,11 +87,13 @@ public class Statistician
* Add the timing for a new content lookup operation that took place
*
* @param time The time the content lookup took in nanoseconds
* @param routeLength The length of the route it took to get the content
*/
public void addContentLookupTime(long time)
public void addContentLookup(long time, int routeLength)
{
this.numContentLookups++;
this.totalContentLookupTime += time;
this.totalRouteLength += routeLength;
}
public int numContentLookups()

View File

@ -56,10 +56,14 @@ public class ContentLookupOperation implements Operation, Receiver
/* Used to sort nodes */
private final Comparator comparator;
/* Statistical information */
private int routeLength; // Length of the route to find this content
{
messagesTransiting = new HashMap<>();
isContentFound = false;
routeLength = 1;
}
/**
@ -250,6 +254,9 @@ public class ContentLookupOperation implements Operation, Receiver
}
else
{
/* Our hop length is increased */
this.routeLength++;
/* The reply received is a NodeReplyMessage with nodes closest to the content needed */
NodeReplyMessage msg = (NodeReplyMessage) incoming;
@ -311,4 +318,12 @@ public class ContentLookupOperation implements Operation, Receiver
throw new ContentNotFoundException("No Value was found for the given key.");
}
}
/**
* @return How many hops it took in order to get to the content.
*/
public int routeLength()
{
return this.routeLength;
}
}