Artifactspublic-v0

ply

main
ply4 git calls32 ms41 KiB3 cachedprotocol v2
116 lines6.5 KiBRaw
1// Round trips and wall time of the read operations against real remotes, old tree against new (issue #218).
2// node test/bench-rt.mjs [--runs 7] [--tree <dir> ...] [--bearer-file <json with .plaintext>] --remote '<url> <file d1> <file d2> <file d3> <dir d1>' ...
3// A tree is any ply checkout (an older commit's `git archive` of src/ and test/ts-resolve.mjs too): its src/ is imported
4// through its own module graph (module state such as the quirks memo is per tree). Each tree gets one quirks record per
5// remote, shared by every run after one warm-up pass, which is how a long-lived caller (ply-web: one record per origin
6// per isolate) runs: the steady state, not first contact. Runs are interleaved tree by tree and op by op, so a change in
7// the network hits every tree alike.
8// requests every HTTP request the op made (GET info/refs, POST git-upload-pack)
9// serial the requests on the critical path: a request that starts after every earlier one has ended starts a new
10// step; one that starts while another is in flight joins the current step
11// ms wall time of the op, a readFile's stream drained
12// `--bearer-file` sends `Authorization: Bearer <plaintext>` to an Artifacts host (*.artifacts.cloudflare.net) only.
13import { readFileSync } from 'node:fs';
14import { resolve } from 'node:path';
15import { pathToFileURL } from 'node:url';
16import { registerHooks } from 'node:module';
18registerHooks({
19 resolve(specifier, context, next) {
20 try { return next(specifier, context); } catch (e) {
21 if (e?.code !== 'ERR_MODULE_NOT_FOUND' || !/^\.\.?\//.test(specifier) || !specifier.endsWith('.js')) throw e;
22 return next(`${specifier.slice(0, -3)}.ts`, context);
23 }
24 },
25});
27const argv = process.argv.slice(2);
28const opt = (k, d) => { const i = argv.indexOf(`--${k}`); return i < 0 ? d : argv[i + 1]; };
29const opts = k => argv.flatMap((a, i) => (a === `--${k}` ? [argv[i + 1]] : []));
30const runs = Number(opt('runs', '7'));
31const trees = opts('tree').length ? opts('tree') : ['.'];
32const bearerFile = opt('bearer-file', null);
33const bearer = bearerFile === null ? null : JSON.parse(readFileSync(bearerFile, 'utf8')).plaintext;
34const remotes = opts('remote').map(s => { const [url, f1, f2, f3, d1] = s.split(' '); return { url, f1, f2, f3, d1 }; });
35if (remotes.length === 0) { console.error('give at least one --remote'); process.exit(2); }
37const load = async dir => {
38 const src = pathToFileURL(resolve(dir, 'src')).href;
39 const [read, log] = await Promise.all([import(`${src}/read.ts`), import(`${src}/log.ts`)]);
40 return { dir, ...read, readLog: log.readLog };
41};
42const loaded = await Promise.all(trees.map(load));
44// A fetch that records each request's start and end (the end is when its body has been read to the end or cancelled).
45function counting() {
46 const events = [];
47 const fetchImpl = async (input, init) => {
48 const ev = { start: performance.now(), end: Number.POSITIVE_INFINITY };
49 events.push(ev);
50 const res = await fetch(input, init);
51 if (!res.body) { ev.end = performance.now(); return res; }
52 const reader = res.body.getReader();
53 const body = new ReadableStream({
54 async pull(c) { const r = await reader.read(); if (r.done) { ev.end = performance.now(); c.close(); } else c.enqueue(r.value); },
55 cancel(reason) { ev.end = performance.now(); return reader.cancel(reason); },
56 });
57 return new Response(body, { status: res.status, statusText: res.statusText, headers: res.headers });
58 };
59 const serial = () => {
60 let steps = 0, until = -1;
61 for (const e of [...events].sort((a, b) => a.start - b.start)) {
62 if (e.start >= until) steps++;
63 until = Math.max(until, e.end);
64 }
65 return steps;
66 };
67 return { fetchImpl, events, serial };
69const drain = async stream => { let n = 0; for await (const c of stream) n += c.length; return n; };
70const ops = r => [
71 ['readCommit', (ply, o) => ply.readCommit(r.url, { ref: null }, o)],
72 ['readLog 10', (ply, o) => ply.readLog(r.url, { ref: null, limit: 10 }, o)],
73 ['listTree /', (ply, o) => ply.listTree(r.url, { ref: null, path: '' }, o)],
74 [`listTree ${r.d1}`, (ply, o) => ply.listTree(r.url, { ref: null, path: r.d1 }, o)],
75 [`readFile ${r.f1}`, (ply, o) => ply.readFile(r.url, { ref: null, path: r.f1 }, o)],
76 [`readFile ${r.f2}`, (ply, o) => ply.readFile(r.url, { ref: null, path: r.f2 }, o)],
77 [`readFile ${r.f3}`, (ply, o) => ply.readFile(r.url, { ref: null, path: r.f3 }, o)],
78];
79const auth = url => (bearer !== null && new URL(url).host.endsWith('.artifacts.cloudflare.net') ? { auth: { bearer } } : {});
81async function once(ply, quirks, r, fn) {
82 const c = counting();
83 const t0 = performance.now();
84 const got = await fn(ply, { quirks, fetchImpl: c.fetchImpl, ...auth(r.url) });
85 if (!got.ok) throw new Error(`${got.error.code}: ${got.error.message}`);
86 if (got.value.stream) await drain(got.value.stream);
87 return { ms: performance.now() - t0, requests: c.events.length, serial: c.serial() };
89const q = (a, p) => { const s = [...a].sort((x, y) => x - y); return s[Math.min(s.length - 1, Math.floor(p * s.length))]; };
90const fmt = a => `${Math.round(q(a, 0.5))} [${Math.round(q(a, 0))}–${Math.round(q(a, 1))}]`;
91const counts = a => { const lo = Math.min(...a), hi = Math.max(...a); return lo === hi ? `${lo}` : `${lo}–${hi}`; };
93for (const r of remotes) {
94 const quirks = loaded.map(() => ({}));
95 const table = new Map();
96 for (const [name, fn] of ops(r)) {
97 loaded.forEach(ply => table.set(`${name}\0${ply.dir}`, { ms: [], requests: [], serial: [] }));
98 // warm-up: the quirks record learns what this server takes (first contact is not what is measured)
99 for (const [i, ply] of loaded.entries()) await once(ply, quirks[i], r, fn);
100 }
101 for (let run = 0; run < runs; run++) {
102 for (const [name, fn] of ops(r)) {
103 for (const [i, ply] of loaded.entries()) {
104 const m = await once(ply, quirks[i], r, fn);
105 const row = table.get(`${name}\0${ply.dir}`);
106 row.ms.push(m.ms); row.requests.push(m.requests); row.serial.push(m.serial);
107 }
108 }
109 }
110 console.log(`\n${new URL(r.url).host}${new URL(r.url).pathname} (${runs} runs, steady state; median [min–max] ms)`);
111 console.log(` ${'op'.padEnd(44)} ${loaded.map(p => `${p.dir.slice(-14).padStart(14)}: req serial ms`.padEnd(46)).join(' ')}`);
112 for (const [name] of ops(r)) {
113 const cells = loaded.map(ply => { const row = table.get(`${name}\0${ply.dir}`); return `${counts(row.requests).padStart(20)} ${counts(row.serial).padStart(4)} ${fmt(row.ms).padEnd(20)}`; });
114 console.log(` ${name.padEnd(44)} ${cells.join(' ')}`);
115 }
Diagnostics4 git calls · 32 ms
CallStatusSizeTime032 ms
discover200152 B2 ms
git.upload-pack discover
http.response.status_code=200
git.upstream.cf_ray=-
git.upstream.phase=ls-refs
git.upstream.dur_ms=2
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 · hit2 ms
git.upload-pack ls-refs
http.response.status_code=200
git.upstream.cf_ray=-
git.upstream.phase=ls-refs
git.upstream.dur_ms=2
git.response.bytes=145
git.response.cache=HIT
git.response.duration_ms=2
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=55
Open pack map
fetch2002.8 KiB · hit28 ms
git.upload-pack fetch
http.response.status_code=200
git.upstream.cf_ray=-
git.upstream.phase=fetch
git.upstream.dur_ms=28
git.response.bytes=2820
git.response.cache=HIT
git.response.duration_ms=28
git.fetch.wants=e5d134d1c994fd78116c7baede4ade27f61115d7
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=2820
git.pkt.payload.max=2799
git.sideband.band1.bytes=2798
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
a5e2be3df927cfc3
Request
5fef326b…
Protocol
v2 · sha1
Agent
gitty/1.0
Filter
advertised
Fetch
shallow filter sideband-all
Capabilities
agent ls-refs fetch object-format