[freenet-cvs] r10787 - trunk/apps/load-balancing-sims/phase7/sim

2006-11-01 Thread [email protected]
Author: mrogers
Date: 2006-11-01 20:16:48 + (Wed, 01 Nov 2006)
New Revision: 10787

Modified:
   trunk/apps/load-balancing-sims/phase7/sim/Node.java
   trunk/apps/load-balancing-sims/phase7/sim/Packet.java
   trunk/apps/load-balancing-sims/phase7/sim/Peer.java
   trunk/apps/load-balancing-sims/phase7/sim/TokenBucket.java
Log:
Refactored interleaving, coalescing, congestion control and bandwidth limiter

Modified: trunk/apps/load-balancing-sims/phase7/sim/Node.java
===
--- trunk/apps/load-balancing-sims/phase7/sim/Node.java 2006-11-01 20:04:40 UTC 
(rev 10786)
+++ trunk/apps/load-balancing-sims/phase7/sim/Node.java 2006-11-01 20:16:48 UTC 
(rev 10787)
@@ -45,7 +45,7 @@
pubKeyCache = new LruCache (1000);
if (Math.random() < 0.5) decrementMaxHtl = true;
if (Math.random() < 0.25) decrementMinHtl = true;
-   bandwidth = new TokenBucket (3, 6);
+   bandwidth = new TokenBucket (15000, 3);
}

// Return true if a connection was added, false if already connected

Modified: trunk/apps/load-balancing-sims/phase7/sim/Packet.java
===
--- trunk/apps/load-balancing-sims/phase7/sim/Packet.java   2006-11-01 
20:04:40 UTC (rev 10786)
+++ trunk/apps/load-balancing-sims/phase7/sim/Packet.java   2006-11-01 
20:16:48 UTC (rev 10787)
@@ -35,6 +35,12 @@
size += m.size();
}

+   public void addMessages (DeadlineQueue q, int maxSize)
+   {
+   while (q.size > 0 && size + q.headSize() <= maxSize)
+   addMessage (q.pop());
+   }
+   
public String toString()
{
return new String ("packet " + src + ":" + dest + ":" + seq);

Modified: trunk/apps/load-balancing-sims/phase7/sim/Peer.java
===
--- trunk/apps/load-balancing-sims/phase7/sim/Peer.java 2006-11-01 20:04:40 UTC 
(rev 10786)
+++ trunk/apps/load-balancing-sims/phase7/sim/Peer.java 2006-11-01 20:16:48 UTC 
(rev 10787)
@@ -34,7 +34,7 @@
private DeadlineQueue transferQueue; // Outgoing transfers
private CongestionWindow window; // AIMD congestion window
private double lastTransmission = Double.POSITIVE_INFINITY; // Time
-   private int searchBytesSent = 0, transferBytesSent = 0;
+   private boolean tgif = false; // "Transfers go in first" toggle
private boolean timerRunning = false; // Coalescing timer

// Receiver state
@@ -99,41 +99,64 @@
int waiting = ackQueue.size+searchQueue.size+transferQueue.size;
log (waiting + " bytes waiting");
if (waiting == 0) return false;
+   
// Return to slow start when the link is idle
double now = Event.time();
if (now - lastTransmission > LINK_IDLE * rtt) window.reset();
lastTransmission = now;
-   // How many bytes of messages can we send?
-   int available = Math.min (window.available(),
-   node.bandwidth.available());
-   log (available + " bytes available for packet");
-   // If there are no urgent acks, and no urgent messages or no
-   // room to send them, and not enough messages for a large
-   // packet or no room to send a large packet, give up!
-   if (ackQueue.deadline() > now
-   && (searchQueue.deadline() > now
-   || searchQueue.headSize() > available)
-   && (transferQueue.deadline() > now
-   || transferQueue.headSize() > available)
-   && (waiting < Packet.SENSIBLE_PAYLOAD
-   || available < Packet.SENSIBLE_PAYLOAD)) {
-   log ("not sending a packet");
-   return false;
-   }
+   
+   // How many bytes can we send?
+   int size = Math.min (Packet.MAX_SIZE, window.available());
+   size = Math.min (size, node.bandwidth.available());
+   log (size + " bytes available for packet");
+   
+   // Urgent acks to send?
+   if (ackQueue.deadline() <= now) return sendPacket (size);
+   // Urgent searches and room to send them?
+   if (searchQueue.deadline() <= now
+   && searchQueue.headSize() <= size) return sendPacket (size);
+   // Urgent transfers and room to send them?
+   if (transferQueue.deadline() <= now
+   && transferQueue.headSize() <= size) return sendPacket (size);
+   // Enough non-urgent messages for a large packet?
+   if (waiting >= Packet.SENSIBLE_PAYLOAD
+   && size >= Packet.SENSIBLE_PAYLOAD) return sendPacket (si

[freenet-cvs] r10787 - trunk/apps/load-balancing-sims/phase7/sim

2006-11-01 Thread mrogers
Author: mrogers
Date: 2006-11-01 20:16:48 + (Wed, 01 Nov 2006)
New Revision: 10787

Modified:
   trunk/apps/load-balancing-sims/phase7/sim/Node.java
   trunk/apps/load-balancing-sims/phase7/sim/Packet.java
   trunk/apps/load-balancing-sims/phase7/sim/Peer.java
   trunk/apps/load-balancing-sims/phase7/sim/TokenBucket.java
Log:
Refactored interleaving, coalescing, congestion control and bandwidth limiter

Modified: trunk/apps/load-balancing-sims/phase7/sim/Node.java
===
--- trunk/apps/load-balancing-sims/phase7/sim/Node.java 2006-11-01 20:04:40 UTC 
(rev 10786)
+++ trunk/apps/load-balancing-sims/phase7/sim/Node.java 2006-11-01 20:16:48 UTC 
(rev 10787)
@@ -45,7 +45,7 @@
pubKeyCache = new LruCache (1000);
if (Math.random() < 0.5) decrementMaxHtl = true;
if (Math.random() < 0.25) decrementMinHtl = true;
-   bandwidth = new TokenBucket (3, 6);
+   bandwidth = new TokenBucket (15000, 3);
}

// Return true if a connection was added, false if already connected

Modified: trunk/apps/load-balancing-sims/phase7/sim/Packet.java
===
--- trunk/apps/load-balancing-sims/phase7/sim/Packet.java   2006-11-01 
20:04:40 UTC (rev 10786)
+++ trunk/apps/load-balancing-sims/phase7/sim/Packet.java   2006-11-01 
20:16:48 UTC (rev 10787)
@@ -35,6 +35,12 @@
size += m.size();
}

+   public void addMessages (DeadlineQueue q, int maxSize)
+   {
+   while (q.size > 0 && size + q.headSize() <= maxSize)
+   addMessage (q.pop());
+   }
+   
public String toString()
{
return new String ("packet " + src + ":" + dest + ":" + seq);

Modified: trunk/apps/load-balancing-sims/phase7/sim/Peer.java
===
--- trunk/apps/load-balancing-sims/phase7/sim/Peer.java 2006-11-01 20:04:40 UTC 
(rev 10786)
+++ trunk/apps/load-balancing-sims/phase7/sim/Peer.java 2006-11-01 20:16:48 UTC 
(rev 10787)
@@ -34,7 +34,7 @@
private DeadlineQueue transferQueue; // Outgoing transfers
private CongestionWindow window; // AIMD congestion window
private double lastTransmission = Double.POSITIVE_INFINITY; // Time
-   private int searchBytesSent = 0, transferBytesSent = 0;
+   private boolean tgif = false; // "Transfers go in first" toggle
private boolean timerRunning = false; // Coalescing timer

// Receiver state
@@ -99,41 +99,64 @@
int waiting = ackQueue.size+searchQueue.size+transferQueue.size;
log (waiting + " bytes waiting");
if (waiting == 0) return false;
+   
// Return to slow start when the link is idle
double now = Event.time();
if (now - lastTransmission > LINK_IDLE * rtt) window.reset();
lastTransmission = now;
-   // How many bytes of messages can we send?
-   int available = Math.min (window.available(),
-   node.bandwidth.available());
-   log (available + " bytes available for packet");
-   // If there are no urgent acks, and no urgent messages or no
-   // room to send them, and not enough messages for a large
-   // packet or no room to send a large packet, give up!
-   if (ackQueue.deadline() > now
-   && (searchQueue.deadline() > now
-   || searchQueue.headSize() > available)
-   && (transferQueue.deadline() > now
-   || transferQueue.headSize() > available)
-   && (waiting < Packet.SENSIBLE_PAYLOAD
-   || available < Packet.SENSIBLE_PAYLOAD)) {
-   log ("not sending a packet");
-   return false;
-   }
+   
+   // How many bytes can we send?
+   int size = Math.min (Packet.MAX_SIZE, window.available());
+   size = Math.min (size, node.bandwidth.available());
+   log (size + " bytes available for packet");
+   
+   // Urgent acks to send?
+   if (ackQueue.deadline() <= now) return sendPacket (size);
+   // Urgent searches and room to send them?
+   if (searchQueue.deadline() <= now
+   && searchQueue.headSize() <= size) return sendPacket (size);
+   // Urgent transfers and room to send them?
+   if (transferQueue.deadline() <= now
+   && transferQueue.headSize() <= size) return sendPacket (size);
+   // Enough non-urgent messages for a large packet?
+   if (waiting >= Packet.SENSIBLE_PAYLOAD
+   && size >= Packet.SENSIBLE_PAYLOA