Keep upload speed limits at the configured decimal MB/s
CI / verify (push) Canceled after 0s

The shared upload limiter started with a full second of tokens and refilled
up to one second during short idle gaps, so new uploads could briefly send
almost twice the limit. In a parallel-upload test it released 3.87 MB in one
second at a 2 MB/s limit. Uploads now reserve send time on one shared
schedule with at most a 200 ms burst and exact waits.

Speeds and limits used 1024-based kB and MB while being shown as kB/s and
MB/s, so a limit of 100 meant 104.9 MB/s. Limits, measured speeds, ETA and
the speed graph now use 1 MB = 1,000,000 bytes. Saved limits are converted
once so the displayed value stays the same.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
SucukdeluxeandClaude Opus 5.5 committed 2026-10-21 00:26:01 +02:00
1 parent 290b9db8ce
commit d37e86690f
5 files changed
+60 -54

No files matched your search

+13 -13
View File
@@ -319,9 +319,9 @@ class UploadManager extends EventEmitter {
const newKbs = (this.globalSettings.globalMaxSpeedKbs || 0);
if (newKbs > 0) {
if (this.globalThrottle) {
this.globalThrottle.updateRate(newKbs * 1024);
this.globalThrottle.updateRate(newKbs * 1000);
} else {
this.globalThrottle = new Throttle(newKbs * 1024);
this.globalThrottle = new Throttle(newKbs * 1000);
}
} else {
this.globalThrottle = null;
@@ -363,9 +363,9 @@ class UploadManager extends EventEmitter {
const kbs = Number(this.globalSettings.globalMaxSpeedKbs || 0);
if (!Number.isFinite(kbs) || kbs <= 0) return null;
if (!this.globalThrottle) {
this.globalThrottle = new Throttle(kbs * 1024);
this.globalThrottle = new Throttle(kbs * 1000);
} else {
this.globalThrottle.updateRate(kbs * 1024);
this.globalThrottle.updateRate(kbs * 1000);
}
return this.globalThrottle;
}
@@ -730,7 +730,7 @@ class UploadManager extends EventEmitter {
});
const hosterThrottle = settings.maxSpeedKbs > 0
? new Throttle(settings.maxSpeedKbs * 1024)
? new Throttle(settings.maxSpeedKbs * 1000)
: null;
const globalThrottle = this._getGlobalThrottle();
const throttle = hosterThrottle && globalThrottle
@@ -770,7 +770,7 @@ class UploadManager extends EventEmitter {
const timeDelta = (now - lastSpeedTime) / 1000;
if (Number.isFinite(timeDelta) && timeDelta >= 1) {
const bytesDelta = bytesUploaded - lastBytes;
currentSpeedKbs = Math.round(bytesDelta / timeDelta / 1024);
currentSpeedKbs = Math.round(bytesDelta / timeDelta / 1000);
lastBytes = bytesUploaded;
lastSpeedTime = now;
}
@@ -782,7 +782,7 @@ class UploadManager extends EventEmitter {
lastEmitTime = now;
const remaining = currentSpeedKbs > 0
? Math.round((bytesTotal - bytesUploaded) / (currentSpeedKbs * 1024))
? Math.round((bytesTotal - bytesUploaded) / (currentSpeedKbs * 1000))
: 0;
this._emitProgress(uploadId, fileName, task.hoster, { accountId: task.accountId,
@@ -1105,7 +1105,7 @@ class UploadManager extends EventEmitter {
const now = Date.now();
const timeDelta = (now - lastSpeedTime) / 1000;
if (timeDelta >= 1) {
currentSpeedKbs = Math.round((bytesUploaded - lastBytes) / timeDelta / 1024);
currentSpeedKbs = Math.round((bytesUploaded - lastBytes) / timeDelta / 1000);
lastBytes = bytesUploaded;
lastSpeedTime = now;
}
@@ -1114,7 +1114,7 @@ class UploadManager extends EventEmitter {
if (now - lastEmitTime < PROGRESS_EMIT_INTERVAL) return;
lastEmitTime = now;
const elapsed = Math.round((now - jobStart) / 1000);
const remaining = currentSpeedKbs > 0 ? Math.round((bytesTotal - bytesUploaded) / (currentSpeedKbs * 1024)) : 0;
const remaining = currentSpeedKbs > 0 ? Math.round((bytesTotal - bytesUploaded) / (currentSpeedKbs * 1000)) : 0;
this._emitProgress(uploadId, fileName, task.hoster, { accountId: task.accountId,
jobId, status: 'uploading',
progress: bytesTotal > 0 ? Math.min(1, bytesUploaded / bytesTotal) : 0,
@@ -1123,7 +1123,7 @@ class UploadManager extends EventEmitter {
});
};
const hosterThrottle = settings.maxSpeedKbs > 0 ? new Throttle(settings.maxSpeedKbs * 1024) : null;
const hosterThrottle = settings.maxSpeedKbs > 0 ? new Throttle(settings.maxSpeedKbs * 1000) : null;
const globalThrottle = this._getGlobalThrottle();
const throttle = hosterThrottle && globalThrottle
? { consume: async (bytes, sig) => { await hosterThrottle.consume(bytes, sig); await globalThrottle.consume(bytes, sig); } }
@@ -1259,7 +1259,7 @@ class UploadManager extends EventEmitter {
const now = Date.now();
const timeDelta = (now - lastSpeedTime) / 1000;
if (timeDelta >= 1) {
currentSpeedKbs = Math.round((bytesUploaded - lastBytes) / timeDelta / 1024);
currentSpeedKbs = Math.round((bytesUploaded - lastBytes) / timeDelta / 1000);
lastBytes = bytesUploaded;
lastSpeedTime = now;
}
@@ -1268,7 +1268,7 @@ class UploadManager extends EventEmitter {
if (now - lastEmitTime < PROGRESS_EMIT_INTERVAL) return;
lastEmitTime = now;
const elapsed = Math.round((now - jobStart) / 1000);
const remaining = currentSpeedKbs > 0 ? Math.round((bytesTotal - bytesUploaded) / (currentSpeedKbs * 1024)) : 0;
const remaining = currentSpeedKbs > 0 ? Math.round((bytesTotal - bytesUploaded) / (currentSpeedKbs * 1000)) : 0;
this._emitProgress(uploadId, fileName, task.hoster, { accountId: task.accountId,
jobId, status: 'uploading',
progress: bytesTotal > 0 ? Math.min(1, bytesUploaded / bytesTotal) : 0,
@@ -1276,7 +1276,7 @@ class UploadManager extends EventEmitter {
elapsed, remaining, error: null, result: null, attempt: 1, maxAttempts: 1
});
};
const hosterThrottle = settings.maxSpeedKbs > 0 ? new Throttle(settings.maxSpeedKbs * 1024) : null;
const hosterThrottle = settings.maxSpeedKbs > 0 ? new Throttle(settings.maxSpeedKbs * 1000) : null;
const globalThrottle = this._getGlobalThrottle();
const throttle = hosterThrottle && globalThrottle
? { consume: async (bytes, sig) => { await hosterThrottle.consume(bytes, sig); await globalThrottle.consume(bytes, sig); } }