Author: mrogers
Date: 2006-11-20 20:44:07 +0000 (Mon, 20 Nov 2006)
New Revision: 11026
Added:
trunk/apps/load-balancing-sims/phase7/choplog
Modified:
trunk/apps/load-balancing-sims/phase7/sim/Node.java
trunk/apps/load-balancing-sims/phase7/sim/SearchThrottle.java
trunk/apps/load-balancing-sims/phase7/sim/Sim.java
trunk/apps/load-balancing-sims/phase7/sim/handlers/MessageHandler.java
Log:
Converted the search throttle to a leaky bucket
Added: trunk/apps/load-balancing-sims/phase7/choplog
===================================================================
--- trunk/apps/load-balancing-sims/phase7/choplog 2006-11-20 19:26:23 UTC
(rev 11025)
+++ trunk/apps/load-balancing-sims/phase7/choplog 2006-11-20 20:44:07 UTC
(rev 11026)
@@ -0,0 +1,5 @@
+#!/usr/bin/perl
+while (<STDIN>) {
+ split ' ';
+ print unless ($_[0] < $ARGV[0]);
+}
Property changes on: trunk/apps/load-balancing-sims/phase7/choplog
___________________________________________________________________
Name: svn:executable
+ *
Modified: trunk/apps/load-balancing-sims/phase7/sim/Node.java
===================================================================
--- trunk/apps/load-balancing-sims/phase7/sim/Node.java 2006-11-20 19:26:23 UTC
(rev 11025)
+++ trunk/apps/load-balancing-sims/phase7/sim/Node.java 2006-11-20 20:44:07 UTC
(rev 11026)
@@ -494,11 +494,16 @@
private void addToSearchQueue (Search s)
{
searchQueue.add (s);
+ log (searchQueue.size() + " searches in queue");
if (USE_THROTTLE) {
if (searchQueue.size() > 1) return; // Already waiting
double now = Event.time();
- double then = searchThrottle.nextSearchTime (now);
- Event.schedule (this, then - now, SEND_SEARCH, null);
+ double wait = searchThrottle.delay (now);
+ if (wait <= 0.0) sendSearch();
+ else {
+ log ("throttled for " + wait + " seconds");
+ Event.schedule (this, wait, SEND_SEARCH, null);
+ }
}
else sendSearch();
}
@@ -522,11 +527,12 @@
handleSskInsert ((SskInsert) s, null);
}
if (USE_THROTTLE) {
- searchThrottle.searchSent();
+ double now = Event.time();
+ searchThrottle.sent (now);
if (searchQueue.isEmpty()) return;
- double now = Event.time();
- double then = searchThrottle.nextSearchTime (now);
- Event.schedule (this, then - now, SEND_SEARCH, null);
+ double wait = searchThrottle.delay (now);
+ log ("throttled for " + wait + " seconds");
+ Event.schedule (this, wait, SEND_SEARCH, null);
}
}
Modified: trunk/apps/load-balancing-sims/phase7/sim/SearchThrottle.java
===================================================================
--- trunk/apps/load-balancing-sims/phase7/sim/SearchThrottle.java
2006-11-20 19:26:23 UTC (rev 11025)
+++ trunk/apps/load-balancing-sims/phase7/sim/SearchThrottle.java
2006-11-20 20:44:07 UTC (rev 11026)
@@ -1,4 +1,4 @@
-// An AIMD token bucket
+// An AIMD leaky bucket
package sim;
@@ -11,8 +11,7 @@
public final static double BETA = 0.969; // AIMD decrease parameter
private double rate = INITIAL_RATE;
- private double tokens = INITIAL_RATE, size = INITIAL_RATE;
- private double lastUpdated = 0.0; // Time
+ private double lastSent = Double.NEGATIVE_INFINITY; // Time
public void increaseRate()
{
@@ -28,18 +27,14 @@
Event.log ("rate decreased to " + rate);
}
- // Return the time when the next search can be sent
- public double nextSearchTime (double now)
+ // Return the time remaining until the next search can be sent
+ public double delay (double now)
{
- tokens += (now - lastUpdated) * rate;
- if (tokens > size) tokens = size;
- lastUpdated = now;
- if (tokens >= 1.0) return now;
- else return now + (1.0 - tokens) * rate;
+ return lastSent + 1.0 / rate - now;
}
- public void searchSent()
+ public void sent (double now)
{
- tokens--;
+ lastSent = now;
}
}
Modified: trunk/apps/load-balancing-sims/phase7/sim/Sim.java
===================================================================
--- trunk/apps/load-balancing-sims/phase7/sim/Sim.java 2006-11-20 19:26:23 UTC
(rev 11025)
+++ trunk/apps/load-balancing-sims/phase7/sim/Sim.java 2006-11-20 20:44:07 UTC
(rev 11026)
@@ -32,7 +32,6 @@
}
}
// Run the simulation
- Event.startLogging = 3600.0; // Settling time
Event.duration = 10800.0;
Event.run();
}
Modified: trunk/apps/load-balancing-sims/phase7/sim/handlers/MessageHandler.java
===================================================================
--- trunk/apps/load-balancing-sims/phase7/sim/handlers/MessageHandler.java
2006-11-20 19:26:23 UTC (rev 11025)
+++ trunk/apps/load-balancing-sims/phase7/sim/handlers/MessageHandler.java
2006-11-20 20:44:07 UTC (rev 11026)
@@ -100,11 +100,12 @@
Peer closestPeer = null;
for (Peer peer : nexts) {
if (Node.USE_TOKENS && peer.tokensOut == 0) {
- node.log ("bypassing busy peer " + peer);
+ node.log ("no tokens for " + peer);
continue;
}
if (Node.USE_BACKOFF && now < peer.backoffUntil) {
- node.log ("bypassing backed off peer " + peer);
+ node.log ("backed off from " + peer
+ + " until " + peer.backoffUntil);
continue;
}
double dist = Node.distance (keyLoc, peer.location);