Rebuild: the worker joins stream pieces once per frame, gzips posts off its thread
decodeFrames joined each network piece (~64 KB) onto the frame so far: a chunk of MBs copied over and over, 5.4% of a worker's time in an end-to-end profile (the bench reads files, so it never showed). Pieces are now joined once a frame is complete. A batch post's gzip (1.6%) runs on a thread-pool thread. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
bd1c846f27
commit
168605148f
3 files changed
+40
-12
No files matched your search
@@ -4,11 +4,12 @@ import { setTimeout as sleep } from 'node:timers/promises'
|
||||
import { spawn, type ChildProcess } from 'node:child_process'
|
||||
import { availableParallelism } from 'node:os'
|
||||
import { promisify } from 'node:util'
|
||||
import { gzipSync, unzip } from 'node:zlib'
|
||||
import { gzip, unzip } from 'node:zlib'
|
||||
import { RangeIndexer, decodeFrames, isKeepalive, toWire, type EdgeBatch, type Lease } from '#lib/edge/index'
|
||||
|
||||
const IDLE_MS = 30_000
|
||||
const unzipAsync = promisify(unzip)
|
||||
const gzipAsync = promisify(gzip)
|
||||
const RETRIES = 8
|
||||
|
||||
class LeaseLost extends Error {}
|
||||
@@ -219,8 +220,8 @@ class Api {
|
||||
}
|
||||
|
||||
async batch(rangeId: number, batch: EdgeBatch): Promise<{ releases: number; candidates: number; bytes: number }> {
|
||||
// Gzipped: chunk payloads are compressed already, the rest (names, fragments, candidates) compresses well.
|
||||
const body = gzipSync(JSON.stringify(toWire(batch)), { level: 1 })
|
||||
// Gzipped (on a thread-pool thread): chunk payloads are compressed already, the rest compresses well.
|
||||
const body = await gzipAsync(JSON.stringify(toWire(batch)), { level: 1 })
|
||||
const response = await this.request(`ranges/${rangeId}/batches`, { method: 'POST', body, headers: { 'Content-Encoding': 'gzip' } })
|
||||
if (!response.ok) throw new Error(`batch: HTTP ${response.status}`)
|
||||
return { ...((await response.json()) as { releases: number; candidates: number }), bytes: body.length }
|
||||
|
||||
Reference in new issue
Block a user