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
This commit is contained in:
@ -93,6 +93,15 @@ public class Router {
|
|||||||
_oomListener = new I2PThread.OOMEventListener() {
|
_oomListener = new I2PThread.OOMEventListener() {
|
||||||
public void outOfMemory(OutOfMemoryError oom) {
|
public void outOfMemory(OutOfMemoryError oom) {
|
||||||
_log.log(Log.CRIT, "Thread ran out of memory", 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();
|
shutdown();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@ -310,8 +319,8 @@ public class Router {
|
|||||||
RateStat receiveRate = _context.statManager().getRate("transport.receiveMessageSize");
|
RateStat receiveRate = _context.statManager().getRate("transport.receiveMessageSize");
|
||||||
for (int i = 0; i < receiveRate.getPeriods().length; i++) {
|
for (int i = 0; i < receiveRate.getPeriods().length; i++) {
|
||||||
Rate rate = receiveRate.getRate(receiveRate.getPeriods()[i]);
|
Rate rate = receiveRate.getRate(receiveRate.getPeriods()[i]);
|
||||||
double bytes = rate.getLastTotalValue() + rate.getCurrentTotalValue();
|
double bytes = rate.getLastTotalValue();
|
||||||
long ms = rate.getLastTotalEventTime() + rate.getLastTotalEventTime();
|
long ms = rate.getLastTotalEventTime();
|
||||||
if (ms <= 0) {
|
if (ms <= 0) {
|
||||||
bytes = 0;
|
bytes = 0;
|
||||||
ms = 1;
|
ms = 1;
|
||||||
@ -330,7 +339,7 @@ public class Router {
|
|||||||
buf.append(DataHelper.formatDuration(rate.getPeriod())).append(" period receive avg: ");
|
buf.append(DataHelper.formatDuration(rate.getPeriod())).append(" period receive avg: ");
|
||||||
// we include lastPeriod + current *partial* period, and jrandom is too lazy to calculate how
|
// 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.
|
// 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) {
|
if (bps > 2048) {
|
||||||
bps /= 1024.0d;
|
bps /= 1024.0d;
|
||||||
buf.append(fmt.format(bps)).append(" KBps");
|
buf.append(fmt.format(bps)).append(" KBps");
|
||||||
@ -407,8 +416,15 @@ public class Router {
|
|||||||
r.runRouter();
|
r.runRouter();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
private static int __id = 0;
|
||||||
private class ShutdownHook extends Thread {
|
private class ShutdownHook extends Thread {
|
||||||
|
private int _id;
|
||||||
|
public ShutdownHook() {
|
||||||
|
_id = ++__id;
|
||||||
|
}
|
||||||
public void run() {
|
public void run() {
|
||||||
|
setName("Router " + _id + " shutdown");
|
||||||
_log.log(Log.CRIT, "Shutting down the router...");
|
_log.log(Log.CRIT, "Shutting down the router...");
|
||||||
shutdown();
|
shutdown();
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user