mirror of
https://github.com/ChronosX88/KademliaDHT.git
synced 2024-12-23 00:01:46 +00:00
Statistician
- Added measuring the route Length (Hop Length) of content lookup operation
This commit is contained in:
parent
92ce527c0c
commit
b90a87b149
@ -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();
|
||||
}
|
||||
|
||||
|
@ -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;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -84,12 +86,14 @@ 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 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()
|
||||
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user