diff options
| author | oliviercommelarbre <oliviercommelarbre@gmail.com> | 2016-02-11 00:04:49 +0100 |
|---|---|---|
| committer | Tatsuhiro Tsujikawa <tatsuhiro.t@gmail.com> | 2016-03-16 21:22:49 +0900 |
| commit | 9e05371fb6a70d7d5e9d49db31b879e79c1b56e7 (patch) | |
| tree | de5e25d3a5b89c932f897e6c4905ba7b507337ec /src/SpeedCalc.cc | |
| parent | f0f1b8ef47c391550ff99982f1cad3dd4e1d410d (diff) | |
Added support for a dynamic management of the number of concurrent downloads as a function of the overall bandwidth observed
Diffstat (limited to 'src/SpeedCalc.cc')
| -rw-r--r-- | src/SpeedCalc.cc | 27 |
1 files changed, 26 insertions, 1 deletions
diff --git a/src/SpeedCalc.cc b/src/SpeedCalc.cc index a2bf4ee9..2c49c9ef 100644 --- a/src/SpeedCalc.cc +++ b/src/SpeedCalc.cc @@ -42,7 +42,7 @@ namespace aria2 { namespace { -constexpr auto WINDOW_TIME = 15_s; +constexpr auto WINDOW_TIME = 10_s; } // namespace SpeedCalc::SpeedCalc() : accumulatedLength_(0), bytesWindow_(0), maxSpeed_(0) {} @@ -84,6 +84,31 @@ int SpeedCalc::calculateSpeed() return speed; } +int SpeedCalc::calculateNewestSpeed(int seconds) +{ + const auto& now = global::wallclock(); + removeStaleTimeSlot(now); + + int64_t bytesCount(0); + auto it = timeSlots_.rbegin(); + while (it != timeSlots_.rend()) { + if (it->first.difference(now) > seconds * 1_s) { + break; + } + bytesCount += (*it++).second; + } + if (it == timeSlots_.rbegin()) { + return 0; + } + + auto elapsed = std::chrono::duration_cast<std::chrono::milliseconds>( + (*--it).first.difference(now)).count(); + if (elapsed <= 0) { + elapsed = 1; + } + return bytesCount * (1000. / elapsed); +} + void SpeedCalc::update(size_t bytes) { const auto& now = global::wallclock(); |
