main
ply4 git calls26 ms42 KiB3 cachedprotocol v2
70 lines3.6 KiBRaw
1#!/usr/bin/env node
2// Freshness pushes: N commits to public-v0/<repo> straight to Artifacts (not through the mirror), one every <gapS>
3// seconds, each recorded with the laptop clock when `git push` returned and the laptop's offset to Cloudflare's clock
4// (ply-fresh /now, best round trip of 8). Prints one JSON line per push. Watchers (ply-fresh /watch-start) observe
5// /r/<repo> meanwhile; analyse.mjs joins the two.
6//
7// env -u CLOUDFLARE_API_TOKEN node bench/fresh/push.mjs <repo> <workdir> <n> <gapS>
8//
9// The write token (10 min, this repo only, re-minted after 8 min) reaches git through GIT_CONFIG_* only and is revoked
10// at the end. It is never printed.
11import { spawnSync } from 'node:child_process';
12import { readFileSync, writeFileSync } from 'node:fs';
13import { join } from 'node:path';
14import { fileURLToPath } from 'node:url';
16const ROOT = fileURLToPath(new URL('../..', import.meta.url));
17const CF = join(ROOT, 'node_modules', '.bin', 'cf');
18const NS = 'public-v0';
19const [repo, work, nArg, gapArg] = process.argv.slice(2);
20if (!repo || !work) throw new Error('usage: push.mjs <repo> <workdir> <n> <gapS>');
21const n = Number(nArg || 10), gapS = Number(gapArg || 30);
23function cf(args) {
24 const r = spawnSync(CF, args, { encoding: 'utf8', env: { ...process.env, CF_SEND_TELEMETRY: 'false' } });
25 if (r.status !== 0) throw new Error(`cf ${args.slice(0, 4).join(' ')} exited ${r.status}`);
26 return JSON.parse(r.stdout.slice(r.stdout.indexOf('{')));
28function git(args, env = {}) {
29 const r = spawnSync('git', args, { cwd: work, encoding: 'utf8', env: { ...process.env, GIT_TERMINAL_PROMPT: '0', ...env } });
30 if (r.status !== 0) throw new Error(`git ${args[0]} exited ${r.status}: ${String(r.stderr).replace(/art_v1_\w+/g, '[redacted]').slice(-300)}`);
31 return r.stdout.trim();
33async function offset() {
34 let best = { rtt: Infinity, off: 0 };
35 for (let i = 0; i < 8; i++) {
36 const a = Date.now();
37 const { now } = await (await fetch('https://ply-fresh.ivar.workers.dev/now')).json();
38 const b = Date.now();
39 if (b - a < best.rtt) best = { rtt: b - a, off: now - (a + b) / 2 };
40 }
41 return best;
44const remote = cf(['artifacts', 'namespaces', 'repos', 'get', repo, '--namespace', NS]).remote;
45let token = null, ids = [];
46const mint = () => {
47 if (token && Date.now() - token.at < 480_000) return token.value;
48 const m = cf(['artifacts', 'namespaces', 'tokens', 'create', NS, '--repo', repo, '--scope', 'write', '--ttl', '600']);
49 ids.push(m.id);
50 token = { value: String(m.plaintext), at: Date.now() };
51 return token.value;
52};
53const sleep = ms => new Promise(r => setTimeout(r, ms));
54try {
55 for (let i = 1; i <= n; i++) {
56 const readme = join(work, 'README.md');
57 writeFileSync(readme, readFileSync(readme, 'utf8').replace(/counter: \d+/, `counter: ${Date.now()}`));
58 git(['-c', 'user.name=ply fresh', '-c', 'user.email=fresh@ply.invalid', 'commit', '-q', '-am', `fresh-probe: push ${i}`]);
59 const oid = git(['rev-parse', 'HEAD']);
60 const env = { GIT_CONFIG_COUNT: '1', GIT_CONFIG_KEY_0: 'http.extraHeader', GIT_CONFIG_VALUE_0: `Authorization: Bearer ${mint()}` };
61 const t0 = Date.now();
62 git(['push', '--quiet', remote, 'HEAD:refs/heads/main'], env);
63 const t1 = Date.now();
64 const o = await offset();
65 console.log(JSON.stringify({ i, oid, pushStart: t0, pushDone: t1, pushMs: t1 - t0, cfOffset: o.off, offRtt: o.rtt, cfPushDone: t1 + o.off }));
66 if (i < n) await sleep(gapS * 1000 - (Date.now() - t0));
67 }
68} finally {
69 for (const id of ids) spawnSync(CF, ['artifacts', 'namespaces', 'tokens', 'revoke', String(id), '--namespace', NS, '--force'], { encoding: 'utf8' });
Diagnostics4 git calls · 26 ms
CallStatusSizeTime026 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 · hit3 ms
git.upload-pack ls-refs
http.response.status_code=200
git.upstream.cf_ray=-
git.upstream.phase=ls-refs
git.upstream.dur_ms=3
git.response.bytes=145
git.response.cache=HIT
git.response.duration_ms=3
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 1020040 KiB · hit3 ms
git.upload-pack fetch
http.response.status_code=200
git.upstream.cf_ray=-
git.upstream.phase=fetch
git.upstream.dur_ms=3
git.response.bytes=41349
git.response.cache=HIT
git.response.duration_ms=3
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=526b305930b8ef382f2d7a1f9c0238730a585921
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=41349
git.pkt.payload.max=41254
git.sideband.band1.bytes=41253
git.sideband.band2.bytes=0
git.sideband.band3.bytes=0
git.pack.objects=61
git.pack.bytes=41253
git.pack.ofs_delta=0
git.pack.ref_delta=0
git.pack.chain.max=0
git.pack.trailer=ab60efef4b7243678c75de64a4386986ee885c1c
git.pack.full=61
Open pack map
fetch2001.8 KiB · hit20 ms
git.upload-pack fetch
http.response.status_code=200
git.upstream.cf_ray=-
git.upstream.phase=fetch
git.upstream.dur_ms=20
git.response.bytes=1831
git.response.cache=HIT
git.response.duration_ms=20
git.fetch.wants=cd42d201e4a6950fb95624e0c75d1dc91c6064a8
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=1831
git.pkt.payload.max=1810
git.sideband.band1.bytes=1809
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-web.git
Ref
refs/heads/main
Commit
526b305930b8ef382f2d7a1f9c0238730a585921
cf-ray
a5e3390368d3f162
Request
7b09af67…
Protocol
v2 · sha1
Agent
gitty/1.0
Filter
advertised
Fetch
shallow filter sideband-all
Capabilities
agent ls-refs fetch object-format