|
@@ -134,14 +134,17 @@ RequestGroupMan::~RequestGroupMan() { openedFileCounter_->deactivate(); }
|
|
|
|
|
|
bool RequestGroupMan::setupOptimizeConcurrentDownloads(void)
|
|
|
{
|
|
|
- optimizeConcurrentDownloads_ = option_->getAsBool(PREF_OPTIMIZE_CONCURRENT_DOWNLOADS);
|
|
|
- if (optimizeConcurrentDownloads_) {
|
|
|
- if (option_->defined(PREF_OPTIMIZE_CONCURRENT_DOWNLOADS_COEFFA)) {
|
|
|
- optimizeConcurrentDownloadsCoeffA_ = std::stod(option_->get(PREF_OPTIMIZE_CONCURRENT_DOWNLOADS_COEFFA));
|
|
|
- optimizeConcurrentDownloadsCoeffB_ = std::stod(option_->get(PREF_OPTIMIZE_CONCURRENT_DOWNLOADS_COEFFB));
|
|
|
- }
|
|
|
+ optimizeConcurrentDownloads_ =
|
|
|
+ option_->getAsBool(PREF_OPTIMIZE_CONCURRENT_DOWNLOADS);
|
|
|
+ if (optimizeConcurrentDownloads_) {
|
|
|
+ if (option_->defined(PREF_OPTIMIZE_CONCURRENT_DOWNLOADS_COEFFA)) {
|
|
|
+ optimizeConcurrentDownloadsCoeffA_ =
|
|
|
+ std::stod(option_->get(PREF_OPTIMIZE_CONCURRENT_DOWNLOADS_COEFFA));
|
|
|
+ optimizeConcurrentDownloadsCoeffB_ =
|
|
|
+ std::stod(option_->get(PREF_OPTIMIZE_CONCURRENT_DOWNLOADS_COEFFB));
|
|
|
}
|
|
|
- return optimizeConcurrentDownloads_;
|
|
|
+ }
|
|
|
+ return optimizeConcurrentDownloads_;
|
|
|
}
|
|
|
|
|
|
bool RequestGroupMan::downloadFinished()
|
|
@@ -493,7 +496,9 @@ void RequestGroupMan::fillRequestGroupFromReserver(DownloadEngine* e)
|
|
|
{
|
|
|
removeStoppedGroup(e);
|
|
|
|
|
|
- int maxConcurrentDownloads = optimizeConcurrentDownloads_ ? optimizeConcurrentDownloads() : maxConcurrentDownloads_;
|
|
|
+ int maxConcurrentDownloads = optimizeConcurrentDownloads_
|
|
|
+ ? optimizeConcurrentDownloads()
|
|
|
+ : maxConcurrentDownloads_;
|
|
|
|
|
|
if (static_cast<size_t>(maxConcurrentDownloads) <= numActive_) {
|
|
|
return;
|
|
@@ -1026,7 +1031,6 @@ void RequestGroupMan::decreaseNumActive()
|
|
|
--numActive_;
|
|
|
}
|
|
|
|
|
|
-
|
|
|
int RequestGroupMan::optimizeConcurrentDownloads()
|
|
|
{
|
|
|
// gauge the current speed
|
|
@@ -1036,14 +1040,19 @@ int RequestGroupMan::optimizeConcurrentDownloads()
|
|
|
if (currentSpeed >= optimizationSpeed_) {
|
|
|
optimizationSpeed_ = currentSpeed;
|
|
|
optimizationSpeedTimer_ = now;
|
|
|
- } else if (std::chrono::duration_cast<std::chrono::seconds>(optimizationSpeedTimer_.difference(now)) >= 5_s) {
|
|
|
- // we keep using the reference speed for minimum 5 seconds so reset the timer
|
|
|
+ }
|
|
|
+ else if (std::chrono::duration_cast<std::chrono::seconds>(
|
|
|
+ optimizationSpeedTimer_.difference(now)) >= 5_s) {
|
|
|
+ // we keep using the reference speed for minimum 5 seconds so reset the
|
|
|
+ // timer
|
|
|
optimizationSpeedTimer_ = now;
|
|
|
|
|
|
- // keep the reference speed as long as the speed tends to augment or to maintain itself within 10%
|
|
|
+ // keep the reference speed as long as the speed tends to augment or to
|
|
|
+ // maintain itself within 10%
|
|
|
if (currentSpeed >= 1.1 * getNetStat().calculateNewestDownloadSpeed(5)) {
|
|
|
- // else assume a possible congestion and record a new optimization speed by dichotomy
|
|
|
- optimizationSpeed_ = (optimizationSpeed_ + currentSpeed)/2.;
|
|
|
+ // else assume a possible congestion and record a new optimization speed
|
|
|
+ // by dichotomy
|
|
|
+ optimizationSpeed_ = (optimizationSpeed_ + currentSpeed) / 2.;
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -1052,22 +1061,25 @@ int RequestGroupMan::optimizeConcurrentDownloads()
|
|
|
}
|
|
|
|
|
|
// apply the rule
|
|
|
- if ((maxOverallDownloadSpeedLimit_ > 0) && (optimizationSpeed_ > maxOverallDownloadSpeedLimit_)) {
|
|
|
+ if ((maxOverallDownloadSpeedLimit_ > 0) &&
|
|
|
+ (optimizationSpeed_ > maxOverallDownloadSpeedLimit_)) {
|
|
|
optimizationSpeed_ = maxOverallDownloadSpeedLimit_;
|
|
|
}
|
|
|
- int maxConcurrentDownloads = ceil(
|
|
|
- optimizeConcurrentDownloadsCoeffA_
|
|
|
- + optimizeConcurrentDownloadsCoeffB_ * log10(optimizationSpeed_ * 8. / 1000000.)
|
|
|
- );
|
|
|
+ int maxConcurrentDownloads =
|
|
|
+ ceil(optimizeConcurrentDownloadsCoeffA_ +
|
|
|
+ optimizeConcurrentDownloadsCoeffB_ *
|
|
|
+ log10(optimizationSpeed_ * 8. / 1000000.));
|
|
|
|
|
|
// bring the value in bound between 1 and the defined maximum
|
|
|
- maxConcurrentDownloads = std::min(std::max(1, maxConcurrentDownloads), maxConcurrentDownloads_);
|
|
|
-
|
|
|
- A2_LOG_DEBUG
|
|
|
- (fmt("Max concurrent downloads optimized at %d (%lu currently active) "
|
|
|
- "[optimization speed %sB/s, current speed %sB/s]",
|
|
|
- maxConcurrentDownloads, numActive_, util::abbrevSize(optimizationSpeed_).c_str(),
|
|
|
- util::abbrevSize(currentSpeed).c_str()));
|
|
|
+ maxConcurrentDownloads =
|
|
|
+ std::min(std::max(1, maxConcurrentDownloads), maxConcurrentDownloads_);
|
|
|
+
|
|
|
+ A2_LOG_DEBUG(
|
|
|
+ fmt("Max concurrent downloads optimized at %d (%lu currently active) "
|
|
|
+ "[optimization speed %sB/s, current speed %sB/s]",
|
|
|
+ maxConcurrentDownloads, numActive_,
|
|
|
+ util::abbrevSize(optimizationSpeed_).c_str(),
|
|
|
+ util::abbrevSize(currentSpeed).c_str()));
|
|
|
|
|
|
return maxConcurrentDownloads;
|
|
|
}
|