From 5ab813179d8c822cb19209c7c555825f36440e90 Mon Sep 17 00:00:00 2001 From: zzz Date: Fri, 3 Dec 2010 21:30:32 +0000 Subject: [PATCH] dont update stats after failure --- .../i2p/i2ptunnel/I2PTunnelHTTPServer.java | 14 +++++----- .../net/i2p/i2ptunnel/I2PTunnelServer.java | 26 ++++++++++++------- 2 files changed, 24 insertions(+), 16 deletions(-) diff --git a/apps/i2ptunnel/java/src/net/i2p/i2ptunnel/I2PTunnelHTTPServer.java b/apps/i2ptunnel/java/src/net/i2p/i2ptunnel/I2PTunnelHTTPServer.java index 1aa6a8347..21c77769a 100644 --- a/apps/i2ptunnel/java/src/net/i2p/i2ptunnel/I2PTunnelHTTPServer.java +++ b/apps/i2ptunnel/java/src/net/i2p/i2ptunnel/I2PTunnelHTTPServer.java @@ -138,6 +138,13 @@ public class I2PTunnelHTTPServer extends I2PTunnelServer { } else { new I2PTunnelRunner(s, socket, slock, null, modifiedHeader.getBytes(), null); } + + long afterHandle = getTunnel().getContext().clock().now(); + long timeToHandle = afterHandle - afterAccept; + getTunnel().getContext().statManager().addRateData("i2ptunnel.httpserver.blockingHandleTime", timeToHandle, 0); + if ( (timeToHandle > 1000) && (_log.shouldLog(Log.WARN)) ) + _log.warn("Took a while to handle the request for " + remoteHost + ':' + remotePort + + " [" + timeToHandle + ", socket create: " + (afterSocket-afterAccept) + "]"); } catch (SocketException ex) { try { // Send a 503, so the user doesn't get an HTTP Proxy error message @@ -162,13 +169,6 @@ public class I2PTunnelHTTPServer extends I2PTunnelServer { if (_log.shouldLog(Log.ERROR)) _log.error("OOM in HTTP server", oom); } - - long afterHandle = getTunnel().getContext().clock().now(); - long timeToHandle = afterHandle - afterAccept; - getTunnel().getContext().statManager().addRateData("i2ptunnel.httpserver.blockingHandleTime", timeToHandle, 0); - if ( (timeToHandle > 1000) && (_log.shouldLog(Log.WARN)) ) - _log.warn("Took a while to handle the request for " + remoteHost + ':' + remotePort + - " [" + timeToHandle + ", socket create: " + (afterSocket-afterAccept) + "]"); } private static class CompressedRequestor implements Runnable { diff --git a/apps/i2ptunnel/java/src/net/i2p/i2ptunnel/I2PTunnelServer.java b/apps/i2ptunnel/java/src/net/i2p/i2ptunnel/I2PTunnelServer.java index 6fc05daa4..bce682eef 100644 --- a/apps/i2ptunnel/java/src/net/i2p/i2ptunnel/I2PTunnelServer.java +++ b/apps/i2ptunnel/java/src/net/i2p/i2ptunnel/I2PTunnelServer.java @@ -268,6 +268,14 @@ public class I2PTunnelServer extends I2PTunnelTask implements Runnable { return rv; } + /** + * If usePool is set, this starts the Handler pool and exits. + * Otherwise, this is the accept() loop, and it + * hands each I2P socket to a new thread. + * Note that there is no option to handle each socket in-line, which + * might be appropriate for standard servers that are not filtering headers, + * and are thus unlikely to block. + */ public void run() { I2PServerSocket i2pS_S = sockMgr.getServerSocket(); if (shouldUsePool()) { @@ -300,9 +308,9 @@ public class I2PTunnelServer extends I2PTunnelTask implements Runnable { public boolean shouldUsePool() { return _usePool; } /** - * minor thread pool to pull off the accept() concurrently. there are still lots - * (and lots) of wasted threads within the I2PTunnelRunner, but its a start - * + * Minor thread pool to pull off the accept() concurrently. + * This is NOT used by default; enable and set number of Handlers + * in the options. */ private class Handler implements Runnable { private I2PServerSocket _serverSocket; @@ -336,6 +344,12 @@ public class I2PTunnelServer extends I2PTunnelTask implements Runnable { Socket s = new Socket(remoteHost, remotePort); afterSocket = I2PAppContext.getGlobalContext().clock().now(); new I2PTunnelRunner(s, socket, slock, null, null); + + long afterHandle = I2PAppContext.getGlobalContext().clock().now(); + long timeToHandle = afterHandle - afterAccept; + if ( (timeToHandle > 1000) && (_log.shouldLog(Log.WARN)) ) + _log.warn("Took a while to handle the request for " + remoteHost + ':' + remotePort + + " [" + timeToHandle + ", socket create: " + (afterSocket-afterAccept) + "]"); } catch (SocketException ex) { try { socket.close(); @@ -345,12 +359,6 @@ public class I2PTunnelServer extends I2PTunnelTask implements Runnable { } catch (IOException ex) { _log.error("Error while waiting for I2PConnections", ex); } - - long afterHandle = I2PAppContext.getGlobalContext().clock().now(); - long timeToHandle = afterHandle - afterAccept; - if ( (timeToHandle > 1000) && (_log.shouldLog(Log.WARN)) ) - _log.warn("Took a while to handle the request for " + remoteHost + ':' + remotePort + - " [" + timeToHandle + ", socket create: " + (afterSocket-afterAccept) + "]"); } }