Console: Fix lifetime participating bandwidth display (ticket #1706)

Add locking to HopConfig counts
Split participatingMessageCount stat into two stats,
participatingMessageCountAvgPerTunnel for throttle (same as old participatingMessagecount)
and participatingMessageCount for console (straight total)
Fix calculation of stat for throttle by adjusting for new
stat coalesce time (50 not 20 seconds)
This commit is contained in:
zzz
2015-11-13 21:18:21 +00:00
parent a028bba997
commit 8a1f02aa89
6 changed files with 52 additions and 17 deletions

View File

@ -276,7 +276,7 @@ class RouterThrottleImpl implements RouterThrottle {
// ok, we're not hosed, but can we handle the bandwidth requirements
// of another tunnel?
rs = _context.statManager().getRate("tunnel.participatingMessageCount");
rs = _context.statManager().getRate("tunnel.participatingMessageCountAvgPerTunnel");
r = null;
double messagesPerTunnel = DEFAULT_MESSAGES_PER_TUNNEL_ESTIMATE;
if (rs != null) {

View File

@ -18,7 +18,7 @@ public class RouterVersion {
/** deprecated */
public final static String ID = "Monotone";
public final static String VERSION = CoreVersion.VERSION;
public final static long BUILD = 26;
public final static long BUILD = 27;
/** for example "-test" */
public final static String EXTRA = "-rc";

View File

@ -26,6 +26,7 @@ public class HopConfig {
// these 4 were longs, let's save some space
// 2 billion * 1KB / 10 minutes = 3 GBps in a single tunnel
// we use synchronization instead of an AtomicInteger here to save space
private int _messagesProcessed;
private int _oldMessagesProcessed;
//private int _messagesSent;
@ -125,12 +126,29 @@ public class HopConfig {
/**
* Take note of a message being pumped through this tunnel.
* "processed" is for incoming and "sent" is for outgoing (could be dropped in between)
* We use synchronization instead of an AtomicInteger here to save space.
*/
public void incrementProcessedMessages() { _messagesProcessed++; }
public synchronized void incrementProcessedMessages() { _messagesProcessed++; }
public int getProcessedMessagesCount() { return _messagesProcessed; }
public synchronized int getProcessedMessagesCount() { return _messagesProcessed; }
public int getRecentMessagesCount() {
/**
* This returns the number of processed messages since
* the last time getAndResetRecentMessagesCount() was called.
* As of 0.9.23, does NOT reset the count, see getAndResetRecentMessagesCount().
*/
public synchronized int getRecentMessagesCount() {
return _messagesProcessed - _oldMessagesProcessed;
}
/**
* This returns the number of processed messages since the last time this was called,
* and resets the count. It should only be called by code that updates the router stats.
* See TunnelDispatcher.updateParticipatingStats().
*
* @since 0.9.23
*/
synchronized int getAndResetRecentMessagesCount() {
int rv = _messagesProcessed - _oldMessagesProcessed;
_oldMessagesProcessed = _messagesProcessed;
return rv;
@ -169,8 +187,9 @@ public class HopConfig {
}
buf.append(" exp. ").append(TunnelCreatorConfig.format(_expiration));
if (_messagesProcessed > 0)
buf.append(" used ").append(_messagesProcessed).append("KB");
int messagesProcessed = getProcessedMessagesCount();
if (messagesProcessed > 0)
buf.append(" used ").append(messagesProcessed).append("KB");
return buf.toString();
}
}

View File

@ -163,9 +163,14 @@ public class TunnelDispatcher implements Service {
ctx.statManager().createRateStat("tunnel.participatingMessageDropped",
"Dropped for exceeding share limit", "Tunnels",
new long[] { 60*1000l, 60*10*1000l });
// count for console
ctx.statManager().createRequiredRateStat("tunnel.participatingMessageCount",
"Number of 1KB participating messages", "Tunnels",
new long[] { 60*1000l, 60*10*1000l, 60*60*1000l });
// estimate for RouterThrottleImpl
ctx.statManager().createRequiredRateStat("tunnel.participatingMessageCountAvgPerTunnel",
"Estimate of participating messages per tunnel lifetime", "Tunnels",
new long[] { 60*1000l });
ctx.statManager().createRateStat("tunnel.ownedMessageCount",
"How many messages are sent through a tunnel we created (period == failures)?", "Tunnels",
new long[] { 60*1000l, 10*60*1000l, 60*60*1000l });
@ -711,7 +716,7 @@ public class TunnelDispatcher implements Service {
long tooYoung = _context.clock().now() - 60*1000;
long tooOld = tooYoung - 9*60*1000;
for (HopConfig cfg : _participatingConfig.values()) {
long c = cfg.getRecentMessagesCount();
long c = cfg.getAndResetRecentMessagesCount();
bw += c;
//bwOut += cfg.getRecentSentMessagesCount();
long created = cfg.getCreation();
@ -720,9 +725,15 @@ public class TunnelDispatcher implements Service {
tcount++;
count += c;
}
// This is an estimate of the average number of participating messages per tunnel
// in a tunnel lifetime, used only by RouterThrottleImpl
// 10 minutes / 50 seconds = 12
if (tcount > 0)
count = count * 30 / tcount;
_context.statManager().addRateData("tunnel.participatingMessageCount", count, ms);
count = count * (10*60*1000 / ms) / tcount;
_context.statManager().addRateData("tunnel.participatingMessageCountAvgPerTunnel", count, ms);
// This is a straight count of the total participating messages, used in the router console
_context.statManager().addRateData("tunnel.participatingMessageCount", bw, ms);
// Bandwidth in bits per second
_context.statManager().addRateData("tunnel.participatingBandwidth", bw*1024/(ms/1000), ms);
// moved to FIFOBandwidthRefiller
//_context.statManager().addRateData("tunnel.participatingBandwidthOut", bwOut*1024/(ms/1000), ms);