From 5033a22a9b7cc30fa4a59cef5016ade3deac3dc1 Mon Sep 17 00:00:00 2001
From: jrandom <jrandom>
Date: Tue, 13 Dec 2005 21:56:41 +0000
Subject: [PATCH] 2005-12-13  zzz     * Don't test tunnels expiring within 90
 seconds     * Defer Test Tunnel jobs if job lag too large     * Use
 JobQueue.getMaxLag() rather than the jobQueue.jobLag stat to measure      
 job lag for tunnel build backoff, allowing for more agile handling      
 (since the stat is only updated once a minute)     * Use tunnel length
 override if all tunnels are expiring within one       minute.

---
 history.txt                                         | 11 ++++++++++-
 router/java/src/net/i2p/router/RouterVersion.java   |  4 ++--
 .../src/net/i2p/router/tunnel/pool/TestJob.java     | 10 +++++++++-
 .../src/net/i2p/router/tunnel/pool/TunnelPool.java  | 13 +++++++------
 4 files changed, 28 insertions(+), 10 deletions(-)

diff --git a/history.txt b/history.txt
index e9b6d3f4a2..6a502f39f2 100644
--- a/history.txt
+++ b/history.txt
@@ -1,4 +1,13 @@
-$Id: history.txt,v 1.352 2005/12/09 03:05:48 jrandom Exp $
+$Id: history.txt,v 1.353 2005/12/13 04:38:52 jrandom Exp $
+
+2005-12-13  zzz
+    * Don't test tunnels expiring within 90 seconds
+    * Defer Test Tunnel jobs if job lag too large
+    * Use JobQueue.getMaxLag() rather than the jobQueue.jobLag stat to measure
+      job lag for tunnel build backoff, allowing for more agile handling
+      (since the stat is only updated once a minute)
+    * Use tunnel length override if all tunnels are expiring within one
+      minute.
 
 2005-12-13  jrandom
     * Fixed I2PSnark's handling of some torrent files to deal with those
diff --git a/router/java/src/net/i2p/router/RouterVersion.java b/router/java/src/net/i2p/router/RouterVersion.java
index dff197ec62..487daebee1 100644
--- a/router/java/src/net/i2p/router/RouterVersion.java
+++ b/router/java/src/net/i2p/router/RouterVersion.java
@@ -15,9 +15,9 @@ import net.i2p.CoreVersion;
  *
  */
 public class RouterVersion {
-    public final static String ID = "$Revision: 1.308 $ $Date: 2005/12/08 15:53:41 $";
+    public final static String ID = "$Revision: 1.309 $ $Date: 2005/12/09 03:05:48 $";
     public final static String VERSION = "0.6.1.7";
-    public final static long BUILD = 2;
+    public final static long BUILD = 3;
     public static void main(String args[]) {
         System.out.println("I2P Router version: " + VERSION + "-" + BUILD);
         System.out.println("Router ID: " + RouterVersion.ID);
diff --git a/router/java/src/net/i2p/router/tunnel/pool/TestJob.java b/router/java/src/net/i2p/router/tunnel/pool/TestJob.java
index 5db5495147..1be33003a1 100644
--- a/router/java/src/net/i2p/router/tunnel/pool/TestJob.java
+++ b/router/java/src/net/i2p/router/tunnel/pool/TestJob.java
@@ -50,6 +50,14 @@ class TestJob extends JobImpl {
     }
     public String getName() { return "Test tunnel"; }
     public void runJob() {
+        long lag = getContext().jobQueue().getMaxLag();
+        if (lag > 3000) {
+            if (_log.shouldLog(Log.WARN))
+                _log.warn("Deferring test of " + _cfg + " due to job lag = " + lag);
+            getContext().statManager().addRateData("tunnel.testAborted", _cfg.getLength(), 0);
+            scheduleRetest();
+            return;
+        }
         _found = false;
         // note: testing with exploratory tunnels always, even if the tested tunnel
         // is a client tunnel (per _cfg.getDestination())
@@ -166,7 +174,7 @@ class TestJob extends JobImpl {
         _outTunnel = null;
         _replyTunnel = null;
         int delay = getDelay();
-        if (_cfg.getExpiration() > getContext().clock().now() + delay)
+        if (_cfg.getExpiration() > getContext().clock().now() + delay + (3 * getTestPeriod()) + 30*1000)
             requeue(delay);
     }
     
diff --git a/router/java/src/net/i2p/router/tunnel/pool/TunnelPool.java b/router/java/src/net/i2p/router/tunnel/pool/TunnelPool.java
index 34ec54c269..e6cb4ff003 100644
--- a/router/java/src/net/i2p/router/tunnel/pool/TunnelPool.java
+++ b/router/java/src/net/i2p/router/tunnel/pool/TunnelPool.java
@@ -141,7 +141,7 @@ public class TunnelPool {
             if (maxBuild > 0 && build > maxBuild)
                 build = maxBuild;
             int buildThrottle = MAX_BUILDS_PER_MINUTE;
-            int lag = (int) _context.statManager().getRate("jobQueue.jobLag").getRate(60*1000).getAverageValue();
+            long lag = _context.jobQueue().getMaxLag();
             int netErrors = (int) _context.statManager().getRate("udp.sendException").getRate(60*1000).getLastEventCount();
             if (lag > 3 * 1000 || netErrors > 5) {
                 if (_log.shouldLog(Log.WARN))
@@ -161,10 +161,11 @@ public class TunnelPool {
             if (build <= 0) return 0;
 
             if ((_settings.isExploratory() && baseTarget > countUsableTunnels(1)) ||
-                ((!_settings.isExploratory()) && baseTarget > countUsableTunnels(0)))
-                    _settings.setLengthOverride(1);
-                else
-                    _settings.setLengthOverride(0);
+                ((!_settings.isExploratory()) && baseTarget > countUsableTunnels(0)) ||
+                ((!_settings.isExploratory()) && countUsableTunnels(1) == 0))
+                _settings.setLengthOverride(1);
+            else
+                _settings.setLengthOverride(0);
 
             int wanted = build;
             build = _manager.allocateBuilds(build);
@@ -540,7 +541,7 @@ public class TunnelPool {
             else
                 added = refreshBuilders(0, 1);
             if ( (added > 0) && (_log.shouldLog(Log.WARN)) )
-                _log.warn("Additional parallel rebuilding of tunnel for " + TunnelPool.this.toString());
+                _log.warn(added + " additional parallel rebuild(s) for " + TunnelPool.this.toString());
             requeue(30*1000);
         }
     }
-- 
GitLab