From 7f8c993bd7726090db7fea914615d7f325ea169e Mon Sep 17 00:00:00 2001 From: Stephen Birarda Date: Fri, 31 Jul 2015 19:42:24 -0700 Subject: [PATCH] make send rate actually send rate, don't sync as sender --- libraries/networking/src/udt/Connection.cpp | 27 +++++++++++-------- libraries/networking/src/udt/Connection.h | 2 ++ .../networking/src/udt/ConnectionStats.cpp | 5 ++++ .../networking/src/udt/ConnectionStats.h | 2 ++ libraries/networking/src/udt/SendQueue.cpp | 2 ++ tools/udt-test/src/UDTTest.cpp | 2 +- 6 files changed, 28 insertions(+), 12 deletions(-) diff --git a/libraries/networking/src/udt/Connection.cpp b/libraries/networking/src/udt/Connection.cpp index 8ad7259347..c27d5d5bed 100644 --- a/libraries/networking/src/udt/Connection.cpp +++ b/libraries/networking/src/udt/Connection.cpp @@ -72,16 +72,18 @@ void Connection::sendReliablePacket(unique_ptr packet) { } void Connection::sync() { - // we send out a periodic ACK every rate control interval - sendACK(); - - // check if we need to re-transmit a loss list - // we do this if it has been longer than the current nakInterval since we last sent - auto now = high_resolution_clock::now(); - - if (duration_cast(now - _lastNAKTime).count() >= _nakInterval) { - // Send a timeout NAK packet - sendTimeoutNAK(); + if (_hasReceivedFirstPacket) { + // we send out a periodic ACK every rate control interval + sendACK(); + + // check if we need to re-transmit a loss list + // we do this if it has been longer than the current nakInterval since we last sent + auto now = high_resolution_clock::now(); + + if (duration_cast(now - _lastNAKTime).count() >= _nakInterval) { + // Send a timeout NAK packet + sendTimeoutNAK(); + } } } @@ -265,6 +267,9 @@ SequenceNumber Connection::nextACK() const { } bool Connection::processReceivedSequenceNumber(SequenceNumber sequenceNumber, int packetSize, int payloadSize) { + + _hasReceivedFirstPacket = true; + // check if this is a packet pair we should estimate bandwidth from, or just a regular packet if (((uint32_t) sequenceNumber & 0xF) == 0) { _receiveWindow.onProbePair1Arrival(); @@ -424,7 +429,7 @@ void Connection::processACK(std::unique_ptr controlPacket) { static const int EMWA_ALPHA_NUMERATOR = 8; // record these samples in connection stats - _stats.recordReceiveRate(receiveRate); + _stats.recordSendRate(receiveRate); _stats.recordEstimatedBandwidth(bandwidth); _deliveryRate = (_deliveryRate * (EMWA_ALPHA_NUMERATOR - 1) + receiveRate) / EMWA_ALPHA_NUMERATOR; diff --git a/libraries/networking/src/udt/Connection.h b/libraries/networking/src/udt/Connection.h index dd86f9bc5b..0876a814e3 100644 --- a/libraries/networking/src/udt/Connection.h +++ b/libraries/networking/src/udt/Connection.h @@ -86,6 +86,8 @@ private: int _minNAKInterval { 100000 }; // NAK timeout interval lower bound, default of 100ms std::chrono::high_resolution_clock::time_point _lastNAKTime; + bool _hasReceivedFirstPacket { false }; + LossList _lossList; // List of all missing packets SequenceNumber _lastReceivedSequenceNumber; // The largest sequence number received from the peer SequenceNumber _lastReceivedACK; // The last ACK received diff --git a/libraries/networking/src/udt/ConnectionStats.cpp b/libraries/networking/src/udt/ConnectionStats.cpp index 62497ab496..1f8308bf5d 100644 --- a/libraries/networking/src/udt/ConnectionStats.cpp +++ b/libraries/networking/src/udt/ConnectionStats.cpp @@ -139,6 +139,11 @@ void ConnectionStats::recordDuplicates() { static const double EWMA_CURRENT_SAMPLE_WEIGHT = 0.125; static const double EWMA_PREVIOUS_SAMPLES_WEIGHT = 1 - 0.125; +void ConnectionStats::recordSendRate(int sample) { + _currentSample.sendRate = sample; + _total.sendRate = (_total.sendRate * EWMA_PREVIOUS_SAMPLES_WEIGHT) + (sample * EWMA_CURRENT_SAMPLE_WEIGHT); +} + void ConnectionStats::recordReceiveRate(int sample) { _currentSample.receiveRate = sample; _total.receiveRate = (_total.receiveRate * EWMA_PREVIOUS_SAMPLES_WEIGHT) + (sample * EWMA_CURRENT_SAMPLE_WEIGHT); diff --git a/libraries/networking/src/udt/ConnectionStats.h b/libraries/networking/src/udt/ConnectionStats.h index f4b912ace5..27d8bbd7a1 100644 --- a/libraries/networking/src/udt/ConnectionStats.h +++ b/libraries/networking/src/udt/ConnectionStats.h @@ -52,6 +52,7 @@ public: int duplicates { 0 }; // the following stats are trailing averages in the result, not totals + int sendRate { 0 }; int receiveRate { 0 }; int estimatedBandwith { 0 }; int rtt { 0 }; @@ -84,6 +85,7 @@ public: void recordRetransmission(); void recordDuplicates(); + void recordSendRate(int sample); void recordReceiveRate(int sample); void recordEstimatedBandwidth(int sample); void recordRTT(int sample); diff --git a/libraries/networking/src/udt/SendQueue.cpp b/libraries/networking/src/udt/SendQueue.cpp index f271a1c685..508e674278 100644 --- a/libraries/networking/src/udt/SendQueue.cpp +++ b/libraries/networking/src/udt/SendQueue.cpp @@ -108,6 +108,8 @@ void SendQueue::overrideNAKListFromPacket(ControlPacket& packet) { packet.readPrimitive(&first); packet.readPrimitive(&second); + qDebug() << "NAK" << (uint32_t) first << (uint32_t) second; + if (first == second) { _naks.append(first); } else { diff --git a/tools/udt-test/src/UDTTest.cpp b/tools/udt-test/src/UDTTest.cpp index 97de033dfe..780e035a89 100644 --- a/tools/udt-test/src/UDTTest.cpp +++ b/tools/udt-test/src/UDTTest.cpp @@ -222,7 +222,7 @@ void UDTTest::sampleStats() { // setup a list of left justified values QStringList values { - QString::number(stats.receiveRate).leftJustified(STATS_TABLE_HEADERS[++headerIndex].size()), + QString::number(stats.sendRate).leftJustified(STATS_TABLE_HEADERS[++headerIndex].size()), QString::number(stats.rtt / USECS_PER_MSEC).leftJustified(STATS_TABLE_HEADERS[++headerIndex].size()), QString::number(stats.congestionWindowSize).leftJustified(STATS_TABLE_HEADERS[++headerIndex].size()), QString::number(stats.packetSendPeriod).leftJustified(STATS_TABLE_HEADERS[++headerIndex].size()),