Author: mrogers
Date: 2006-11-24 00:20:24 +0000 (Fri, 24 Nov 2006)
New Revision: 11039
Modified:
trunk/apps/load-balancing-sims/phase7/sim/Node.java
trunk/apps/load-balancing-sims/phase7/sim/Peer.java
trunk/apps/load-balancing-sims/phase7/sim/Sim.java
trunk/apps/load-balancing-sims/phase7/sim/handlers/MessageHandler.java
Log:
Move token/backoff/throttle switches to the command line
Modified: trunk/apps/load-balancing-sims/phase7/sim/Node.java
===================================================================
--- trunk/apps/load-balancing-sims/phase7/sim/Node.java 2006-11-23 14:51:34 UTC
(rev 11038)
+++ trunk/apps/load-balancing-sims/phase7/sim/Node.java 2006-11-24 00:20:24 UTC
(rev 11039)
@@ -13,9 +13,9 @@
public final static double RETX_TIMER = 0.1; // Seconds
// Flow control
- public final static boolean USE_TOKENS = false;
- public final static boolean USE_BACKOFF = true;
- public final static boolean USE_THROTTLE = false;
+ public static boolean useTokens = false;
+ public static boolean useBackoff = false;
+ public static boolean useThrottle = false;
public final static int FLOW_TOKENS = 20; // Shared by all peers
public final static double TOKEN_DELAY = 1.0; // Allocate initial tokens
public final static double DELAY_DECAY = 0.99; // Exp moving average
@@ -64,10 +64,10 @@
if (Math.random() < 0.25) decrementMinHtl = true;
bandwidth = new TokenBucket (40000, 60000);
// Allocate flow control tokens after a short delay
- if (USE_TOKENS) Event.schedule (this, Math.random() * 0.1,
+ if (useTokens) Event.schedule (this, Math.random() * 0.1,
ALLOCATE_TOKENS, null);
searchQueue = new LinkedList<Search>();
- if (USE_THROTTLE) searchThrottle = new SearchThrottle();
+ if (useThrottle) searchThrottle = new SearchThrottle();
}
// Return true if a connection was added, false if already connected
@@ -154,7 +154,7 @@
log ("rejecting recently seen search " + id);
prev.sendMessage (new RejectedLoop (id));
- if (USE_TOKENS) allocateToken (prev);
+ if (useTokens) allocateToken (prev);
// Don't forward the same search back to prev
MessageHandler mh = messageHandlers.get (id);
if (mh != null) mh.removeNextHop (prev);
@@ -294,9 +294,9 @@
private void handleChkRequest (ChkRequest r, Peer prev)
{
- if ((USE_BACKOFF || USE_THROTTLE)
+ if ((useBackoff || useThrottle)
&& rejectIfOverloaded (prev, r.id)) return;
- if (USE_TOKENS && !getToken (prev)) return;
+ if (useTokens && !getToken (prev)) return;
if (rejectIfRecentlySeen (prev, r.id)) return;
// Accept the search
if (prev != null) {
@@ -312,7 +312,7 @@
for (int i = 0; i < 32; i++)
prev.sendMessage (new Block (r.id, i));
}
- if (USE_TOKENS) allocateToken (prev);
+ if (useTokens) allocateToken (prev);
return;
}
log ("key " + r.key + " not found in CHK store");
@@ -325,7 +325,7 @@
for (int i = 0; i < 32; i++)
prev.sendMessage (new Block (r.id, i));
}
- if (USE_TOKENS) allocateToken (prev);
+ if (useTokens) allocateToken (prev);
return;
}
log ("key " + r.key + " not found in CHK cache");
@@ -337,9 +337,9 @@
private void handleChkInsert (ChkInsert i, Peer prev)
{
- if ((USE_BACKOFF || USE_THROTTLE)
+ if ((useBackoff || useThrottle)
&& rejectIfOverloaded (prev, i.id)) return;
- if (USE_TOKENS && !getToken (prev)) return;
+ if (useTokens && !getToken (prev)) return;
if (rejectIfRecentlySeen (prev, i.id)) return;
// Accept the search
if (prev != null) {
@@ -354,9 +354,9 @@
private void handleSskRequest (SskRequest r, Peer prev)
{
- if ((USE_BACKOFF || USE_THROTTLE)
+ if ((useBackoff || useThrottle)
&& rejectIfOverloaded (prev, r.id)) return;
- if (USE_TOKENS && !getToken (prev)) return;
+ if (useTokens && !getToken (prev)) return;
if (rejectIfRecentlySeen (prev, r.id)) return;
// Look up the public key
boolean pub = pubKeyStore.get (r.key) || pubKeyCache.get(r.key);
@@ -378,7 +378,7 @@
prev.sendMessage
(new SskPubKey (r.id, r.key));
}
- if (USE_TOKENS) allocateToken (prev);
+ if (useTokens) allocateToken (prev);
return;
}
log ("key " + r.key + " not found in SSK store");
@@ -393,7 +393,7 @@
prev.sendMessage
(new SskPubKey (r.id, r.key));
}
- if (USE_TOKENS) allocateToken (prev);
+ if (useTokens) allocateToken (prev);
return;
}
log ("key " + r.key + " not found in SSK cache");
@@ -405,9 +405,9 @@
private void handleSskInsert (SskInsert i, Peer prev)
{
- if ((USE_BACKOFF || USE_THROTTLE)
+ if ((useBackoff || useThrottle)
&& rejectIfOverloaded (prev, i.id)) return;
- if (USE_TOKENS && !getToken (prev)) return;
+ if (useTokens && !getToken (prev)) return;
if (rejectIfRecentlySeen (prev, i.id)) return;
// Look up the public key
boolean pub = pubKeyStore.get (i.key) || pubKeyCache.get(i.key);
@@ -426,12 +426,12 @@
public void increaseSearchRate()
{
- if (USE_THROTTLE) searchThrottle.increaseRate();
+ if (useThrottle) searchThrottle.increaseRate();
}
public void decreaseSearchRate()
{
- if (USE_THROTTLE) searchThrottle.decreaseRate();
+ if (useThrottle) searchThrottle.decreaseRate();
}
public void removeMessageHandler (int id)
@@ -440,7 +440,7 @@
if (mh == null) log ("no message handler to remove for " + id);
else {
log ("removing message handler for " + id);
- if (USE_TOKENS) allocateToken (mh.prev);
+ if (useTokens) allocateToken (mh.prev);
}
}
@@ -495,7 +495,7 @@
{
searchQueue.add (s);
log (searchQueue.size() + " searches in queue");
- if (USE_THROTTLE) {
+ if (useThrottle) {
if (searchQueue.size() > 1) return; // Already waiting
double now = Event.time();
double wait = searchThrottle.delay (now);
@@ -526,7 +526,7 @@
pubKeyCache.put (s.key);
handleSskInsert ((SskInsert) s, null);
}
- if (USE_THROTTLE) {
+ if (useThrottle) {
double now = Event.time();
searchThrottle.sent (now);
if (searchQueue.isEmpty()) return;
Modified: trunk/apps/load-balancing-sims/phase7/sim/Peer.java
===================================================================
--- trunk/apps/load-balancing-sims/phase7/sim/Peer.java 2006-11-23 14:51:34 UTC
(rev 11038)
+++ trunk/apps/load-balancing-sims/phase7/sim/Peer.java 2006-11-24 00:20:24 UTC
(rev 11039)
@@ -253,7 +253,7 @@
// When a local RejectedOverload is received, back off unless backed off
public void localRejectedOverload()
{
- if (!Node.USE_BACKOFF) return;
+ if (!Node.useBackoff) return;
double now = Event.time();
if (now < backoffUntil) return; // Already backed off
backoffLength *= BACKOFF_MULTIPLIER;
@@ -265,7 +265,7 @@
// When a search is accepted, reset the backoff length unless backed off
public void successNotOverload()
{
- if (!Node.USE_BACKOFF) return;
+ if (!Node.useBackoff) return;
if (Event.time() < backoffUntil) return;
backoffLength = INITIAL_BACKOFF;
log ("resetting backoff length");
Modified: trunk/apps/load-balancing-sims/phase7/sim/Sim.java
===================================================================
--- trunk/apps/load-balancing-sims/phase7/sim/Sim.java 2006-11-23 14:51:34 UTC
(rev 11038)
+++ trunk/apps/load-balancing-sims/phase7/sim/Sim.java 2006-11-24 00:20:24 UTC
(rev 11039)
@@ -65,11 +65,20 @@
}
}
+ private static void usage()
+ {
+ System.err.println ("Usage: Sim <load> <tokens> <backoff>
<throttle>");
+ System.exit (1);
+ }
+
public static void main (String[] args)
{
- if (args.length != 1) System.exit (1);
- double interval = Double.parseDouble (args[0]);
- if (interval < 1.0) System.exit (1);
- new Sim (1.0 / interval);
+ if (args.length != 4) usage();
+ double load = Double.parseDouble (args[0]);
+ Node.useTokens = Boolean.parseBoolean (args[1]);
+ Node.useBackoff = Boolean.parseBoolean (args[2]);
+ Node.useThrottle = Boolean.parseBoolean (args[3]);
+ if (load <= 0.0) usage();
+ new Sim (load / 60.0);
}
}
Modified: trunk/apps/load-balancing-sims/phase7/sim/handlers/MessageHandler.java
===================================================================
--- trunk/apps/load-balancing-sims/phase7/sim/handlers/MessageHandler.java
2006-11-23 14:51:34 UTC (rev 11038)
+++ trunk/apps/load-balancing-sims/phase7/sim/handlers/MessageHandler.java
2006-11-24 00:20:24 UTC (rev 11039)
@@ -81,7 +81,7 @@
htl = node.decrementHtl (htl);
node.log (this + " has htl " + htl);
// Consume a token
- if (Node.USE_TOKENS) next.tokensOut--;
+ if (Node.useTokens) next.tokensOut--;
// Forward the search
node.log ("forwarding " + this + " to " + next.address);
next.sendMessage (makeSearchMessage());
@@ -94,9 +94,12 @@
// Find the closest remaining peer, if any
private Peer closestPeer()
{
- Peer p = closestPeer (Node.USE_BACKOFF);
+ Peer p = closestPeer (Node.useBackoff);
// If all peers are backed off, try again ignoring backoff
- if (p == null && Node.USE_BACKOFF) return closestPeer (false);
+ if (p == null && Node.useBackoff) {
+ node.log ("considering backed off peers");
+ return closestPeer (false);
+ }
else return p;
}
@@ -107,7 +110,7 @@
double closestDist = Double.POSITIVE_INFINITY;
Peer closestPeer = null;
for (Peer peer : nexts) {
- if (Node.USE_TOKENS && peer.tokensOut == 0) {
+ if (Node.useTokens && peer.tokensOut == 0) {
node.log ("no tokens for " + peer);
continue;
}