From ba36954c6c7ab8394432f8527d9b8d23a2138c70 Mon Sep 17 00:00:00 2001 From: Yat Ho Date: Sat, 21 Oct 2023 00:23:00 +0800 Subject: [PATCH] fix: only consider piece data in bandwidth limit (#6082) (#6134) * fix: only consider piece data in bandwidth limit * refactor: remove unused `tr_bandwidth::clamp()` signature (cherry picked from commit 43aff088d898974f13d621e0203d75803891054c) --- libtransmission/bandwidth.cc | 31 ++----------------------------- libtransmission/bandwidth.h | 7 +------ 2 files changed, 3 insertions(+), 35 deletions(-) diff --git a/libtransmission/bandwidth.cc b/libtransmission/bandwidth.cc index d43242160..6e125d94b 100644 --- a/libtransmission/bandwidth.cc +++ b/libtransmission/bandwidth.cc @@ -259,45 +259,18 @@ void tr_bandwidth::allocate(unsigned int period_msec) // --- -size_t tr_bandwidth::clamp(uint64_t now, tr_direction dir, size_t byte_count) const +size_t tr_bandwidth::clamp(tr_direction const dir, size_t byte_count) const noexcept { TR_ASSERT(tr_isDirection(dir)); if (this->band_[dir].is_limited_) { byte_count = std::min(byte_count, this->band_[dir].bytes_left_); - - /* if we're getting close to exceeding the speed limit, - * clamp down harder on the bytes available */ - if (byte_count > 0) - { - if (now == 0) - { - now = tr_time_msec(); - } - - auto const current = this->getRawSpeedBytesPerSecond(now, dir); - auto const desired = this->getDesiredSpeedBytesPerSecond(dir); - auto const r = desired >= 1 ? static_cast(current) / desired : 0.0; - - if (r > 1.0) - { - byte_count = 0; // none left - } - else if (r > 0.9) - { - byte_count -= (byte_count / 5U); // cap at 80% - } - else if (r > 0.8) - { - byte_count -= (byte_count / 10U); // cap at 90% - } - } } if (this->parent_ != nullptr && this->band_[dir].honor_parent_limits_ && byte_count > 0) { - byte_count = this->parent_->clamp(now, dir, byte_count); + byte_count = this->parent_->clamp(dir, byte_count); } return byte_count; diff --git a/libtransmission/bandwidth.h b/libtransmission/bandwidth.h index 85eed3914..9e1c9f1b1 100644 --- a/libtransmission/bandwidth.h +++ b/libtransmission/bandwidth.h @@ -132,10 +132,7 @@ public: /** * @brief clamps `byte_count` down to a number that this bandwidth will allow to be consumed */ - [[nodiscard]] size_t clamp(tr_direction dir, size_t byte_count) const noexcept - { - return this->clamp(0, dir, byte_count); - } + [[nodiscard]] size_t clamp(tr_direction dir, size_t byte_count) const noexcept; /** @brief Get the raw total of bytes read or sent by this bandwidth subtree. */ [[nodiscard]] auto getRawSpeedBytesPerSecond(uint64_t const now, tr_direction const dir) const @@ -262,8 +259,6 @@ private: static void notifyBandwidthConsumedBytes(uint64_t now, RateControl* r, size_t size); - [[nodiscard]] size_t clamp(uint64_t now, tr_direction dir, size_t byte_count) const; - static void phaseOne(std::vector& peers, tr_direction dir); void allocateBandwidth(