Console: Show smoothed receive BPS for SSU peers

Don't show zero send/receive BPS after 15 sec idle; show smoothed value,
so display isn't mostly zeros.
BPS sorters will now work correctly and totals are more accurate.
Pass now to send/receive BPS methods and BW estimator
Comment out UDPTransport.noteSend()
Fix alignment issue in NTCP peers table
Show 0 instead of 0.00 for zero BPS
Change rounding mode of formatters
This commit is contained in:
zzz committed 2023-01-15 08:17:09 -05:00
1 parent 65d99d2082
commit d6891d4b7a
6 files changed
+46 -17

No files matched your search

@@ -25,7 +25,6 @@ import net.i2p.router.transport.udp.InboundMessageFragments.ModifiableLong;
import net.i2p.router.util.CachedIteratorCollection;
import net.i2p.router.util.CoDelPriorityBlockingQueue;
import net.i2p.router.util.PriBlockingQueue;
import net.i2p.util.BandwidthEstimator;
import net.i2p.util.ConcurrentHashSet;
import net.i2p.util.Log;
import net.i2p.util.SimpleTimer2;
@@ -116,7 +115,7 @@ public class PeerState {
/** how many bytes can we send to the peer in the current second */
private int _sendWindowBytesRemaining;
private final Object _sendWindowBytesRemainingLock = new Object();
private final BandwidthEstimator _bwEstimator;
private final SimpleBandwidthEstimator _bwEstimator;
// smoothed value, for display only
private int _receiveBps;
private int _receiveBytes;
@@ -640,13 +639,21 @@ public class PeerState {
* The Westwood+ bandwidth estimate
* @return the smoothed send transfer rate
*/
public int getSendBps() { return (int) (_bwEstimator.getBandwidthEstimate() * 1000); }
public int getSendBps(long now) { return (int) (_bwEstimator.getBandwidthEstimate(now) * 1000); }
/**
* An approximation, for display only
* @return the smoothed receive transfer rate
*/
public synchronized int getReceiveBps() { return _receiveBps; }
public synchronized int getReceiveBps(long now) {
long duration = now - _receivePeriodBegin;
if (duration >= 1000) {
_receiveBps = (int)(0.9f*_receiveBps + 0.1f*(_receiveBytes * (1000f/duration)));
_receiveBytes = 0;
_receivePeriodBegin = now;
}
return _receiveBps;
}
int incrementConsecutiveFailedSends() {
synchronized(_outboundMessages) {
@@ -870,7 +877,7 @@ public class PeerState {
bwe = -1; // for log below
} else {
_sendWindowBytes = getVersion() == 2 ? PeerState2.MAX_MTU : (isIPv6() ? MAX_IPV6_MTU : LARGE_MTU);
bwe = _bwEstimator.getBandwidthEstimate();
bwe = _bwEstimator.getBandwidthEstimate(now);
_slowStartThreshold = Math.max( (int)(bwe * _rtt), 2 * _mtu);
}
@@ -87,7 +87,14 @@ class SimpleBandwidthEstimator implements BandwidthEstimator {
* @return the current bandwidth estimate in bytes/ms.
*/
public float getBandwidthEstimate() {
long now = _context.clock().now();
return getBandwidthEstimate(_context.clock().now());
}
/**
* @return the current bandwidth estimate in bytes/ms.
* @since 0.9.58
*/
public float getBandwidthEstimate(long now) {
// avoid deadlock
int rtt = _state.getRTT();
// anti-aliasing filter
@@ -3487,11 +3487,12 @@ public class UDPTransport extends TransportImpl implements TimedWeightedPriority
if (_log.shouldLog(Log.DEBUG))
_log.debug("Failed sending " + msg + " to " + msg.getPeer());
}
noteSend(msg, false);
//noteSend(msg, false);
if (m != null)
super.afterSend(m, false);
}
/*
private void noteSend(OutboundMessageState msg, boolean successful) {
// bail before we do all the work
if (!_context.messageHistory().getDoLog())
@@ -3529,6 +3530,7 @@ public class UDPTransport extends TransportImpl implements TimedWeightedPriority
(p != null ? p.getRemotePeer() : null), successful, buf.toString());
}
}
*/
public void failed(OutNetMessage msg, String reason) {
if (msg == null) return;
@@ -3545,7 +3547,7 @@ public class UDPTransport extends TransportImpl implements TimedWeightedPriority
if (msg == null) return;
if (_log.shouldLog(Log.DEBUG))
_log.debug("Sending message succeeded: " + msg);
noteSend(msg, true);
//noteSend(msg, true);
OutNetMessage m = msg.getMessage();
if (m != null)
super.afterSend(m, true);