From e2da05b19707f4c0743d31b3d0c6a1cb9beb772a Mon Sep 17 00:00:00 2001 From: jrandom Date: Sun, 20 Jun 2004 01:18:31 +0000 Subject: [PATCH] more accurrate (but less lively) bandwidth rate calculation (since we dont necessarily calculate exactly on the edge of a measurement period, we use the data from the last full period) logging on OOM --- router/java/src/net/i2p/router/Router.java | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/router/java/src/net/i2p/router/Router.java b/router/java/src/net/i2p/router/Router.java index b7cd11d19..b99c577ab 100644 --- a/router/java/src/net/i2p/router/Router.java +++ b/router/java/src/net/i2p/router/Router.java @@ -93,6 +93,15 @@ public class Router { _oomListener = new I2PThread.OOMEventListener() { public void outOfMemory(OutOfMemoryError oom) { _log.log(Log.CRIT, "Thread ran out of memory", oom); + for (int i = 0; i < 5; i++) { // try this 5 times, in case it OOMs + try { + _log.log(Log.CRIT, "free mem: " + Runtime.getRuntime().freeMemory() + + " total mem: " + Runtime.getRuntime().totalMemory()); + break; // w00t + } catch (OutOfMemoryError oome) { + // gobble + } + } shutdown(); } }; @@ -310,8 +319,8 @@ public class Router { RateStat receiveRate = _context.statManager().getRate("transport.receiveMessageSize"); for (int i = 0; i < receiveRate.getPeriods().length; i++) { Rate rate = receiveRate.getRate(receiveRate.getPeriods()[i]); - double bytes = rate.getLastTotalValue() + rate.getCurrentTotalValue(); - long ms = rate.getLastTotalEventTime() + rate.getLastTotalEventTime(); + double bytes = rate.getLastTotalValue(); + long ms = rate.getLastTotalEventTime(); if (ms <= 0) { bytes = 0; ms = 1; @@ -330,7 +339,7 @@ public class Router { buf.append(DataHelper.formatDuration(rate.getPeriod())).append(" period receive avg: "); // we include lastPeriod + current *partial* period, and jrandom is too lazy to calculate how // much of that partial is contained here, so 2*period it is. - bps = bytes*1000.0d/(2*rate.getPeriod()); + bps = bytes*1000.0d/(rate.getPeriod()); if (bps > 2048) { bps /= 1024.0d; buf.append(fmt.format(bps)).append(" KBps"); @@ -407,8 +416,15 @@ public class Router { r.runRouter(); } + + private static int __id = 0; private class ShutdownHook extends Thread { + private int _id; + public ShutdownHook() { + _id = ++__id; + } public void run() { + setName("Router " + _id + " shutdown"); _log.log(Log.CRIT, "Shutting down the router..."); shutdown(); }