Statistician

- Added Timing Node Bootstrap.
- Added timing content lookup operation.
This commit is contained in:
Joshua Kissoon 2014-05-07 00:41:49 +05:30
parent baeb656050
commit 095738dcbc
3 changed files with 65 additions and 1 deletions

View File

@ -273,8 +273,11 @@ public class KademliaNode
* */ * */
public synchronized final void bootstrap(Node n) throws IOException, RoutingException 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); Operation op = new ConnectOperation(this.server, this, n, this.config);
op.execute(); 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 public StorageEntry get(GetParameter param) throws NoSuchElementException, IOException, ContentNotFoundException
{ {
long startTime = System.currentTimeMillis() / 1000L;
if (this.dht.contains(param)) if (this.dht.contains(param))
{ {
/* If the content exist in our own DHT, then return it. */ /* 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); return this.dht.get(param);
} }
/* Seems like it doesn't exist in our DHT, get it from other Nodes */ /* Seems like it doesn't exist in our DHT, get it from other Nodes */
ContentLookupOperation clo = new ContentLookupOperation(server, this, param, this.config); ContentLookupOperation clo = new ContentLookupOperation(server, this, param, this.config);
clo.execute(); clo.execute();
long endTime = System.currentTimeMillis() / 1000L;
this.statistician.addContentLookupTime(endTime - startTime);
return clo.getContentFound(); return clo.getContentFound();
} }

View File

@ -14,10 +14,20 @@ public class Statistician
/* How much data was sent and received by the server over the network */ /* How much data was sent and received by the server over the network */
private long totalDataSent, totalDataReceived; private long totalDataSent, totalDataReceived;
/* Bootstrap timings */
private long bootstrapTime;
/* Content lookup operation timing */
private int numContentLookups;
private long totalContentLookupTime;
{ {
this.totalDataSent = 0; this.totalDataSent = 0;
this.totalDataReceived = 0; this.totalDataReceived = 0;
this.bootstrapTime = 0;
this.numContentLookups = 0;
this.totalContentLookupTime = 0;
} }
/** /**
@ -55,4 +65,50 @@ public class Statistician
{ {
return this.totalDataReceived; 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;
}
} }

View File

@ -10,7 +10,7 @@ import java.io.File;
public class DefaultConfiguration implements KadConfiguration 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 RESPONSE_TIMEOUT = 1500;
private final static long OPERATION_TIMEOUT = 3000; private final static long OPERATION_TIMEOUT = 3000;
private final static int CONCURRENCY = 10; private final static int CONCURRENCY = 10;