summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/FillRequestGroupCommand.cc7
-rw-r--r--src/OptionHandlerFactory.cc8
-rw-r--r--src/OptionHandlerImpl.cc37
-rw-r--r--src/OptionHandlerImpl.h1
-rw-r--r--src/RequestGroupMan.cc64
-rw-r--r--src/RpcMethodImpl.cc2
-rw-r--r--src/prefs.cc9
7 files changed, 73 insertions, 55 deletions
diff --git a/src/FillRequestGroupCommand.cc b/src/FillRequestGroupCommand.cc
index 6ec4151b..421360eb 100644
--- a/src/FillRequestGroupCommand.cc
+++ b/src/FillRequestGroupCommand.cc
@@ -86,9 +86,10 @@ bool FillRequestGroupCommand::execute()
// if we use the optimize-concurrent-download option
if (rgman->getOptimizeConcurrentDownloads()) {
const auto& now = global::wallclock();
- if (std::chrono::duration_cast<std::chrono::seconds>(lastExecTime.difference(now)) >= 1_s) {
- lastExecTime = now;
- rgman->requestQueueCheck();
+ if (std::chrono::duration_cast<std::chrono::seconds>(
+ lastExecTime.difference(now)) >= 1_s) {
+ lastExecTime = now;
+ rgman->requestQueueCheck();
}
}
diff --git a/src/OptionHandlerFactory.cc b/src/OptionHandlerFactory.cc
index f2d3de87..205dfa4c 100644
--- a/src/OptionHandlerFactory.cc
+++ b/src/OptionHandlerFactory.cc
@@ -562,11 +562,9 @@ std::vector<OptionHandler*> OptionHandlerFactory::createOptionHandlers()
handlers.push_back(op);
}
{
- OptionHandler* op(new OptimizeConcurrentDownloadsOptionHandler
- (PREF_OPTIMIZE_CONCURRENT_DOWNLOADS,
- TEXT_OPTIMIZE_CONCURRENT_DOWNLOADS,
- A2_V_FALSE,
- OptionHandler::OPT_ARG));
+ OptionHandler* op(new OptimizeConcurrentDownloadsOptionHandler(
+ PREF_OPTIMIZE_CONCURRENT_DOWNLOADS, TEXT_OPTIMIZE_CONCURRENT_DOWNLOADS,
+ A2_V_FALSE, OptionHandler::OPT_ARG));
op->addTag(TAG_ADVANCED);
op->setChangeGlobalOption(true);
handlers.push_back(op);
diff --git a/src/OptionHandlerImpl.cc b/src/OptionHandlerImpl.cc
index 600564cb..6dec8503 100644
--- a/src/OptionHandlerImpl.cc
+++ b/src/OptionHandlerImpl.cc
@@ -587,15 +587,18 @@ std::string PrioritizePieceOptionHandler::createPossibleValuesString() const
return "head[=SIZE], tail[=SIZE]";
}
-OptimizeConcurrentDownloadsOptionHandler::OptimizeConcurrentDownloadsOptionHandler(
- PrefPtr pref, const char* description, const std::string& defaultValue, char shortName)
+OptimizeConcurrentDownloadsOptionHandler::
+ OptimizeConcurrentDownloadsOptionHandler(PrefPtr pref,
+ const char* description,
+ const std::string& defaultValue,
+ char shortName)
: AbstractOptionHandler(pref, description, defaultValue,
OptionHandler::OPT_ARG, shortName)
{
}
-void OptimizeConcurrentDownloadsOptionHandler::parseArg(Option& option,
- const std::string& optarg) const
+void OptimizeConcurrentDownloadsOptionHandler::parseArg(
+ Option& option, const std::string& optarg) const
{
if (optarg == "true" || optarg.empty()) {
option.put(pref_, A2_V_TRUE);
@@ -606,28 +609,29 @@ void OptimizeConcurrentDownloadsOptionHandler::parseArg(Option& option,
else {
auto p = util::divide(std::begin(optarg), std::end(optarg), ':');
- std::string coeff_b(p.second.first,p.second.second);
- if(coeff_b.empty()) {
+ std::string coeff_b(p.second.first, p.second.second);
+ if (coeff_b.empty()) {
std::string msg = pref_->k;
msg += " ";
- msg += _("must be either 'true', 'false' or a pair numeric coefficients A and B under the form 'A:B'.");
+ msg += _("must be either 'true', 'false' or a pair numeric coefficients "
+ "A and B under the form 'A:B'.");
throw DL_ABORT_EX(msg);
}
- std::string coeff_a(p.first.first,p.first.second);
+ std::string coeff_a(p.first.first, p.first.second);
-
- PrefPtr pref=PREF_OPTIMIZE_CONCURRENT_DOWNLOADS_COEFFA;
- std::string *sptr = &coeff_a;
- for(;;) {
+ PrefPtr pref = PREF_OPTIMIZE_CONCURRENT_DOWNLOADS_COEFFA;
+ std::string* sptr = &coeff_a;
+ for (;;) {
try {
double dbl = std::stod(*sptr);
- } catch(std::invalid_argument & ex) {
+ }
+ catch (std::invalid_argument& ex) {
throw DL_ABORT_EX(fmt("Bad number '%s'", sptr->c_str()));
}
- option.put(pref,*sptr);
+ option.put(pref, *sptr);
- if(pref == PREF_OPTIMIZE_CONCURRENT_DOWNLOADS_COEFFB) {
+ if (pref == PREF_OPTIMIZE_CONCURRENT_DOWNLOADS_COEFFB) {
break;
}
pref = PREF_OPTIMIZE_CONCURRENT_DOWNLOADS_COEFFB;
@@ -637,7 +641,8 @@ void OptimizeConcurrentDownloadsOptionHandler::parseArg(Option& option,
}
}
-std::string OptimizeConcurrentDownloadsOptionHandler::createPossibleValuesString() const
+std::string
+OptimizeConcurrentDownloadsOptionHandler::createPossibleValuesString() const
{
return "true, false, A:B";
}
diff --git a/src/OptionHandlerImpl.h b/src/OptionHandlerImpl.h
index a31ade77..f153a721 100644
--- a/src/OptionHandlerImpl.h
+++ b/src/OptionHandlerImpl.h
@@ -264,7 +264,6 @@ public:
virtual std::string createPossibleValuesString() const CXX11_OVERRIDE;
};
-
// This class is used to deprecate option and optionally handle its
// option value using replacing option.
class DeprecatedOptionHandler : public OptionHandler {
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;
}
diff --git a/src/RpcMethodImpl.cc b/src/RpcMethodImpl.cc
index 5d6e8202..a1c5770f 100644
--- a/src/RpcMethodImpl.cc
+++ b/src/RpcMethodImpl.cc
@@ -1596,7 +1596,7 @@ void changeGlobalOption(const Option& option, DownloadEngine* e)
option.getAsInt(PREF_MAX_CONCURRENT_DOWNLOADS));
e->getRequestGroupMan()->requestQueueCheck();
}
- if(option.defined(PREF_OPTIMIZE_CONCURRENT_DOWNLOADS)) {
+ if (option.defined(PREF_OPTIMIZE_CONCURRENT_DOWNLOADS)) {
e->getRequestGroupMan()->setupOptimizeConcurrentDownloads();
e->getRequestGroupMan()->requestQueueCheck();
}
diff --git a/src/prefs.cc b/src/prefs.cc
index 3206a31a..4eb2fc5c 100644
--- a/src/prefs.cc
+++ b/src/prefs.cc
@@ -217,11 +217,14 @@ PrefPtr PREF_DEFERRED_INPUT = makePref("deferred-input");
// value: 1*digit
PrefPtr PREF_MAX_CONCURRENT_DOWNLOADS = makePref("max-concurrent-downloads");
// value: true | false | A:B
-PrefPtr PREF_OPTIMIZE_CONCURRENT_DOWNLOADS = makePref("optimize-concurrent-downloads");
+PrefPtr PREF_OPTIMIZE_CONCURRENT_DOWNLOADS =
+ makePref("optimize-concurrent-downloads");
// values: 1*digit ['.' [ 1*digit ] ]
-PrefPtr PREF_OPTIMIZE_CONCURRENT_DOWNLOADS_COEFFA = makePref("optimize-concurrent-downloads-coeffA");
+PrefPtr PREF_OPTIMIZE_CONCURRENT_DOWNLOADS_COEFFA =
+ makePref("optimize-concurrent-downloads-coeffA");
// values: 1*digit ['.' [ 1*digit ] ]
-PrefPtr PREF_OPTIMIZE_CONCURRENT_DOWNLOADS_COEFFB = makePref("optimize-concurrent-downloads-coeffB");
+PrefPtr PREF_OPTIMIZE_CONCURRENT_DOWNLOADS_COEFFB =
+ makePref("optimize-concurrent-downloads-coeffB");
// value: true | false
PrefPtr PREF_FORCE_SEQUENTIAL = makePref("force-sequential");
// value: true | false