main
1// One sweep cell, in its own process. The parent passes --max-old-space-size when the cell is the 128 MiB heap.
2// argv[2] is the cell JSON. One JSON line on stdout; exit 0 even on a typed refusal so the parent can tell a
3// refusal from a crash. Peak RSS is the kernel's VmHWM for this process (vmHwmKiB below). ArrayBuffers are sampled because they
4// sit outside the V8 heap the flag caps.
5import { readFileSync } from 'node:fs';
6import { execFileSync } from 'node:child_process';
7import { createHash } from 'node:crypto';
8import { GitHttp } from '../../src/client.js';
9import { parsePack, resolvePack } from '../../src/pack.js';
10import { scanPackIndex } from '../../src/packscanindex.js';
11import { resolvePackRange } from '../../src/packrangeresolve.js';
12import { rangeFromBytes } from '../../src/rangesource.js';
13import { pushRepo } from '../../src/repo-node.js';
14import { Tracer } from '../../src/otel.js';
15import { unwrap, unwrapAsync } from '../unwrap.js';
16import { failure, fetchOps } from './ops.mjs';
18const cell = JSON.parse(process.argv[2]);
19// the cell's limits as written: the keys it sets, every other key the default (parseLimits, where the client is made)
20const opts = { tracer: new Tracer(), limits: cell.limits ?? {} };
22let heapPeak = 0;
23let abPeak = 0;
24const sample = setInterval(() => {
25 const m = process.memoryUsage();
26 if (m.heapUsed > heapPeak) heapPeak = m.heapUsed;
27 if (m.arrayBuffers > abPeak) abPeak = m.arrayBuffers;
28}, 5);
29sample.unref();
31/** @param {Iterable<string>} oids */
32function oidsHash(oids) {
33 const hash = createHash('sha1');
34 for (const oid of [...oids].sort()) hash.update(oid);
35 return hash.digest('hex');
36}
38// KiB. /proc/self/status VmHWM is this image's own high-water mark (reset by exec); elsewhere, ru_maxrss.
39function vmHwmKiB() {
40 try {
41 const m = /VmHWM:\s+(\d+)\s+kB/.exec(readFileSync('/proc/self/status', 'utf8'));
42 if (m) return Number(m[1]);
43 } catch {
44 // not Linux
45 }
46 return process.resourceUsage().maxRSS;
47}
49const TYPE_ID = { commit: 1, tree: 2, blob: 3, tag: 4 };
51const ops = {
52 ...fetchOps(cell, opts),
53 async pack() {
54 const buf = new Uint8Array(readFileSync(cell.pack));
55 const parsed = unwrap(parsePack(buf, { limits: opts.limits }));
56 const resolved = unwrap(resolvePack(parsed, () => null, opts.limits));
57 return { n: resolved.objects.size, maxChain: resolved.stats.maxChain, oidsHash: oidsHash(resolved.objects.keys()) };
58 },
59 // resolvePackRange over the pack's bytes. The index is scanned on the defaults; the cell's limits bound the resolve.
60 async resolveRange() {
61 const buf = new Uint8Array(readFileSync(cell.pack));
62 const index = unwrap(await scanPackIndex(new Blob([buf]).stream()));
63 const resolved = unwrap(await resolvePackRange(index, rangeFromBytes(buf), { limits: opts.limits }));
64 return { n: resolved.count, work: resolved.stats.work };
65 },
66 // A thin fetch: the server deltas against the haves, and the bases come from the local store (`cell.store`, a bare
67 // repo holding the haves) through the external lookup, the way a client with those objects resolves them.
68 async fetchThin() {
69 const external = (/** @type {string} */ oid) => {
70 try {
71 const type = execFileSync('git', ['-C', cell.store, 'cat-file', '-t', oid], { encoding: 'utf8' }).trim();
72 const data = execFileSync('git', ['-C', cell.store, 'cat-file', type, oid], { maxBuffer: 1 << 28 });
73 return { type: TYPE_ID[type], data: new Uint8Array(data) };
74 } catch {
75 return null;
76 }
77 };
78 const c = unwrap(GitHttp.create(cell.url, opts));
79 const r = await unwrapAsync(c.fetchPack({ wants: cell.wants, haves: cell.haves, thinPack: true }, { external }));
80 const objects = r.resolved?.objects ?? r.objects ?? new Map();
81 return { n: objects.size, refDelta: r.parsed?.stats.refDelta ?? 0, oidsHash: oidsHash(objects.keys()) };
82 },
83 async pushRepo() {
84 const r = await unwrapAsync(pushRepo(cell.local, cell.url, cell.spec ?? {}, opts));
85 return { updates: r.updates.length, objects: r.objects, thinDeltas: r.thinDeltas, upToDate: r.upToDate };
86 },
87};
89const t0 = performance.now();
90const cpu0 = process.cpuUsage();
91/** @type {Record<string, unknown>} */
92let res;
93try {
94 const op = ops[cell.op];
95 if (!op) throw new Error(`unknown op ${cell.op}`);
96 res = { status: 'ok', ...(await op()) };
97} catch (e) {
98 res = failure(e);
99} finally {
100 clearInterval(sample);
101}
102const cpu = process.cpuUsage(cpu0);
103res.ms = Math.round(performance.now() - t0);
104res.cpuMs = Math.round((cpu.user + cpu.system) / 1000);
105// The peak the kernel saw, including ArrayBuffers the heap flag does not cap. VmHWM, not ru_maxrss: ru_maxrss survives
106// exec, so a cell spawned by a driver that had grown to 500 MB building fixtures reported 500 MB whatever it used.
107res.rssPeakMB = Math.round(vmHwmKiB() / 1024);
108res.heapPeakMB = Math.round(heapPeak / (1024 * 1024));
109res.abPeakMB = Math.round(abPeak / (1024 * 1024));
110process.stdout.write(`${JSON.stringify(res)}\n`);
111process.exit(0);
Diagnostics4 git calls · 372 ms
CallStatusSizeTime0372 ms
discover200152 B3 ms
git.upload-pack discover http.response.status_code=200 git.upstream.cf_ray=- git.upstream.phase=ls-refs git.upstream.dur_ms=3 git.response.bytes=152 git.server.agent=gitty/1.0 git.server.object_format=sha1 git.server.caps=agent ls-refs fetch object-format git.server.fetch=shallow filter sideband-all git.protocol.version=2 git.pkt.frames=8 git.pkt.data=6 git.pkt.flush=2 git.pkt.delim=0 git.pkt.bytes=152 git.pkt.payload.max=34
ls-refs200145 B · hit4 ms
git.upload-pack ls-refs http.response.status_code=200 git.upstream.cf_ray=- git.upstream.phase=ls-refs git.upstream.dur_ms=4 git.response.bytes=145 git.response.cache=HIT git.response.duration_ms=4 git.protocol.version=2 git.pkt.frames=3 git.pkt.data=2 git.pkt.flush=1 git.pkt.delim=0 git.pkt.bytes=145 git.pkt.payload.max=76 git.ls_refs.count=2 git.ls_refs.head=refs/heads/main
fetchblob:none · deepen 1020038 KiB · hit2 ms
git.upload-pack fetch http.response.status_code=200 git.upstream.cf_ray=- git.upstream.phase=fetch git.upstream.dur_ms=2 git.response.bytes=38434 git.response.cache=HIT git.response.duration_ms=2 git.fetch.filter=blob:none git.fetch.filter.requested=tree:0 git.fetch.filter.fallback=blob:none git.fetch.filter.learned=false git.fetch.wants=19912563f540228593df0c489082e5e2508e21e4 git.fetch.haves.count=0 git.fetch.deepen=10 git.fetch.thin_pack=false git.fetch.ofs_delta=true git.protocol.version=2 git.pkt.frames=6 git.pkt.data=4 git.pkt.flush=1 git.pkt.delim=1 git.pkt.bytes=38434 git.pkt.payload.max=38339 git.sideband.band1.bytes=38338 git.sideband.band2.bytes=0 git.sideband.band3.bytes=0 git.pack.objects=63 git.pack.bytes=38338 git.pack.ofs_delta=0 git.pack.ref_delta=8 git.pack.chain.max=8 git.pack.trailer=0bc36ab7adf82d3109177f11f1ea93f1ce071f77 git.pack.full=55Open pack map
fetch2002.1 KiB366 ms
git.upload-pack fetch http.response.status_code=200 git.upstream.cf_ray=- git.upstream.phase=fetch git.upstream.dur_ms=366 git.response.bytes=2172 git.response.cache=MISS git.response.duration_ms=366 git.fetch.wants=6c2a5f290431326299bef6b62871acee7203f3b9 git.fetch.haves.count=0 git.fetch.deepen=0 git.fetch.thin_pack=false git.fetch.ofs_delta=true git.protocol.version=2 git.pkt.frames=3 git.pkt.data=2 git.pkt.flush=1 git.pkt.delim=0 git.pkt.bytes=2172 git.pkt.payload.max=2151 git.sideband.band1.bytes=2150 git.sideband.band2.bytes=0 git.sideband.band3.bytes=0
Each row is one HTTP round trip ply made to the git server for this page, on one timeline. discover asks what the server speaks, ls-refs lists branch tips, fetch brings objects by id. A hit was served by Workers Cache. Tap a row for its wire details.
- Remote
- https://5ad2236b39de4c8bd8f6270ea63f3ea9.artifacts.cloudflare.net/git/public-v0/ply.git
- Ref
- refs/heads/main
- Commit
- 19912563f540228593df0c489082e5e2508e21e4
- cf-ray
- a5e30c8119bb8a31
- Request
- 2b56ed08…
- Protocol
- v2 · sha1
- Agent
- gitty/1.0
- Filter
- advertised
- Fetch
- shallow filter sideband-all
- Capabilities
- agent ls-refs fetch object-format