Spaces:
Running
Running
File size: 14,672 Bytes
5c9088d 4531c3e 322a83f 4531c3e 322a83f 4531c3e 5c9088d | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 | <!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta name="description" content="Pulsefold is a C++17 heartbeat freshness monitor for large agent fleets. Try the live timeline, download the source and reproduce its billion-watch benchmark.">
<meta name="theme-color" content="#f7f7f2">
<title>Pulsefold · Heartbeat replay</title>
<style>
:root{color-scheme:light;--paper:#f7f7f2;--ink:#152119;--muted:#556159;--line:#ced5c9;--white:#fff;--green:#236147;--green-light:#bfe2c5;--red:#993e24;--red-light:#f5b89e;--mono:"IBM Plex Mono",ui-monospace,SFMono-Regular,Consolas,monospace;--sans:"Instrument Sans",Inter,system-ui,sans-serif}
*{box-sizing:border-box}body{margin:0;background:var(--paper);color:var(--ink);font-family:var(--sans);line-height:1.5}main{max-width:1040px;margin:auto;padding:26px 36px 64px}header{display:flex;align-items:center;justify-content:space-between;border-bottom:1px solid var(--line);padding-bottom:18px}.brand{display:inline-flex;gap:9px;align-items:center;font-size:20px;font-weight:750;letter-spacing:-.05em}.brand svg{color:var(--green)}button,select{font:inherit;color:inherit;background:var(--white)}button,select{border:1px solid #aab5a9;border-radius:7px;min-height:40px;padding:7px 12px}button{cursor:pointer;font-weight:600}button:hover:not(:disabled),select:hover{border-color:var(--green);background:#f4faf3}button:disabled{cursor:default;opacity:.44}button:focus-visible,select:focus-visible,a:focus-visible{outline:3px solid #276cb3;outline-offset:3px}button.primary{background:var(--green);border-color:var(--green);color:white}button.primary:hover:not(:disabled){background:#184a33}h1{font-size:clamp(34px,5.6vw,62px);line-height:1.04;letter-spacing:-.065em;margin:0 0 13px}h2{font-size:21px;letter-spacing:-.045em;margin:0}.intro{padding:34px 0 26px}.intro p{font-size:17px;max-width:60ch;margin:0;color:var(--muted)}.panel{background:var(--white);border:1px solid var(--line);border-radius:14px;overflow:hidden}.toolbar,.panel-head,.panel-foot{display:flex;align-items:center;justify-content:space-between;gap:14px;flex-wrap:wrap}.toolbar{padding:16px 20px;border-bottom:1px solid var(--line);background:#f1f4ed}.scenario,.actions{display:flex;align-items:center;gap:8px}.scenario label{font-size:14px;font-weight:650}.panel-head{padding:24px 22px 8px}.clock{font-family:var(--mono);font-size:14px;color:var(--green);font-weight:650}.chart{padding:10px 22px 22px;--names:148px;--state:70px}.chart-row{display:grid;grid-template-columns:var(--names) minmax(0,1fr) var(--state);align-items:center;column-gap:12px;min-height:55px;border-top:1px solid #e6eae2}.chart-row.axis{border-top:0;min-height:32px}.name strong,.name small{display:block}.name strong{font-size:14px}.name small{font-size:12px;color:var(--muted)}.axis-track,.track{position:relative}.axis-track{height:22px}.tick{position:absolute;transform:translateX(-50%);top:0;color:var(--muted);font:11px/22px var(--mono)}.tick:first-child{transform:none}.tick:last-child{transform:translateX(-100%)}.track{height:20px;background:#f3f5f0;border-radius:3px}.track:before{content:"";position:absolute;inset:0;background:repeating-linear-gradient(90deg,transparent 0 calc(16.6667% - 1px),#dce2d8 calc(16.6667% - 1px) 16.6667%)}.segment{position:absolute;top:2px;bottom:2px}.segment.fresh{background:var(--green-light)}.segment.stale{background:repeating-linear-gradient(135deg,var(--red-light) 0 4px,#f9c9b7 4px 6px)}.beat,.cursor,.instant{position:absolute;transform:translateX(-50%)}.beat{top:5px;width:4px;height:10px;background:#2f4535;border-radius:1px}.cursor{top:-5px;bottom:-5px;width:2px;background:#172a1e}.instant{top:6px;width:8px;height:8px;transform:translateX(-50%) rotate(45deg);background:#a14526;border:1px solid white;z-index:1}.badge{justify-self:end;font:600 10px/1.4 var(--mono);letter-spacing:.03em;text-transform:uppercase;border-radius:4px;padding:4px 7px}.badge.fresh{background:#e5f3e3;color:#245a36}.badge.stale{background:#fff0e9;color:#823c27}.feed-count{justify-self:end;color:var(--muted);font:12px var(--mono)}.panel-foot{border-top:1px solid var(--line);padding:13px 22px;color:var(--muted);font-size:12px}.legend{display:flex;gap:14px;flex-wrap:wrap}.legend span{display:inline-flex;align-items:center;gap:5px}.key{display:inline-block;width:13px;height:9px;border-radius:1px}.key.fresh{background:var(--green-light)}.key.stale{background:repeating-linear-gradient(135deg,var(--red-light) 0 3px,#f9c9b7 3px 5px)}.key.instant-key{width:7px;height:7px;transform:rotate(45deg);background:#a14526}.events{margin-top:23px}.events .panel-head{padding:16px 22px}.events .panel-head span{font:12px var(--mono);color:var(--muted)}table{width:100%;border-collapse:collapse;text-align:left;font-size:14px}th,td{padding:8px 22px;border-top:1px solid #e4e8df}th{font-size:12px;font-weight:600;color:var(--muted);background:#fafbf8}td:first-child{font-family:var(--mono);white-space:nowrap}.state-text{font-weight:650}.state-text.stale{color:var(--red)}.state-text.fresh{color:var(--green)}.empty{margin:0;padding:14px 22px 20px;color:var(--muted);font-size:14px}.note{color:var(--muted);font-size:13px;max-width:88ch;margin:14px 2px}.reader-only{position:absolute;width:1px;height:1px;overflow:hidden;clip-path:inset(50%)}[hidden]{display:none!important}
@media(max-width:670px){main{padding:18px 14px 40px}.intro{padding:25px 0 20px}.toolbar{padding:12px;gap:10px}.scenario,.actions{flex-wrap:wrap}.panel-head,.events .panel-head{padding:16px 12px 7px}.chart{padding:7px 12px 15px;--names:101px;--state:47px}.chart-row{column-gap:7px;min-height:50px}.name strong{font-size:12px}.name small{font-size:11px}.badge{font-size:9px;padding:3px 4px}.panel-foot{padding:12px}.events{margin-top:15px}.events .panel-head{padding-bottom:12px}th,td{padding:8px 12px}.intro p{font-size:15px}.empty{padding:12px}.scenario label{font-size:13px}}
.release-links{display:flex;gap:.45rem 1rem;flex-wrap:wrap;align-items:center;font-size:.95rem}.release-links a,.details a{color:var(--green);text-decoration:underline;text-underline-offset:.2em}.release-links a:focus-visible,.details a:focus-visible{outline:3px solid var(--green);outline-offset:3px}
.details{margin:2.2rem 0 0;border-top:1px solid var(--line);padding-top:1.2rem}.details p{max-width:75ch}.details code{font-family:var(--mono);overflow-wrap:anywhere}
@media(max-width:620px){header{flex-wrap:wrap;gap:.65rem}}
</style>
</head>
<body>
<main>
<header><div class="brand"><svg width="29" height="25" viewBox="0 0 29 25" fill="none" aria-hidden="true"><path d="M1 14h6l4-10 6 17 4-10 2 3h5" stroke="currentColor" stroke-width="2.8" stroke-linejoin="round"/></svg>Pulsefold</div><nav class="release-links" aria-label="Release"><a href="https://huggingface.co/spaces/pgg-engineering/pulsefold/resolve/main/releases/pulsefold-0.1.0.zip">Download source</a><a href="https://huggingface.co/spaces/pgg-engineering/pulsefold/blob/main/results/REPORT.md">Benchmarks</a></nav></header>
<section class="intro"><h1>Heartbeat replay</h1><p>Three subscribers watch one agent. Each chooses how long it can wait for the next heartbeat before the feed goes stale.</p></section>
<section class="panel" aria-labelledby="timeline-title">
<div class="toolbar">
<div class="scenario"><label for="scenario">Feed</label><select id="scenario"><option value="boundary">Four-second gap</option><option value="outage">Long outage</option><option value="steady">Steady heartbeat</option></select></div>
<div class="actions"><button type="button" id="restart">Reset</button><button type="button" id="play" class="primary">Play</button><button type="button" id="step">Step +1 s</button></div>
</div>
<div class="panel-head"><h2 id="timeline-title">Subscriber freshness</h2><output class="clock" id="clock"></output></div>
<div class="chart" id="chart"></div>
<div class="panel-foot"><div class="legend"><span><i class="key fresh"></i>Fresh</span><span><i class="key stale"></i>Stale</span><span><i class="key instant-key"></i>Expired and renewed together</span></div></div>
</section>
<section class="panel events" aria-labelledby="events-title"><div class="panel-head"><h2 id="events-title">Transition log</h2><span id="count"></span></div>
<table id="event-table"><thead><tr><th scope="col">Time</th><th scope="col">Subscriber</th><th scope="col">Transition</th></tr></thead><tbody id="log"></tbody></table><p class="empty" id="empty"></p>
</section>
<p class="note">The first heartbeat arms every subscriber. A deadline that coincides with a heartbeat expires first. Receiving another heartbeat emits a recovery only for subscribers that went stale.</p>
<section class="details"><h2>Run it on your fleet</h2><p>Pulsefold is a single C++17 header. Feeds that use the same deadlines can share one policy, and a receiver can handle a group of expired readers in one callback. The scale test armed 1,048,576 feeds with 1,024 logical watches each at 34.27 MiB peak process memory.</p><p>Unzip the <a href="https://huggingface.co/spaces/pgg-engineering/pulsefold/resolve/main/releases/pulsefold-0.1.0.zip">release</a> and run <code>make check live-check</code>. Run <code>make scale</code> to reproduce the fleet test. The <a href="https://huggingface.co/spaces/pgg-engineering/pulsefold/blob/main/results/REPORT.md">benchmark report</a> includes real sensor timestamps and cases where other schedulers win.</p></section>
<div class="reader-only" id="announcement" role="status"></div>
</main>
<script>
"use strict";
const endTime = 12;
const feeds = {
boundary: [0, 1, 2, 6, 7, 8, 9, 10, 11, 12],
outage: [0, 1, 2, 10, 11, 12],
steady: Array.from({length: endTime + 1}, (_, i) => i)
};
const readers = [
{name: "Live router", budget: 2},
{name: "Coordinator", budget: 4},
{name: "Dashboard", budget: 7}
];
function framesFor(beats) {
let lastBeat = null;
const states = readers.map(() => "pending");
const frames = [];
for (let time = 0; time <= endTime; time++) {
const transitions = [];
readers.forEach(({budget}, i) => {
if (states[i] === "fresh" && lastBeat + budget <= time) {
states[i] = "stale";
transitions.push({time: lastBeat + budget, reader: i, state: "stale"});
}
});
const beat = beats.includes(time);
if (beat) {
states.forEach((state, i) => {
if (state === "stale") transitions.push({time, reader: i, state: "fresh"});
states[i] = "fresh";
});
lastBeat = time;
}
frames.push({time, transitions, beat, states: states.slice()});
}
return frames;
}
const byId = id => document.getElementById(id);
const make = (tag, className = "", content = "") => {
const el = document.createElement(tag);
if (className) el.className = className;
el.textContent = content;
return el;
};
const pct = time => 100 * time / endTime + "%";
let frames = framesFor(feeds.boundary);
let time = 6;
let timer = null;
function addMarker(track, style, position, title) {
const mark = make("i", style);
mark.style.left = pct(position);
if (title) mark.title = title;
track.append(mark);
}
function makeRow(label, subtitle, track, value) {
const row = make("div", "chart-row"), name = make("div", "name");
name.append(make("strong", "", label), make("small", "", subtitle));
row.append(name, track, value);
return row;
}
function render() {
const now = frames.slice(0, time + 1);
const axis = make("div", "chart-row axis"), scale = make("div", "axis-track");
for (let t = 0; t <= endTime; t += 2) {
const tick = make("span", "tick", t + "s");
tick.style.left = pct(t);
scale.append(tick);
}
axis.append(make("span"), scale);
const feedTrack = make("div", "track");
const beats = now.filter(f => f.beat);
beats.forEach(f => addMarker(feedTrack, "beat", f.time, "Heartbeat at " + f.time + " s"));
addMarker(feedTrack, "cursor", time);
const rows = [axis, makeRow("Agent heartbeat", "1 Hz nominal", feedTrack, make("span", "feed-count", beats.length + " seen"))];
readers.forEach((reader, i) => {
const track = make("div", "track");
let start = 0;
for (let t = 1; t <= time; t++) {
if (now[t].states[i] === now[start].states[i] && t !== time) continue;
const part = make("div", "segment " + now[start].states[i]);
part.style.left = pct(start);
part.style.width = pct(t - start);
track.append(part);
start = t;
}
now.forEach(frame => {
const own = frame.transitions.filter(e => e.reader === i);
if (own.length === 2) addMarker(track, "instant", frame.time, "Stale, then fresh at " + frame.time + " s");
});
addMarker(track, "cursor", time);
const state = now[time].states[i];
rows.push(makeRow(reader.name, reader.budget + " s budget", track, make("span", "badge " + state, state)));
});
byId("chart").replaceChildren(...rows);
const events = now.flatMap(f => f.transitions);
const logRows = events.map(e => {
const row = make("tr");
row.append(make("td", "", e.time + " s"), make("td", "", readers[e.reader].name), make("td", "state-text " + e.state, e.state === "stale" ? "Went stale" : "Recovered"));
return row;
});
byId("log").replaceChildren(...logRows);
byId("count").textContent = events.length + (events.length === 1 ? " event" : " events");
byId("event-table").hidden = events.length === 0;
byId("empty").hidden = events.length !== 0;
byId("empty").textContent = "All three subscribers are armed. No deadline has expired.";
byId("clock").textContent = time + " s / " + endTime + " s";
byId("play").textContent = timer !== null ? "Pause" : time === endTime ? "Replay" : "Play";
byId("step").disabled = time === endTime;
byId("restart").disabled = time === 0 && timer === null;
const latest = now[time].transitions.map(e => readers[e.reader].name + " " + e.state);
byId("announcement").textContent = time + " seconds. " + latest.join(". ");
}
function pause() {
if (timer !== null) window.clearInterval(timer);
timer = null;
}
function advance() {
time = Math.min(time + 1, endTime);
if (time === endTime) pause();
render();
}
byId("play").addEventListener("click", () => {
if (timer !== null) pause();
else {
if (time === endTime) time = 0;
timer = window.setInterval(advance, 700);
}
render();
});
byId("step").addEventListener("click", () => { pause(); advance(); });
byId("restart").addEventListener("click", () => { pause(); time = 0; render(); });
byId("scenario").addEventListener("change", event => {
pause();
frames = framesFor(feeds[event.target.value]);
time = 0;
render();
});
render();
</script>
</body>
</html>
|