summaryrefslogtreecommitdiff
path: root/src/RequestGroupMan.cc
diff options
context:
space:
mode:
authorTatsuhiro Tsujikawa <tatsuhiro.t@gmail.com>2016-03-26 00:35:16 +0900
committerTatsuhiro Tsujikawa <tatsuhiro.t@gmail.com>2016-03-26 00:35:16 +0900
commita7cd943a06b1a5ff4515b57060b84037f8d01f9f (patch)
treef99947cca1090cf4f6a3ac6b369ebe74dc9c13eb /src/RequestGroupMan.cc
parent2a8522f6a5d14fa3a1493abc1aa80160feab4c99 (diff)
clang-format
Diffstat (limited to 'src/RequestGroupMan.cc')
-rw-r--r--src/RequestGroupMan.cc64
1 files changed, 38 insertions, 26 deletions
diff --git a/src/RequestGroupMan.cc b/src/RequestGroupMan.cc
index 824e1ea2..5ca6f2b2 100644
--- a/src/RequestGroupMan.cc
+++ b/src/RequestGroupMan.cc
@@ -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;
}