Author: mrogers
Date: 2006-12-12 23:39:16 +0000 (Tue, 12 Dec 2006)
New Revision: 11364
Modified:
trunk/apps/load-balancing-sims/phase7/sim/Node.java
trunk/apps/load-balancing-sims/phase7/sim/Sim.java
trunk/apps/load-balancing-sims/phase7/sim/handlers/ChkInsertHandler.java
trunk/apps/load-balancing-sims/phase7/sim/handlers/ChkRequestHandler.java
trunk/apps/load-balancing-sims/phase7/sim/handlers/MessageHandler.java
trunk/apps/load-balancing-sims/phase7/sim/handlers/RequestHandler.java
trunk/apps/load-balancing-sims/phase7/sim/handlers/SskInsertHandler.java
trunk/apps/load-balancing-sims/phase7/sim/handlers/SskRequestHandler.java
Log:
Static counters for success and failure
Modified: trunk/apps/load-balancing-sims/phase7/sim/Node.java
===================================================================
--- trunk/apps/load-balancing-sims/phase7/sim/Node.java 2006-12-12 17:31:40 UTC
(rev 11363)
+++ trunk/apps/load-balancing-sims/phase7/sim/Node.java 2006-12-12 23:39:16 UTC
(rev 11364)
@@ -23,6 +23,11 @@
public final static double MAX_DELAY = 2.0; // Reject all, seconds
public final static double HIGH_DELAY = 1.0; // Reject some, seconds
+ // Statistics (for requests and inserts combined)
+ public static int succeededLocally = 0;
+ public static int succeededRemotely = 0;
+ public static int failed = 0;
+
public double location; // Routing location
public NetworkInterface net;
private HashMap<Integer,Peer> peers; // Look up a peer by its address
@@ -314,7 +319,10 @@
// If the data is in the store, return it
if (chkStore.get (r.key)) {
if (LOG) log ("key " + r.key + " found in CHK store");
- if (prev == null) log (r + " succeeded locally");
+ if (prev == null) {
+ if (LOG) log (r + " succeeded locally");
+ succeededLocally++;
+ }
else {
prev.sendMessage (new ChkDataFound (r.id));
for (int i = 0; i < 32; i++)
@@ -327,7 +335,10 @@
// If the data is in the cache, return it
if (chkCache.get (r.key)) {
if (LOG) log ("key " + r.key + " found in CHK cache");
- if (prev == null) log (r + " succeeded locally");
+ if (prev == null) {
+ if (LOG) log (r + " succeeded locally");
+ succeededLocally++;
+ }
else {
prev.sendMessage (new ChkDataFound (r.id));
for (int i = 0; i < 32; i++)
@@ -381,7 +392,10 @@
Integer data = sskStore.get (r.key);
if (pub && data != null) {
if (LOG) log ("key " + r.key + " found in SSK store");
- if (prev == null) log (r + " succeeded locally");
+ if (prev == null) {
+ if (LOG) log (r + " succeeded locally");
+ succeededLocally++;
+ }
else {
prev.sendMessage (new SskDataFound (r.id,data));
if (r.needPubKey)
@@ -396,7 +410,10 @@
data = sskCache.get (r.key);
if (pub && data != null) {
if (LOG) log ("key " + r.key + " found in SSK cache");
- if (prev == null) log (r + " succeeded locally");
+ if (prev == null) {
+ if (LOG) log (r + " succeeded locally");
+ succeededLocally++;
+ }
else {
prev.sendMessage (new SskDataFound (r.id,data));
if (r.needPubKey)
Modified: trunk/apps/load-balancing-sims/phase7/sim/Sim.java
===================================================================
--- trunk/apps/load-balancing-sims/phase7/sim/Sim.java 2006-12-12 17:31:40 UTC
(rev 11363)
+++ trunk/apps/load-balancing-sims/phase7/sim/Sim.java 2006-12-12 23:39:16 UTC
(rev 11364)
@@ -1,7 +1,7 @@
package sim;
import sim.generators.SimplePublisher;
-class Sim
+class Sim implements EventTarget
{
private final int NODES = 100; // Number of nodes
private final int DEGREE = 5; // Average degree
@@ -10,7 +10,7 @@
private final double LATENCY = 0.1; // Latency of all links in seconds
private Node[] nodes;
- public Sim (double rate)
+ public void run (double rate)
{
Network.reorder = true;
Network.lossRate = 0.001;
@@ -36,9 +36,14 @@
if (pub.addReader (nodes[index])) readers++;
}
}
+ // Reset the counters after the first hour
+ Event.schedule (this, 3600.0, RESET_COUNTERS, null);
// Run the simulation
Event.duration = 10800.0;
Event.run();
+ // Print the copiously detailed results
+ System.out.println (Node.succeededLocally + " "
+ + Node.succeededRemotely + " " + Node.failed);
}
// Return the lattice distance between a and b
@@ -84,6 +89,17 @@
Node.useBackoff = Boolean.parseBoolean (args[2]);
Node.useThrottle = Boolean.parseBoolean (args[3]);
if (load <= 0.0) usage();
- new Sim (load / 60.0);
+ new Sim().run (load / 60.0);
}
+
+ public void handleEvent (int type, Object data)
+ {
+ if (type == RESET_COUNTERS) {
+ Node.succeededLocally = 0;
+ Node.succeededRemotely = 0;
+ Node.failed = 0;
+ }
+ }
+
+ private final static int RESET_COUNTERS = 1;
}
Modified:
trunk/apps/load-balancing-sims/phase7/sim/handlers/ChkInsertHandler.java
===================================================================
--- trunk/apps/load-balancing-sims/phase7/sim/handlers/ChkInsertHandler.java
2006-12-12 17:31:40 UTC (rev 11363)
+++ trunk/apps/load-balancing-sims/phase7/sim/handlers/ChkInsertHandler.java
2006-12-12 23:39:16 UTC (rev 11364)
@@ -116,7 +116,8 @@
if (searchState != ACCEPTED && LOG)
node.log (ir + " out of order");
if (prev == null) {
- node.log (this + " succeeded");
+ if (LOG) node.log (this + " succeeded remotely");
+ Node.succeededRemotely++;
node.increaseSearchRate();
}
else prev.sendMessage (ir); // Forward the message
@@ -125,8 +126,11 @@
protected void sendReply()
{
+ // We count this as a remote success because the insert has
+ // run out of hops, so it must have left the node at some point
if (prev == null) {
- node.log (this + " succeeded");
+ if (LOG) node.log (this + " succeeded remotely");
+ Node.succeededRemotely++;
node.increaseSearchRate();
}
else prev.sendMessage (new InsertReply (id));
Modified:
trunk/apps/load-balancing-sims/phase7/sim/handlers/ChkRequestHandler.java
===================================================================
--- trunk/apps/load-balancing-sims/phase7/sim/handlers/ChkRequestHandler.java
2006-12-12 17:31:40 UTC (rev 11363)
+++ trunk/apps/load-balancing-sims/phase7/sim/handlers/ChkRequestHandler.java
2006-12-12 23:39:16 UTC (rev 11364)
@@ -47,7 +47,8 @@
if (blocksReceived == 32) {
node.cacheChk (key);
if (prev == null) {
- node.log (this + "succeeded");
+ if (LOG) node.log (this+ " succeeded remotely");
+ Node.succeededRemotely++;
node.increaseSearchRate();
}
finish();
@@ -72,7 +73,8 @@
if (blocksReceived == 32 && searchState == TRANSFERRING) {
node.cacheChk (key);
if (prev == null) {
- node.log (this + " succeeded");
+ if (LOG) node.log (this+ " succeeded remotely");
+ Node.succeededRemotely++;
node.increaseSearchRate();
}
finish();
Modified: trunk/apps/load-balancing-sims/phase7/sim/handlers/MessageHandler.java
===================================================================
--- trunk/apps/load-balancing-sims/phase7/sim/handlers/MessageHandler.java
2006-12-12 17:31:40 UTC (rev 11363)
+++ trunk/apps/load-balancing-sims/phase7/sim/handlers/MessageHandler.java
2006-12-12 23:39:16 UTC (rev 11364)
@@ -69,7 +69,8 @@
if (next == null) {
if (LOG) node.log ("route not found for " + this);
if (prev == null) {
- node.log (this + " failed (rnf)");
+ if (LOG) node.log (this + " failed (rnf)");
+ Node.failed++;
node.increaseSearchRate(); // Yes, increase
}
else prev.sendMessage (new RouteNotFound (id, htl));
@@ -181,7 +182,8 @@
p.localRejectedOverload(); // Back off from p
// Tell the sender to slow down
if (prev == null) {
- node.log (this + " failed (search)");
+ if (LOG) node.log (this + " failed (search)");
+ Node.failed++;
node.decreaseSearchRate();
}
else prev.sendMessage (new RejectedOverload (id, false));
Modified: trunk/apps/load-balancing-sims/phase7/sim/handlers/RequestHandler.java
===================================================================
--- trunk/apps/load-balancing-sims/phase7/sim/handlers/RequestHandler.java
2006-12-12 17:31:40 UTC (rev 11363)
+++ trunk/apps/load-balancing-sims/phase7/sim/handlers/RequestHandler.java
2006-12-12 23:39:16 UTC (rev 11364)
@@ -30,14 +30,20 @@
{
if (searchState != ACCEPTED && LOG)
node.log (dnf + " out of order");
- if (prev == null) node.log (this + " failed (dnf)");
+ if (prev == null) {
+ if (LOG) node.log (this + " failed (dnf)");
+ Node.failed++;
+ }
else prev.sendMessage (dnf); // Forward the message
finish();
}
protected void sendReply()
{
- if (prev == null) node.log (this + " failed (dnf)");
+ if (prev == null) {
+ if (LOG) node.log (this + " failed (dnf)");
+ Node.failed++;
+ }
else prev.sendMessage (new DataNotFound (id));
}
@@ -57,7 +63,10 @@
{
if (searchState != TRANSFERRING) return;
if (LOG) node.log (this + " transfer timeout from " + p);
- if (prev == null) node.log (this + " failed (xfer)");
+ if (prev == null) {
+ if (LOG) node.log (this + " failed (xfer)");
+ Node.failed++;
+ }
finish();
}
Modified:
trunk/apps/load-balancing-sims/phase7/sim/handlers/SskInsertHandler.java
===================================================================
--- trunk/apps/load-balancing-sims/phase7/sim/handlers/SskInsertHandler.java
2006-12-12 17:31:40 UTC (rev 11363)
+++ trunk/apps/load-balancing-sims/phase7/sim/handlers/SskInsertHandler.java
2006-12-12 23:39:16 UTC (rev 11364)
@@ -107,7 +107,8 @@
if (searchState != ACCEPTED && LOG)
node.log (ir + " out of order");
if (prev == null) {
- node.log (this + " succeeded");
+ if (LOG) node.log (this + " succeeded remotely");
+ Node.succeededRemotely++;
node.increaseSearchRate();
}
else prev.sendMessage (ir); // Forward the message
@@ -116,8 +117,11 @@
protected void sendReply()
{
+ // We count this as a remote success because the insert has
+ // run out of hops, so it must have left the node at some point
if (prev == null) {
- node.log (this + " succeeded");
+ if (LOG) node.log (this + " succeeded remotely");
+ Node.succeededRemotely++;
node.increaseSearchRate();
}
else prev.sendMessage (new InsertReply (id));
Modified:
trunk/apps/load-balancing-sims/phase7/sim/handlers/SskRequestHandler.java
===================================================================
--- trunk/apps/load-balancing-sims/phase7/sim/handlers/SskRequestHandler.java
2006-12-12 17:31:40 UTC (rev 11363)
+++ trunk/apps/load-balancing-sims/phase7/sim/handlers/SskRequestHandler.java
2006-12-12 23:39:16 UTC (rev 11364)
@@ -47,7 +47,8 @@
dataFound = df;
if (pubKey == null) return; // Keep waiting
if (prev == null) {
- node.log (this + " succeeded");
+ if (LOG) node.log (this + " succeeded remotely");
+ Node.succeededRemotely++;
node.increaseSearchRate();
}
else {
@@ -66,7 +67,8 @@
pubKey = pk;
if (dataFound == null) return; // Keep waiting
if (prev == null) {
- node.log (this + " succeeded");
+ if (LOG) node.log (this + " succeeded remotely");
+ Node.succeededRemotely++;
node.increaseSearchRate();
}
else {