GitHubivarvong

ply

main
ply7 git calls165 ms19 KiB4 cachedprotocol v2
67 lines2.8 KiBRaw
1// Shared helpers for the worker-mem harness: paths, the cf CLI (always without CLOUDFLARE_API_TOKEN), redaction.
2import { spawnSync } from 'node:child_process';
3import { mkdirSync, openSync, writeSync, closeSync, existsSync, readFileSync } from 'node:fs';
4import { randomBytes } from 'node:crypto';
5import { homedir } from 'node:os';
6import { dirname, join } from 'node:path';
7import { fileURLToPath } from 'node:url';
9export const HERE = dirname(fileURLToPath(import.meta.url));
10export const ROOT = join(HERE, '..', '..');
11export const DATA = join(HERE, '.data');
12export const REPORTS = join(HERE, 'reports');
13export const WORKER = 'ply-memlab';
14export const NAMESPACE = 'ply-loadgen';
15export const TOKEN_FILE = join(homedir(), '.config', 'ply', 'memlab-token');
17const ART = /art_v\d+_[^\s"'\\]+/g;
18const secrets = new Set();
19export const remember = s => { if (s) secrets.add(s); return s; };
20export function redact(text) {
21 let out = String(text).replace(ART, '[redacted]');
22 for (const s of secrets) out = out.split(s).join('[redacted]');
23 return out;
26const cfEnv = () => {
27 const env = { ...process.env };
28 delete env.CLOUDFLARE_API_TOKEN;
29 return env;
30};
32// Runs cf; returns { code, stdout, stderr } with secrets redacted from stderr only (stdout may carry minted tokens).
33export function cfRaw(args, opts = {}) {
34 const r = spawnSync('cf', args, { encoding: opts.encoding ?? 'utf8', env: cfEnv(), cwd: opts.cwd ?? HERE, maxBuffer: 256 * 1024 * 1024, input: opts.input });
35 return { code: r.status ?? 1, stdout: r.stdout ?? '', stderr: redact(r.stderr ?? '') };
38export function cfJson(args, opts = {}) {
39 const r = cfRaw(args, opts);
40 if (r.code !== 0) throw new Error(`cf ${args.slice(0, 4).join(' ')} failed: ${r.stderr.slice(0, 600)}`);
41 const at = r.stdout.search(/[[{]/);
42 return at < 0 ? null : JSON.parse(r.stdout.slice(at));
45// Writes a secret to a 0600 file without ever echoing it.
46export function writeSecret(path, value) {
47 mkdirSync(dirname(path), { recursive: true });
48 const fd = openSync(path, 'w', 0o600);
49 writeSync(fd, value);
50 closeSync(fd);
53// The bearer for the ply-memlab Worker, generated once.
54export function memlabToken() {
55 if (!existsSync(TOKEN_FILE)) writeSecret(TOKEN_FILE, randomBytes(32).toString('hex'));
56 return remember(readFileSync(TOKEN_FILE, 'utf8').trim());
59export const sleep = ms => new Promise(r => setTimeout(r, ms));
60export const stamp = () => new Date().toISOString().replace(/[-:]/g, '').replace(/\..*/, 'Z');
62export function quantiles(xs) {
63 const v = xs.filter(x => typeof x === 'number' && Number.isFinite(x)).sort((a, b) => a - b);
64 if (v.length === 0) return null;
65 const at = p => v[Math.min(v.length - 1, Math.floor(p * v.length))];
66 return { n: v.length, min: v[0], p50: at(0.5), p90: at(0.9), max: v[v.length - 1] };
Diagnostics7 git calls · 165 ms
CallStatusSizeTime0165 ms
discover200191 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=191
git.server.agent=git/github-9922ec520325-Linux
git.server.object_format=sha1
git.server.caps=agent ls-refs fetch server-option object-format
git.server.fetch=shallow wait-for-done filter
git.protocol.version=2
git.pkt.frames=9
git.pkt.data=7
git.pkt.flush=2
git.pkt.delim=0
git.pkt.bytes=191
git.pkt.payload.max=36
ls-refs20012 KiB87 ms
git.upload-pack ls-refs
http.response.status_code=200
git.upstream.cf_ray=-
git.upstream.phase=ls-refs
git.upstream.dur_ms=82
git.response.bytes=11990
git.response.cache=EXPIRED
git.response.duration_ms=87
git.protocol.version=2
git.pkt.frames=152
git.pkt.data=151
git.pkt.flush=1
git.pkt.delim=0
git.pkt.bytes=11990
git.pkt.payload.max=122
git.ls_refs.count=151
git.ls_refs.head=refs/heads/main
fetchtree:0 · deepen 102004.2 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=4347
git.response.cache=HIT
git.response.duration_ms=2
git.fetch.filter=tree:0
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=7
git.pkt.data=5
git.pkt.flush=1
git.pkt.delim=1
git.pkt.bytes=4347
git.pkt.payload.max=4247
git.sideband.band1.bytes=4247
git.sideband.band2.bytes=0
git.sideband.band3.bytes=0
git.pack.objects=10
git.pack.bytes=4247
git.pack.ofs_delta=0
git.pack.ref_delta=0
git.pack.chain.max=0
git.pack.trailer=a6caf8e129bea82c9bae4cbc7c130c9205add400
git.pack.full=10
Open pack map
fetchtree:0200919 B · hit4 ms
git.upload-pack fetch
http.response.status_code=200
git.upstream.cf_ray=-
git.upstream.phase=fetch
git.upstream.dur_ms=4
git.response.bytes=919
git.response.cache=HIT
git.response.duration_ms=4
git.fetch.filter=tree:0
git.fetch.wants=800d30ba8923860bfc460ca884b7f9ba22083588
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=4
git.pkt.data=3
git.pkt.flush=1
git.pkt.delim=0
git.pkt.bytes=919
git.pkt.payload.max=892
git.sideband.band1.bytes=892
git.sideband.band2.bytes=0
git.sideband.band3.bytes=0
git.pack.objects=1
git.pack.bytes=892
git.pack.trailer=5323b9266eea5ded637285d1c5320699f12be76e
Open pack map
fetchtree:0200106 B · 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=106
git.response.cache=HIT
git.response.duration_ms=2
git.fetch.filter=tree:0
git.fetch.wants=72bbbdb37dc951e0de5615d1376ca1b23588856c
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=4
git.pkt.data=3
git.pkt.flush=1
git.pkt.delim=0
git.pkt.bytes=106
git.pkt.payload.max=79
git.sideband.band1.bytes=79
git.sideband.band2.bytes=0
git.sideband.band3.bytes=0
git.pack.objects=1
git.pack.bytes=79
git.pack.trailer=1cca45a06ebd0c08bccef52d1cdb92cae1868075
Open pack map
fetchtree:0200291 B · 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=291
git.response.cache=HIT
git.response.duration_ms=2
git.fetch.filter=tree:0
git.fetch.wants=d3ab99f804f647a2fe02e623e69e5ccc7a17b935
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=4
git.pkt.data=3
git.pkt.flush=1
git.pkt.delim=0
git.pkt.bytes=291
git.pkt.payload.max=264
git.sideband.band1.bytes=264
git.sideband.band2.bytes=0
git.sideband.band3.bytes=0
git.pack.objects=1
git.pack.bytes=264
git.pack.trailer=1fec5d654a53d2752ea2b9c5bd06569c4565d5b6
Open pack map
fetch2001.3 KiB68 ms
git.upload-pack fetch
http.response.status_code=200
git.upstream.cf_ray=-
git.upstream.phase=fetch
git.upstream.dur_ms=68
git.response.bytes=1380
git.response.cache=MISS
git.response.duration_ms=68
git.fetch.wants=bd62cc0a29068185f1714c0e4630380ca9fe61fa
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=4
git.pkt.data=3
git.pkt.flush=1
git.pkt.delim=0
git.pkt.bytes=1380
git.pkt.payload.max=1353
git.sideband.band1.bytes=1353
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://github.com/ivarvong/ply
Ref
refs/heads/main
Commit
19912563f540228593df0c489082e5e2508e21e4
cf-ray
a5e311465c8fbdc9
Request
8d448f7e…
Protocol
v2 · sha1
Agent
git/github-9922ec520325-Linux
Filter
advertised
Fetch
shallow wait-for-done filter
Capabilities
agent ls-refs fetch server-option object-format