* fix: only consider piece data in bandwidth limit
* refactor: remove unused `tr_bandwidth::clamp()` signature
(cherry picked from commit 43aff088d8
)
This commit is contained in:
parent
cf6691acca
commit
ba36954c6c
|
@ -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<double>(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;
|
||||
|
|
|
@ -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<tr_peerIo*>& peers, tr_direction dir);
|
||||
|
||||
void allocateBandwidth(
|
||||
|
|
Loading…
Reference in New Issue