From 70cf9e4ca7a79119914da45c84322056474b53d4 Mon Sep 17 00:00:00 2001
From: jrandom <jrandom>
Date: Sat, 6 May 2006 20:27:34 +0000
Subject: [PATCH] 2006-05-06  jrandom     * Readjust the tunnel creation
 timeouts to reject less but fail earlier,       while tracking the extended
 timeout events.

---
 history.txt                                          |  6 +++++-
 router/java/src/net/i2p/router/RouterVersion.java    |  4 ++--
 .../src/net/i2p/router/tunnel/pool/BuildHandler.java | 12 +++++++-----
 .../net/i2p/router/tunnel/pool/BuildRequestor.java   |  2 +-
 4 files changed, 15 insertions(+), 9 deletions(-)

diff --git a/history.txt b/history.txt
index 7910fecfce..59e143ef2b 100644
--- a/history.txt
+++ b/history.txt
@@ -1,4 +1,8 @@
-$Id: history.txt,v 1.468 2006/05/03 06:13:29 complication Exp $
+$Id: history.txt,v 1.469 2006/05/04 18:09:17 jrandom Exp $
+
+2006-05-06  jrandom
+    * Readjust the tunnel creation timeouts to reject less but fail earlier,
+      while tracking the extended timeout events.
 
 2006-05-04  jrandom
     * Short circuit a highly congested part of the stat logging unless its
diff --git a/router/java/src/net/i2p/router/RouterVersion.java b/router/java/src/net/i2p/router/RouterVersion.java
index 2e4967be8d..e69c126ca4 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.408 $ $Date: 2006/05/03 06:13:29 $";
+    public final static String ID = "$Revision: 1.409 $ $Date: 2006/05/04 18:08:51 $";
     public final static String VERSION = "0.6.1.17";
-    public final static long BUILD = 7;
+    public final static long BUILD = 8;
     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/BuildHandler.java b/router/java/src/net/i2p/router/tunnel/pool/BuildHandler.java
index 7c0b144d8b..774306e676 100644
--- a/router/java/src/net/i2p/router/tunnel/pool/BuildHandler.java
+++ b/router/java/src/net/i2p/router/tunnel/pool/BuildHandler.java
@@ -51,6 +51,7 @@ class BuildHandler {
         _context.statManager().createRateStat("tunnel.dropLoadProactive", "What the estimated queue time was when we dropped an inbound request (period is num pending)", "Tunnels", new long[] { 60*1000, 10*60*1000 });
         _context.statManager().createRateStat("tunnel.dropLoadProactiveAbort", "How often we would have proactively dropped a request, but allowed it through?", "Tunnels", new long[] { 60*1000, 10*60*1000 });
         _context.statManager().createRateStat("tunnel.handleRemaining", "How many pending inbound requests were left on the queue after one pass?", "Tunnels", new long[] { 60*1000, 10*60*1000 });
+        _context.statManager().createRateStat("tunnel.buildReplyTooSlow", "How often a tunnel build reply came back after we had given up waiting for it?", "Tunnels", new long[] { 60*1000, 10*60*1000 });
         
         _context.statManager().createRateStat("tunnel.receiveRejectionProbabalistic", "How often we are rejected probabalistically?", "Tunnels", new long[] { 10*60*1000l, 60*60*1000l, 24*60*60*1000l });
         _context.statManager().createRateStat("tunnel.receiveRejectionTransient", "How often we are rejected due to transient overload?", "Tunnels", new long[] { 10*60*1000l, 60*60*1000l, 24*60*60*1000l });
@@ -85,7 +86,7 @@ class BuildHandler {
                         handled.add(_inboundBuildMessages.remove(_inboundBuildMessages.size()-1));
                 } else {
                     // drop any expired messages
-                    long dropBefore = System.currentTimeMillis() - BuildRequestor.REQUEST_TIMEOUT;
+                    long dropBefore = System.currentTimeMillis() - (BuildRequestor.REQUEST_TIMEOUT*2);
                     do {
                         BuildMessageState state = (BuildMessageState)_inboundBuildMessages.get(0);
                         if (state.recvTime <= dropBefore) {
@@ -193,6 +194,7 @@ class BuildHandler {
                 _log.warn("The reply " + replyMessageId + " did not match any pending tunnels");
             if (_log.shouldLog(Log.DEBUG))
                 _log.debug("Pending tunnels: " + buf.toString());
+            _context.statManager().addRateData("tunnel.buildReplyTooSlow", 1, 0);
         } else {
             handleReply(state.msg, cfg, System.currentTimeMillis()-state.recvTime);
         }
@@ -276,7 +278,7 @@ class BuildHandler {
         if (_log.shouldLog(Log.DEBUG))
             _log.debug(state.msg.getUniqueId() + ": handling request after " + timeSinceReceived);
         
-        if (timeSinceReceived > BuildRequestor.REQUEST_TIMEOUT) {
+        if (timeSinceReceived > (BuildRequestor.REQUEST_TIMEOUT*2)) {
             // don't even bother, since we are so overloaded locally
             if (_log.shouldLog(Log.WARN))
                 _log.warn("Not even trying to handle/decrypt the request " + state.msg.getUniqueId() 
@@ -415,7 +417,7 @@ class BuildHandler {
         int proactiveDrops = countProactiveDrops();
         long recvDelay = System.currentTimeMillis()-state.recvTime;
         if (response == 0) {
-            float pDrop = recvDelay / (BuildRequestor.REQUEST_TIMEOUT);
+            float pDrop = recvDelay / (BuildRequestor.REQUEST_TIMEOUT*2);
             pDrop = (float)Math.pow(pDrop, 16);
             if (_context.random().nextFloat() < pDrop) { // || (proactiveDrops > MAX_PROACTIVE_DROPS) ) ) {
                 _context.statManager().addRateData("tunnel.rejectOverloaded", recvDelay, proactiveDrops);
@@ -598,7 +600,7 @@ class BuildHandler {
                         for (int i = 0; i < _inboundBuildMessages.size(); i++) {
                             BuildMessageState cur = (BuildMessageState)_inboundBuildMessages.get(i);
                             long age = System.currentTimeMillis() - cur.recvTime;
-                            if (age >= BuildRequestor.REQUEST_TIMEOUT) {
+                            if (age >= BuildRequestor.REQUEST_TIMEOUT*2) {
                                 _inboundBuildMessages.remove(i);
                                 i--;
                                 dropped++;
@@ -610,7 +612,7 @@ class BuildHandler {
                             _context.statManager().addRateData("tunnel.dropLoadBacklog", _inboundBuildMessages.size(), _inboundBuildMessages.size());
                         } else {
                             int queueTime = estimateQueueTime(_inboundBuildMessages.size());
-                            float pDrop = queueTime/((float)BuildRequestor.REQUEST_TIMEOUT);
+                            float pDrop = queueTime/((float)BuildRequestor.REQUEST_TIMEOUT*2);
                             pDrop = (float)Math.pow(pDrop, 16); // steeeep
                             float f = _context.random().nextFloat();
                             if ( (pDrop > f) && (allowProactiveDrop()) ) {
diff --git a/router/java/src/net/i2p/router/tunnel/pool/BuildRequestor.java b/router/java/src/net/i2p/router/tunnel/pool/BuildRequestor.java
index a013b7a398..4d584a8c39 100644
--- a/router/java/src/net/i2p/router/tunnel/pool/BuildRequestor.java
+++ b/router/java/src/net/i2p/router/tunnel/pool/BuildRequestor.java
@@ -22,7 +22,7 @@ class BuildRequestor {
             ORDER.add(new Integer(i));
     }
     private static final int PRIORITY = 500;
-    static final int REQUEST_TIMEOUT = 30*1000;
+    static final int REQUEST_TIMEOUT = 15*1000;
     
     private static boolean usePairedTunnels(RouterContext ctx) {
         String val = ctx.getProperty("router.usePairedTunnels");
-- 
GitLab