Rebuild: edge:node --max-mbit caps a node's download
For workers on a shared line (poweredge-kantoor: 160 Mbit/s): the range stream is read at most at the cap, TCP holds the coordinator back. The cap is the node's, split over its processes (also EDGE_MAX_MBIT). REBUILD.md: where workers run (connections set the speed; remote workers take CPU off homelab). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
104248d8a3
commit
42b6cac3ee
5 files changed
+67
-4
No files matched your search
@@ -4,3 +4,4 @@ export { toWire, fromWire, type WireBatch } from './wire.js'
|
||||
export type { Lease } from './lease.js'
|
||||
export { mergeFragments } from './merge.js'
|
||||
export type { EdgeSegment, FileMeta } from './scan.js'
|
||||
export { throttle } from './throttle.js'
|
||||
@@ -0,0 +1,18 @@
|
||||
import { setTimeout as sleep } from 'node:timers/promises'
|
||||
|
||||
/**
|
||||
* Passes a byte stream on at most `bytesPerSecond` on average: a worker on a
|
||||
* line it shares (`edge:node --max-mbit`) reads its range slower, and TCP
|
||||
* holds the sender back. The first second's worth goes at once.
|
||||
*/
|
||||
export async function* throttle<T extends Uint8Array>(stream: AsyncIterable<T> | Iterable<T>, bytesPerSecond: number): AsyncGenerator<T> {
|
||||
const started = Date.now()
|
||||
let bytes = 0
|
||||
for await (const piece of stream) {
|
||||
yield piece
|
||||
bytes += piece.byteLength
|
||||
const due = started + ((bytes - bytesPerSecond) / bytesPerSecond) * 1000
|
||||
const wait = due - Date.now()
|
||||
if (wait > 0) await sleep(wait)
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user