mirror of
https://github.com/clusterio/clusterio.git
synced 2026-11-21 08:03:13 +09:00
Take a burst allowance off what a transfer check requires
controller.transfer_min_speed is now the speed that is never closed. A check requires that speed over 60 s less 2 MiB, which covers the bursts the OS sends data in, so at the default of 64 KiB/s the cutoff is about 30 KiB/s. The requirement is at least 1 byte, so a transfer that moved nothing is still closed at low settings. The slow receiver test sends 16 MiB so that it spans real checks, and two upload tests with set bursts cover the allowance. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
42bc31e406
commit
2e273dc630
4 files changed
+81
-18
No files matched your search
@@ -473,18 +473,23 @@ const answeredUploadDrainMs = 1000;
|
||||
* so the connection is closed if the body hasn't ended shortly after the
|
||||
* response. Closing it right away could make the client lose the response.
|
||||
*
|
||||
* The connection is also closed if the request moved slower than
|
||||
* controller.transfer_min_speed during a check interval, so that a
|
||||
* The connection is also closed if the request moved too little during a
|
||||
* check interval for controller.transfer_min_speed, so that a
|
||||
* request which stalled or is trickled in does not stay open forever while
|
||||
* a slow one can take the time it needs. For a request body this is what
|
||||
* was received of it. For both ends of a proxy stream it is what the
|
||||
* receiver has taken, as the sender is held back when the receiver is the
|
||||
* slow one. Time spent waiting for a proxy stream to start is not counted,
|
||||
* controller.proxy_stream_timeout limits that.
|
||||
*
|
||||
* The OS hands data on in bursts, so a transfer at the minimum speed can
|
||||
* move up to a burst less than that in a check. The burst allowance is
|
||||
* taken off what a check requires so such a transfer is never closed.
|
||||
* @param checkIntervalMs - Interval to check the progress of requests on.
|
||||
* @param burstAllowanceBytes - Bytes taken off what a check requires.
|
||||
* @returns Express middleware.
|
||||
*/
|
||||
function guardRequest(checkIntervalMs: number) {
|
||||
function guardRequest(checkIntervalMs: number, burstAllowanceBytes: number) {
|
||||
return function(req: Request, res: Response, next: any) {
|
||||
const socket = req.socket;
|
||||
res.once("finish", () => {
|
||||
@@ -521,10 +526,12 @@ function guardRequest(checkIntervalMs: number) {
|
||||
}
|
||||
const bytes = currentBytes();
|
||||
const intervalS = checkIntervalMs / 1000;
|
||||
if (bytes - lastBytes < minSpeedKiBps * 1024 * intervalS) {
|
||||
// At least 1 so a transfer that moved nothing is closed at any speed setting.
|
||||
const requiredBytes = Math.max(minSpeedKiBps * 1024 * intervalS - burstAllowanceBytes, 1);
|
||||
if (bytes - lastBytes < requiredBytes) {
|
||||
logger.warn(
|
||||
`Closing ${req.method} ${req.path}, it moved slower than ${minSpeedKiBps} KiB/s ` +
|
||||
`over ${intervalS} seconds`
|
||||
`Closing ${req.method} ${req.path}, it moved ${bytes - lastBytes} bytes in ${intervalS} seconds, ` +
|
||||
`less than the ${requiredBytes} required for ${minSpeedKiBps} KiB/s`
|
||||
);
|
||||
socket.destroy();
|
||||
}
|
||||
@@ -857,8 +864,12 @@ async function uploadMod(req: Request, res: Response) {
|
||||
}
|
||||
|
||||
|
||||
export function addRouteHandlers(app: Application, progressCheckIntervalMs = 60_000) {
|
||||
app.use(guardRequest(progressCheckIntervalMs));
|
||||
export function addRouteHandlers(
|
||||
app: Application,
|
||||
progressCheckIntervalMs = 60_000,
|
||||
burstAllowanceBytes = 2 * 1024 * 1024,
|
||||
) {
|
||||
app.use(guardRequest(progressCheckIntervalMs, burstAllowanceBytes));
|
||||
app.get("/metrics",
|
||||
validateUserToken,
|
||||
(req:Request, res:Response, next:any) => getMetrics(req, res).catch(next)
|
||||
|
||||
@@ -234,7 +234,7 @@ export class ControllerConfig extends classes.Config<ControllerConfigFields> {
|
||||
},
|
||||
"controller.transfer_min_speed": {
|
||||
title: "Transfer Minimum Speed",
|
||||
description: "KiB/s an upload or download has to move at over 60 seconds to not be closed, 0 for no limit.",
|
||||
description: "KiB/s at which an upload or download is never closed for moving too slowly, 0 for no limit.",
|
||||
type: "number",
|
||||
initialValue: 64,
|
||||
validator: validators.greaterThanEqualZero,
|
||||
|
||||
Reference in new issue
Block a user