mirror of
https://github.com/nextcloud/desktop.git
synced 2024-11-23 05:25:50 +03:00
Bring improvements of new cpp to BandwidthManager::relativeDownloadMeasuringTimerExpired
Signed-off-by: Claudio Cambra <claudio.cambra@nextcloud.com>
This commit is contained in:
parent
350fa72478
commit
dbdce45797
1 changed files with 21 additions and 18 deletions
|
@ -258,22 +258,22 @@ void BandwidthManager::relativeDownloadMeasuringTimerExpired()
|
||||||
|
|
||||||
qCDebug(lcBandwidthManager) << _downloadJobList.size() << "Starting Delay";
|
qCDebug(lcBandwidthManager) << _downloadJobList.size() << "Starting Delay";
|
||||||
|
|
||||||
qint64 relativeLimitProgressMeasured = _relativeLimitCurrentMeasuredJob->currentDownloadPosition();
|
const auto relativeLimitProgressMeasured = _relativeLimitCurrentMeasuredJob->currentDownloadPosition();
|
||||||
qint64 relativeLimitProgressDifference = relativeLimitProgressMeasured - _relativeDownloadLimitProgressAtMeasuringRestart;
|
const auto relativeLimitProgressDifference = relativeLimitProgressMeasured - _relativeDownloadLimitProgressAtMeasuringRestart;
|
||||||
|
|
||||||
qCDebug(lcBandwidthManager) << _relativeDownloadLimitProgressAtMeasuringRestart
|
qCDebug(lcBandwidthManager) << _relativeDownloadLimitProgressAtMeasuringRestart
|
||||||
<< relativeLimitProgressMeasured << relativeLimitProgressDifference;
|
<< relativeLimitProgressMeasured << relativeLimitProgressDifference;
|
||||||
|
|
||||||
qint64 speedkBPerSec = (relativeLimitProgressDifference / relativeLimitMeasuringTimerIntervalMsec * 1000) / 1024;
|
const auto speedkBPerSec = (relativeLimitProgressDifference / relativeLimitMeasuringTimerIntervalMsec * 1000) / 1024;
|
||||||
|
|
||||||
qCDebug(lcBandwidthManager) << relativeLimitProgressDifference / 1024 << "kB =>" << speedkBPerSec << "kB/sec on full speed ("
|
qCDebug(lcBandwidthManager) << relativeLimitProgressDifference / 1024 << "kB =>" << speedkBPerSec << "kB/sec on full speed ("
|
||||||
<< _relativeLimitCurrentMeasuredJob->currentDownloadPosition();
|
<< _relativeLimitCurrentMeasuredJob->currentDownloadPosition();
|
||||||
|
|
||||||
qint64 downloadLimitPercent = -_currentDownloadLimit;
|
const auto downloadLimitPercent = qMax( qMin(-_currentDownloadLimit, qint64(90)), qint64(10));
|
||||||
// don't use too extreme values
|
const auto wholeTimeMsec = (100.0 / downloadLimitPercent) * relativeLimitMeasuringTimerIntervalMsec;
|
||||||
downloadLimitPercent = qMin(downloadLimitPercent, qint64(90));
|
const auto waitTimeMsec = wholeTimeMsec - relativeLimitMeasuringTimerIntervalMsec;
|
||||||
downloadLimitPercent = qMax(qint64(10), downloadLimitPercent);
|
const auto realWaitTimeMsec = waitTimeMsec + wholeTimeMsec;
|
||||||
qint64 wholeTimeMsec = (100.0 / downloadLimitPercent) * relativeLimitMeasuringTimerIntervalMsec;
|
|
||||||
qint64 waitTimeMsec = wholeTimeMsec - relativeLimitMeasuringTimerIntervalMsec;
|
|
||||||
qint64 realWaitTimeMsec = waitTimeMsec + wholeTimeMsec;
|
|
||||||
qCDebug(lcBandwidthManager) << waitTimeMsec << " - " << realWaitTimeMsec << " msec for " << downloadLimitPercent << "%";
|
qCDebug(lcBandwidthManager) << waitTimeMsec << " - " << realWaitTimeMsec << " msec for " << downloadLimitPercent << "%";
|
||||||
|
|
||||||
// We want to wait twice as long since we want to give all
|
// We want to wait twice as long since we want to give all
|
||||||
|
@ -282,18 +282,21 @@ void BandwidthManager::relativeDownloadMeasuringTimerExpired()
|
||||||
_relativeDownloadDelayTimer.setInterval(realWaitTimeMsec);
|
_relativeDownloadDelayTimer.setInterval(realWaitTimeMsec);
|
||||||
_relativeDownloadDelayTimer.start();
|
_relativeDownloadDelayTimer.start();
|
||||||
|
|
||||||
auto jobCount = _downloadJobList.size();
|
const auto jobCount = _downloadJobList.size();
|
||||||
qint64 quota = relativeLimitProgressDifference * (downloadLimitPercent / 100.0);
|
auto quota = relativeLimitProgressDifference * (downloadLimitPercent / 100.0);
|
||||||
|
|
||||||
if (quota > 20 * 1024) {
|
if (quota > 20 * 1024) {
|
||||||
qCInfo(lcBandwidthManager) << "ADJUSTING QUOTA FROM " << quota << " TO " << quota - 20 * 1024;
|
qCInfo(lcBandwidthManager) << "ADJUSTING QUOTA FROM " << quota << " TO " << quota - 20 * 1024;
|
||||||
quota -= 20 * 1024;
|
quota -= 20 * 1024;
|
||||||
}
|
}
|
||||||
qint64 quotaPerJob = quota / jobCount + 1;
|
|
||||||
Q_FOREACH (GETFileJob *gfj, _downloadJobList) {
|
const auto quotaPerJob = quota / jobCount + 1;
|
||||||
gfj->setBandwidthLimited(true);
|
for (const auto getFileJob : _downloadJobList) {
|
||||||
gfj->setChoked(false);
|
getFileJob->setBandwidthLimited(true);
|
||||||
gfj->giveBandwidthQuota(quotaPerJob);
|
getFileJob->setChoked(false);
|
||||||
qCDebug(lcBandwidthManager) << "Gave" << quotaPerJob / 1024.0 << "kB to" << gfj;
|
getFileJob->giveBandwidthQuota(quotaPerJob);
|
||||||
|
|
||||||
|
qCDebug(lcBandwidthManager) << "Gave" << quotaPerJob / 1024.0 << "kB to" << getFileJob;
|
||||||
}
|
}
|
||||||
_relativeLimitCurrentMeasuredDevice = nullptr;
|
_relativeLimitCurrentMeasuredDevice = nullptr;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue