End to end (workstation, recent a.b.boneless ranges from the spool): a 2M range in 10–12 s, 166k–202k headers/s per worker process (edge:bench on one core: 215k). - Prefetcher: spooled_at was set against a total counted from the range's resume point, which shrinks as the worker advances: the last chunks were never fetched and the worker waited. Now counted against the whole range, only new chunks counted, and leased ranges are always checked against the files. Planned ranges ahead are bounded (it had spooled ever more); the spool size is measured every 30 s (a stat per file). - The stream sends an empty frame every 20 s while waiting for a chunk (Node's fetch gave up on a quiet body after 5 minutes). - A range taken over midway: the first batch starts at the resume point (it started at the range's start and was refused). - edge:node inflates the next chunk on the thread pool while indexing the current one, and doesn't wait for a post before indexing on (posts stay in order; a failed post stops the range). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
29 lines
1.2 KiB
TypeScript
29 lines
1.2 KiB
TypeScript
import { test } from '@japa/runner'
|
|
import { KEEPALIVE, decodeFrames, encodeFrame, isKeepalive } from '#lib/edge/index'
|
|
|
|
test.group('edge / stream frames', () => {
|
|
test('frames survive being split anywhere; keep-alive frames are recognised', async ({ assert }) => {
|
|
const whole = Buffer.concat([
|
|
encodeFrame({ from: 160_000_000_001, to: 160_000_050_000, data: Buffer.from('first') }),
|
|
encodeFrame(KEEPALIVE),
|
|
encodeFrame({ from: 160_000_050_001, to: 160_000_100_000, data: Buffer.from('second chunk') }),
|
|
])
|
|
const pieces = [whole.subarray(0, 7), whole.subarray(7, 30), whole.subarray(30)]
|
|
const frames = []
|
|
for await (const frame of decodeFrames(pieces)) frames.push(frame)
|
|
assert.deepEqual(frames.map((f) => [f.from, f.to, f.data.toString(), isKeepalive(f)]), [
|
|
[160_000_000_001, 160_000_050_000, 'first', false],
|
|
[0, 0, '', true],
|
|
[160_000_050_001, 160_000_100_000, 'second chunk', false],
|
|
])
|
|
})
|
|
|
|
test('a stream that ends inside a frame is an error', async ({ assert }) => {
|
|
const cut = encodeFrame({ from: 1, to: 2, data: Buffer.from('abc') }).subarray(0, 21)
|
|
await assert.rejects(async () => {
|
|
for await (const _ of decodeFrames([cut])) {
|
|
}
|
|
}, /inside a frame/)
|
|
})
|
|
})
|