From 7858b6b0cd2cc3c52eafed980598905ba41a8816 Mon Sep 17 00:00:00 2001 From: Stephen Birarda Date: Mon, 14 Mar 2016 15:02:01 -0700 Subject: [PATCH] fix for slow start initial value with new randomization --- libraries/networking/src/udt/CongestionControl.cpp | 7 +++---- libraries/networking/src/udt/CongestionControl.h | 9 +++++++-- libraries/networking/src/udt/Connection.cpp | 7 +++++-- 3 files changed, 15 insertions(+), 8 deletions(-) diff --git a/libraries/networking/src/udt/CongestionControl.cpp b/libraries/networking/src/udt/CongestionControl.cpp index c1feae3911..0f8a9f24f6 100644 --- a/libraries/networking/src/udt/CongestionControl.cpp +++ b/libraries/networking/src/udt/CongestionControl.cpp @@ -34,7 +34,6 @@ void CongestionControl::setPacketSendPeriod(double newSendPeriod) { } DefaultCC::DefaultCC() : - _slowStartLastAck(_sendCurrSeqNum), _lastDecreaseMaxSeq(SequenceNumber {SequenceNumber::MAX }) { _mss = udt::MAX_PACKET_SIZE_WITH_UDP_HEADER; @@ -63,11 +62,11 @@ void DefaultCC::onACK(SequenceNumber ackNum) { if (_slowStart) { // we are in slow start phase - increase the congestion window size by the number of packets just ACKed - _congestionWindowSize += seqlen(_slowStartLastAck, ackNum); + _congestionWindowSize += seqlen(_slowStartLastACK, ackNum); // update the last ACK - _slowStartLastAck = ackNum; - + _slowStartLastACK = ackNum; + // check if we can get out of slow start (is our new congestion window size bigger than the max) if (_congestionWindowSize > _maxCongestionWindowSize) { _slowStart = false; diff --git a/libraries/networking/src/udt/CongestionControl.h b/libraries/networking/src/udt/CongestionControl.h index fa1bf73ecf..5fd784cc20 100644 --- a/libraries/networking/src/udt/CongestionControl.h +++ b/libraries/networking/src/udt/CongestionControl.h @@ -50,6 +50,7 @@ protected: void setMaxCongestionWindowSize(int window) { _maxCongestionWindowSize = window; } void setBandwidth(int bandwidth) { _bandwidth = bandwidth; } void setMaxBandwidth(int maxBandwidth) { _maxBandwidth = maxBandwidth; } + virtual void setInitialSendSequenceNumber(SequenceNumber seqNum) = 0; void setSendCurrentSequenceNumber(SequenceNumber seqNum) { _sendCurrSeqNum = seqNum; } void setReceiveRate(int rate) { _receiveRate = rate; } void setRTT(int rtt) { _rtt = rtt; } @@ -104,14 +105,18 @@ public: virtual void onACK(SequenceNumber ackNum); virtual void onLoss(SequenceNumber rangeStart, SequenceNumber rangeEnd); virtual void onTimeout(); - + +protected: + virtual void setInitialSendSequenceNumber(SequenceNumber seqNum) { _slowStartLastACK = seqNum; } + private: void stopSlowStart(); // stops the slow start on loss or timeout p_high_resolution_clock::time_point _lastRCTime = p_high_resolution_clock::now(); // last rate increase time bool _slowStart { true }; // if in slow start phase - SequenceNumber _slowStartLastAck; // last ACKed seq num + bool _hasSetSlowStartACK { false }; // flag to signal if slow start ACK has been set with handshake sequence number + SequenceNumber _slowStartLastACK; // last ACKed seq num from previous slow start check bool _loss { false }; // if loss happened since last rate increase SequenceNumber _lastDecreaseMaxSeq; // max pkt seq num sent out when last decrease happened double _lastDecreasePeriod { 1 }; // value of _packetSendPeriod when last decrease happened diff --git a/libraries/networking/src/udt/Connection.cpp b/libraries/networking/src/udt/Connection.cpp index e6a15aa6a0..95afbedb86 100644 --- a/libraries/networking/src/udt/Connection.cpp +++ b/libraries/networking/src/udt/Connection.cpp @@ -104,6 +104,9 @@ SendQueue& Connection::getSendQueue() { _sendQueue->setSyncInterval(_synInterval); _sendQueue->setEstimatedTimeout(estimatedTimeout()); _sendQueue->setFlowWindowSize(std::min(_flowWindowSize, (int) _congestionControl->_congestionWindowSize)); + + // give the randomized sequence number to the congestion control object + _congestionControl->setInitialSendSequenceNumber(_sendQueue->getCurrentSequenceNumber()); } return *_sendQueue; @@ -282,7 +285,7 @@ void Connection::sendACK(bool wasCausedBySyncTimeout) { // grab the up to date packet receive speed and estimated bandwidth int32_t packetReceiveSpeed = _receiveWindow.getPacketReceiveSpeed(); int32_t estimatedBandwidth = _receiveWindow.getEstimatedBandwidth(); - + // update those values in our connection stats _stats.recordReceiveRate(packetReceiveSpeed); _stats.recordEstimatedBandwidth(estimatedBandwidth); @@ -541,7 +544,7 @@ void Connection::processACK(std::unique_ptr controlPacket) { // read the ACK sub-sequence number SequenceNumber currentACKSubSequenceNumber; controlPacket->readPrimitive(¤tACKSubSequenceNumber); - + // Check if we need send an ACK2 for this ACK // This will be the case if it has been longer than the sync interval OR // it looks like they haven't received our ACK2 for this ACK