mirror of https://github.com/aria2/aria2
clang-format
parent
2a8522f6a5
commit
a7cd943a06
|
@ -86,9 +86,10 @@ bool FillRequestGroupCommand::execute()
|
||||||
// if we use the optimize-concurrent-download option
|
// if we use the optimize-concurrent-download option
|
||||||
if (rgman->getOptimizeConcurrentDownloads()) {
|
if (rgman->getOptimizeConcurrentDownloads()) {
|
||||||
const auto& now = global::wallclock();
|
const auto& now = global::wallclock();
|
||||||
if (std::chrono::duration_cast<std::chrono::seconds>(lastExecTime.difference(now)) >= 1_s) {
|
if (std::chrono::duration_cast<std::chrono::seconds>(
|
||||||
lastExecTime = now;
|
lastExecTime.difference(now)) >= 1_s) {
|
||||||
rgman->requestQueueCheck();
|
lastExecTime = now;
|
||||||
|
rgman->requestQueueCheck();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -562,11 +562,9 @@ std::vector<OptionHandler*> OptionHandlerFactory::createOptionHandlers()
|
||||||
handlers.push_back(op);
|
handlers.push_back(op);
|
||||||
}
|
}
|
||||||
{
|
{
|
||||||
OptionHandler* op(new OptimizeConcurrentDownloadsOptionHandler
|
OptionHandler* op(new OptimizeConcurrentDownloadsOptionHandler(
|
||||||
(PREF_OPTIMIZE_CONCURRENT_DOWNLOADS,
|
PREF_OPTIMIZE_CONCURRENT_DOWNLOADS, TEXT_OPTIMIZE_CONCURRENT_DOWNLOADS,
|
||||||
TEXT_OPTIMIZE_CONCURRENT_DOWNLOADS,
|
A2_V_FALSE, OptionHandler::OPT_ARG));
|
||||||
A2_V_FALSE,
|
|
||||||
OptionHandler::OPT_ARG));
|
|
||||||
op->addTag(TAG_ADVANCED);
|
op->addTag(TAG_ADVANCED);
|
||||||
op->setChangeGlobalOption(true);
|
op->setChangeGlobalOption(true);
|
||||||
handlers.push_back(op);
|
handlers.push_back(op);
|
||||||
|
|
|
@ -587,15 +587,18 @@ std::string PrioritizePieceOptionHandler::createPossibleValuesString() const
|
||||||
return "head[=SIZE], tail[=SIZE]";
|
return "head[=SIZE], tail[=SIZE]";
|
||||||
}
|
}
|
||||||
|
|
||||||
OptimizeConcurrentDownloadsOptionHandler::OptimizeConcurrentDownloadsOptionHandler(
|
OptimizeConcurrentDownloadsOptionHandler::
|
||||||
PrefPtr pref, const char* description, const std::string& defaultValue, char shortName)
|
OptimizeConcurrentDownloadsOptionHandler(PrefPtr pref,
|
||||||
|
const char* description,
|
||||||
|
const std::string& defaultValue,
|
||||||
|
char shortName)
|
||||||
: AbstractOptionHandler(pref, description, defaultValue,
|
: AbstractOptionHandler(pref, description, defaultValue,
|
||||||
OptionHandler::OPT_ARG, shortName)
|
OptionHandler::OPT_ARG, shortName)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
void OptimizeConcurrentDownloadsOptionHandler::parseArg(Option& option,
|
void OptimizeConcurrentDownloadsOptionHandler::parseArg(
|
||||||
const std::string& optarg) const
|
Option& option, const std::string& optarg) const
|
||||||
{
|
{
|
||||||
if (optarg == "true" || optarg.empty()) {
|
if (optarg == "true" || optarg.empty()) {
|
||||||
option.put(pref_, A2_V_TRUE);
|
option.put(pref_, A2_V_TRUE);
|
||||||
|
@ -606,28 +609,29 @@ void OptimizeConcurrentDownloadsOptionHandler::parseArg(Option& option,
|
||||||
else {
|
else {
|
||||||
auto p = util::divide(std::begin(optarg), std::end(optarg), ':');
|
auto p = util::divide(std::begin(optarg), std::end(optarg), ':');
|
||||||
|
|
||||||
std::string coeff_b(p.second.first,p.second.second);
|
std::string coeff_b(p.second.first, p.second.second);
|
||||||
if(coeff_b.empty()) {
|
if (coeff_b.empty()) {
|
||||||
std::string msg = pref_->k;
|
std::string msg = pref_->k;
|
||||||
msg += " ";
|
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);
|
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;
|
||||||
PrefPtr pref=PREF_OPTIMIZE_CONCURRENT_DOWNLOADS_COEFFA;
|
std::string* sptr = &coeff_a;
|
||||||
std::string *sptr = &coeff_a;
|
for (;;) {
|
||||||
for(;;) {
|
|
||||||
try {
|
try {
|
||||||
double dbl = std::stod(*sptr);
|
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()));
|
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;
|
break;
|
||||||
}
|
}
|
||||||
pref = PREF_OPTIMIZE_CONCURRENT_DOWNLOADS_COEFFB;
|
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";
|
return "true, false, A:B";
|
||||||
}
|
}
|
||||||
|
|
|
@ -264,7 +264,6 @@ public:
|
||||||
virtual std::string createPossibleValuesString() const CXX11_OVERRIDE;
|
virtual std::string createPossibleValuesString() const CXX11_OVERRIDE;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
// This class is used to deprecate option and optionally handle its
|
// This class is used to deprecate option and optionally handle its
|
||||||
// option value using replacing option.
|
// option value using replacing option.
|
||||||
class DeprecatedOptionHandler : public OptionHandler {
|
class DeprecatedOptionHandler : public OptionHandler {
|
||||||
|
|
|
@ -134,14 +134,17 @@ RequestGroupMan::~RequestGroupMan() { openedFileCounter_->deactivate(); }
|
||||||
|
|
||||||
bool RequestGroupMan::setupOptimizeConcurrentDownloads(void)
|
bool RequestGroupMan::setupOptimizeConcurrentDownloads(void)
|
||||||
{
|
{
|
||||||
optimizeConcurrentDownloads_ = option_->getAsBool(PREF_OPTIMIZE_CONCURRENT_DOWNLOADS);
|
optimizeConcurrentDownloads_ =
|
||||||
if (optimizeConcurrentDownloads_) {
|
option_->getAsBool(PREF_OPTIMIZE_CONCURRENT_DOWNLOADS);
|
||||||
if (option_->defined(PREF_OPTIMIZE_CONCURRENT_DOWNLOADS_COEFFA)) {
|
if (optimizeConcurrentDownloads_) {
|
||||||
optimizeConcurrentDownloadsCoeffA_ = std::stod(option_->get(PREF_OPTIMIZE_CONCURRENT_DOWNLOADS_COEFFA));
|
if (option_->defined(PREF_OPTIMIZE_CONCURRENT_DOWNLOADS_COEFFA)) {
|
||||||
optimizeConcurrentDownloadsCoeffB_ = std::stod(option_->get(PREF_OPTIMIZE_CONCURRENT_DOWNLOADS_COEFFB));
|
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()
|
bool RequestGroupMan::downloadFinished()
|
||||||
|
@ -493,7 +496,9 @@ void RequestGroupMan::fillRequestGroupFromReserver(DownloadEngine* e)
|
||||||
{
|
{
|
||||||
removeStoppedGroup(e);
|
removeStoppedGroup(e);
|
||||||
|
|
||||||
int maxConcurrentDownloads = optimizeConcurrentDownloads_ ? optimizeConcurrentDownloads() : maxConcurrentDownloads_;
|
int maxConcurrentDownloads = optimizeConcurrentDownloads_
|
||||||
|
? optimizeConcurrentDownloads()
|
||||||
|
: maxConcurrentDownloads_;
|
||||||
|
|
||||||
if (static_cast<size_t>(maxConcurrentDownloads) <= numActive_) {
|
if (static_cast<size_t>(maxConcurrentDownloads) <= numActive_) {
|
||||||
return;
|
return;
|
||||||
|
@ -1026,7 +1031,6 @@ void RequestGroupMan::decreaseNumActive()
|
||||||
--numActive_;
|
--numActive_;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
int RequestGroupMan::optimizeConcurrentDownloads()
|
int RequestGroupMan::optimizeConcurrentDownloads()
|
||||||
{
|
{
|
||||||
// gauge the current speed
|
// gauge the current speed
|
||||||
|
@ -1036,14 +1040,19 @@ int RequestGroupMan::optimizeConcurrentDownloads()
|
||||||
if (currentSpeed >= optimizationSpeed_) {
|
if (currentSpeed >= optimizationSpeed_) {
|
||||||
optimizationSpeed_ = currentSpeed;
|
optimizationSpeed_ = currentSpeed;
|
||||||
optimizationSpeedTimer_ = now;
|
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;
|
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)) {
|
if (currentSpeed >= 1.1 * getNetStat().calculateNewestDownloadSpeed(5)) {
|
||||||
// else assume a possible congestion and record a new optimization speed by dichotomy
|
// else assume a possible congestion and record a new optimization speed
|
||||||
optimizationSpeed_ = (optimizationSpeed_ + currentSpeed)/2.;
|
// by dichotomy
|
||||||
|
optimizationSpeed_ = (optimizationSpeed_ + currentSpeed) / 2.;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1052,22 +1061,25 @@ int RequestGroupMan::optimizeConcurrentDownloads()
|
||||||
}
|
}
|
||||||
|
|
||||||
// apply the rule
|
// apply the rule
|
||||||
if ((maxOverallDownloadSpeedLimit_ > 0) && (optimizationSpeed_ > maxOverallDownloadSpeedLimit_)) {
|
if ((maxOverallDownloadSpeedLimit_ > 0) &&
|
||||||
|
(optimizationSpeed_ > maxOverallDownloadSpeedLimit_)) {
|
||||||
optimizationSpeed_ = maxOverallDownloadSpeedLimit_;
|
optimizationSpeed_ = maxOverallDownloadSpeedLimit_;
|
||||||
}
|
}
|
||||||
int maxConcurrentDownloads = ceil(
|
int maxConcurrentDownloads =
|
||||||
optimizeConcurrentDownloadsCoeffA_
|
ceil(optimizeConcurrentDownloadsCoeffA_ +
|
||||||
+ optimizeConcurrentDownloadsCoeffB_ * log10(optimizationSpeed_ * 8. / 1000000.)
|
optimizeConcurrentDownloadsCoeffB_ *
|
||||||
);
|
log10(optimizationSpeed_ * 8. / 1000000.));
|
||||||
|
|
||||||
// bring the value in bound between 1 and the defined maximum
|
// bring the value in bound between 1 and the defined maximum
|
||||||
maxConcurrentDownloads = std::min(std::max(1, maxConcurrentDownloads), maxConcurrentDownloads_);
|
maxConcurrentDownloads =
|
||||||
|
std::min(std::max(1, maxConcurrentDownloads), maxConcurrentDownloads_);
|
||||||
|
|
||||||
A2_LOG_DEBUG
|
A2_LOG_DEBUG(
|
||||||
(fmt("Max concurrent downloads optimized at %d (%lu currently active) "
|
fmt("Max concurrent downloads optimized at %d (%lu currently active) "
|
||||||
"[optimization speed %sB/s, current speed %sB/s]",
|
"[optimization speed %sB/s, current speed %sB/s]",
|
||||||
maxConcurrentDownloads, numActive_, util::abbrevSize(optimizationSpeed_).c_str(),
|
maxConcurrentDownloads, numActive_,
|
||||||
util::abbrevSize(currentSpeed).c_str()));
|
util::abbrevSize(optimizationSpeed_).c_str(),
|
||||||
|
util::abbrevSize(currentSpeed).c_str()));
|
||||||
|
|
||||||
return maxConcurrentDownloads;
|
return maxConcurrentDownloads;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1596,7 +1596,7 @@ void changeGlobalOption(const Option& option, DownloadEngine* e)
|
||||||
option.getAsInt(PREF_MAX_CONCURRENT_DOWNLOADS));
|
option.getAsInt(PREF_MAX_CONCURRENT_DOWNLOADS));
|
||||||
e->getRequestGroupMan()->requestQueueCheck();
|
e->getRequestGroupMan()->requestQueueCheck();
|
||||||
}
|
}
|
||||||
if(option.defined(PREF_OPTIMIZE_CONCURRENT_DOWNLOADS)) {
|
if (option.defined(PREF_OPTIMIZE_CONCURRENT_DOWNLOADS)) {
|
||||||
e->getRequestGroupMan()->setupOptimizeConcurrentDownloads();
|
e->getRequestGroupMan()->setupOptimizeConcurrentDownloads();
|
||||||
e->getRequestGroupMan()->requestQueueCheck();
|
e->getRequestGroupMan()->requestQueueCheck();
|
||||||
}
|
}
|
||||||
|
|
|
@ -217,11 +217,14 @@ PrefPtr PREF_DEFERRED_INPUT = makePref("deferred-input");
|
||||||
// value: 1*digit
|
// value: 1*digit
|
||||||
PrefPtr PREF_MAX_CONCURRENT_DOWNLOADS = makePref("max-concurrent-downloads");
|
PrefPtr PREF_MAX_CONCURRENT_DOWNLOADS = makePref("max-concurrent-downloads");
|
||||||
// value: true | false | A:B
|
// 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 ] ]
|
// 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 ] ]
|
// 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
|
// value: true | false
|
||||||
PrefPtr PREF_FORCE_SEQUENTIAL = makePref("force-sequential");
|
PrefPtr PREF_FORCE_SEQUENTIAL = makePref("force-sequential");
|
||||||
// value: true | false
|
// value: true | false
|
||||||
|
|
Loading…
Reference in New Issue