mirror of
https://github.com/ChronosX88/KademliaDHT.git
synced 2024-11-22 02:02:21 +00:00
Statistician
- Added Timing Node Bootstrap. - Added timing content lookup operation.
This commit is contained in:
parent
baeb656050
commit
095738dcbc
@ -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();
|
||||
}
|
||||
|
||||
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
@ -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;
|
||||
|
Loading…
Reference in New Issue
Block a user