From 2e3040715b915a022099122c2d9f01cc3e4b7ce5 Mon Sep 17 00:00:00 2001 From: Atlante45 Date: Wed, 30 Mar 2016 14:59:46 -0700 Subject: [PATCH] Delay congestion epoch's first decrease --- .../networking/src/udt/CongestionControl.cpp | 42 ++++++++++++------- .../networking/src/udt/CongestionControl.h | 12 ++++-- 2 files changed, 35 insertions(+), 19 deletions(-) diff --git a/libraries/networking/src/udt/CongestionControl.cpp b/libraries/networking/src/udt/CongestionControl.cpp index d30be2c139..bb95fef05b 100644 --- a/libraries/networking/src/udt/CongestionControl.cpp +++ b/libraries/networking/src/udt/CongestionControl.cpp @@ -11,8 +11,6 @@ #include "CongestionControl.h" -#include - #include "Packet.h" using namespace udt; @@ -40,7 +38,10 @@ void CongestionControl::setPacketSendPeriod(double newSendPeriod) { } DefaultCC::DefaultCC() : - _lastDecreaseMaxSeq(SequenceNumber {SequenceNumber::MAX }) + _lastDecreaseMaxSeq(SequenceNumber {SequenceNumber::MAX }), + _rd(), + _generator(_rd()), + _distribution(1, 1) { _mss = udt::MAX_PACKET_SIZE_WITH_UDP_HEADER; @@ -152,15 +153,18 @@ void DefaultCC::onLoss(SequenceNumber rangeStart, SequenceNumber rangeEnd) { // check if this NAK starts a new congestion period - this will be the case if the // NAK received occured for a packet sent after the last decrease if (rangeStart > _lastDecreaseMaxSeq) { + _delayedDecrease = (rangeStart == rangeEnd); _lastDecreasePeriod = _packetSendPeriod; - - setPacketSendPeriod(ceil(_packetSendPeriod * INTER_PACKET_ARRIVAL_INCREASE)); // use EWMA to update the average number of NAKs per congestion static const double NAK_EWMA_ALPHA = 0.125; _avgNAKNum = (int)ceil(_avgNAKNum * (1 - NAK_EWMA_ALPHA) + _nakCount * NAK_EWMA_ALPHA); - + + if (!_delayedDecrease) { + setPacketSendPeriod(ceil(_packetSendPeriod * INTER_PACKET_ARRIVAL_INCREASE)); + } + // update the count of NAKs and count of decreases in this interval _nakCount = 1; _decreaseCount = 1; @@ -171,18 +175,24 @@ void DefaultCC::onLoss(SequenceNumber rangeStart, SequenceNumber rangeEnd) { _randomDecreaseThreshold = 1; } else { // avoid synchronous rate decrease across connections using randomization - std::random_device rd; - std::mt19937 generator(rd()); - std::uniform_int_distribution<> distribution(1, std::max(1, _avgNAKNum)); + if (_distribution.b() != _avgNAKNum) { + _distribution = std::uniform_int_distribution<>(1, std::max(1, _avgNAKNum)); + } - _randomDecreaseThreshold = distribution(generator); + _randomDecreaseThreshold = _distribution(_generator); + } + } else { + ++_nakCount; + + if (_delayedDecrease && _nakCount == 2) { + setPacketSendPeriod(ceil(_packetSendPeriod * INTER_PACKET_ARRIVAL_INCREASE)); + } else if ((_decreaseCount++ < MAX_DECREASES_PER_CONGESTION_EPOCH) && ((_nakCount % _randomDecreaseThreshold) == 0)) { + // there have been fewer than MAX_DECREASES_PER_CONGESTION_EPOCH AND this NAK matches the random count at which we + // decided we would decrease the packet send period + + setPacketSendPeriod(ceil(_packetSendPeriod * INTER_PACKET_ARRIVAL_INCREASE)); + _lastDecreaseMaxSeq = _sendCurrSeqNum; } - } else if ((_decreaseCount++ < MAX_DECREASES_PER_CONGESTION_EPOCH) && ((++_nakCount % _randomDecreaseThreshold) == 0)) { - // there have been fewer than MAX_DECREASES_PER_CONGESTION_EPOCH AND this NAK matches the random count at which we - // decided we would decrease the packet send period - - setPacketSendPeriod(ceil(_packetSendPeriod * INTER_PACKET_ARRIVAL_INCREASE)); - _lastDecreaseMaxSeq = _sendCurrSeqNum; } } diff --git a/libraries/networking/src/udt/CongestionControl.h b/libraries/networking/src/udt/CongestionControl.h index 8297b5f6bd..9599df7465 100644 --- a/libraries/networking/src/udt/CongestionControl.h +++ b/libraries/networking/src/udt/CongestionControl.h @@ -15,7 +15,7 @@ #include #include #include -#include +#include #include @@ -81,8 +81,8 @@ private: bool _userDefinedRTO { false }; // if the RTO value is defined by users int _rto { -1 }; // RTO value, microseconds }; - - + + class CongestionControlVirtualFactory { public: virtual ~CongestionControlVirtualFactory() {} @@ -124,6 +124,12 @@ private: int _randomDecreaseThreshold { 1 }; // random threshold on decrease by number of loss events int _avgNAKNum { 0 }; // average number of NAKs per congestion int _decreaseCount { 0 }; // number of decreases in a congestion epoch + + + bool _delayedDecrease { false }; + std::random_device _rd; + std::mt19937 _generator; + std::uniform_int_distribution<> _distribution; }; }