diff --git a/quic/QuicConstants.h b/quic/QuicConstants.h index 56bf2c04a..0ea00a538 100644 --- a/quic/QuicConstants.h +++ b/quic/QuicConstants.h @@ -229,6 +229,8 @@ constexpr std::chrono::microseconds::rep kPersistentCongestionThreshold = 3; constexpr std::chrono::microseconds::rep kPersistentCongestionPeriodFactor = (((std::chrono::microseconds::rep)1 << kPersistentCongestionThreshold) - 1); enum class CongestionControlType : uint8_t { Cubic, NewReno, Copa, BBR, None }; +// This is an approximation of a small enough number for cwnd to be blocked. +constexpr size_t kBlockedSizeBytes = 20; constexpr uint64_t kInitCwndInMss = 10; constexpr uint64_t kMinCwndInMss = 2; diff --git a/quic/api/QuicTransportFunctions.cpp b/quic/api/QuicTransportFunctions.cpp index 7580c1626..ed723074a 100644 --- a/quic/api/QuicTransportFunctions.cpp +++ b/quic/api/QuicTransportFunctions.cpp @@ -348,6 +348,14 @@ void updateConnection( conn.lossState.largestSent = std::max(conn.lossState.largestSent, packetNum); if (conn.congestionController && !pureAck) { conn.congestionController->onPacketSent(pkt); + // An approximation of the app being blocked. The app + // technically might not have bytes to write. + auto writableBytes = conn.congestionController->getWritableBytes(); + bool cwndBlocked = writableBytes < kBlockedSizeBytes; + if (cwndBlocked) { + auto cwndBytes = conn.congestionController->getCongestionWindow(); + QUIC_TRACE(cwnd_may_block, conn, writableBytes, cwndBytes); + } } if (pkt.isHandshake) { ++conn.outstandingHandshakePacketsCount; diff --git a/quic/api/test/QuicTransportTest.cpp b/quic/api/test/QuicTransportTest.cpp index 0ad4bf0ce..29593152c 100644 --- a/quic/api/test/QuicTransportTest.cpp +++ b/quic/api/test/QuicTransportTest.cpp @@ -358,11 +358,8 @@ TEST_F(QuicTransportTest, WriteDataWithProbing) { loopForWrites(); // Pending numProbePackets is cleared: EXPECT_EQ(0, conn.pendingEvents.numProbePackets); - // getWritableBytes should be called with the same times as write - // getWritableBytes should happen exact one less time than socket write and - // onPacketSent on write path and one more time in the updateWriteLooper. - EXPECT_EQ(socketWriteCounter, getWritableBytesCounter); - EXPECT_EQ(onPacketSentCounter, getWritableBytesCounter); + // both write and onPacketSent will inquire getWritableBytes + EXPECT_EQ(onPacketSentCounter + socketWriteCounter, getWritableBytesCounter); transport_->close(folly::none); } diff --git a/quic/congestion_control/QuicCubic.cpp b/quic/congestion_control/QuicCubic.cpp index 5c7adddd0..29f5516c0 100644 --- a/quic/congestion_control/QuicCubic.cpp +++ b/quic/congestion_control/QuicCubic.cpp @@ -10,13 +10,6 @@ #include #include -namespace { - -// This is an approximation of a small enough number -// for cwnd to be blocked. -constexpr size_t kBlockedSizeBytes = 20; -} - namespace quic { Cubic::Cubic( @@ -89,17 +82,6 @@ void Cubic::onPacketSent(const OutstandingPacket& packet) { LocalErrorCode::INFLIGHT_BYTES_OVERFLOW); } inflightBytes_ += packet.encodedSize; - // An approximation of the app being blocked. The app - // technically might not have bytes to write. - bool cwndBlocked = getWritableBytes() < kBlockedSizeBytes; - if (cwndBlocked) { - QUIC_TRACE( - cubic_may_block, - conn_, - cubicStateToString(state_).data(), - cwndBytes_, - inflightBytes_); - } } void Cubic::onPacketLoss(const LossEvent& loss) {