kthwake / index.html
pgg-engineering's picture
Update product artwork and visual presentation
8c5c306 verified
Raw History Blame Contribute Delete
20.5 kB
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta name="color-scheme" content="light">
<meta name="description" content="Explore how a C++17 scheduler turns timestamped events into sliding-window threshold callbacks and wakes on idle expiry.">
<title>KthWake · Sliding-window threshold scheduler</title>
<style>
@font-face {
font-family: "Instrument Sans";
src: url("fonts/instrument-sans.woff2") format("woff2");
font-style: normal;
font-weight: 400 700;
font-display: swap;
}
@font-face {
font-family: "IBM Plex Mono";
src: url("fonts/ibm-plex-mono.woff2") format("woff2");
font-weight: 400;
font-style: normal;
font-display: swap;
}
:root {
color-scheme: light;
--paper: #FAFAFA; --ink: #141619; --blue: #315BFF; --muted: #555C65;
--rule: #DADDE1;
--sans: "Instrument Sans", system-ui, "Helvetica Neue", Arial, sans-serif;
--mono: "IBM Plex Mono", ui-monospace, SFMono-Regular, Consolas, monospace;
}
* { box-sizing: border-box; }
body { margin: 0; background: var(--paper); color: var(--ink); font: 16px/1.5 var(--sans); }
main,header,footer { width: min(1120px,calc(100% - 64px)); margin-inline: auto; }
header,.brand,.topnav,.top,.trace-head,.range-head,.release-links,.buttons,.legend,.legend span { display: flex; align-items: center; }
header { min-height: 66px; justify-content: space-between; gap: 12px; border-bottom: 1px solid var(--rule); }
.brand { font-weight: 650; font-size: 1.13rem; letter-spacing: -.025em; }
.topnav,.release-links,.buttons,.legend { gap: 8px 17px; flex-wrap: wrap; }
a { color: var(--ink); text-underline-offset: .18em; }
a:hover { text-decoration-thickness: 2px; }
.topnav a { color: var(--ink); font-size: .92rem; font-weight: 550; }
.hero { display: grid; grid-template-columns: 1fr 1.2fr; gap: clamp(20px,5vw,66px); align-items: end; padding: clamp(26px,4vw,52px) 0 34px; }
.hero .category { margin: 0 0 10px; font: 450 .82rem/1.4 var(--mono); color: var(--muted); }
h1,h2,h3,p,dl { margin: 0; }
.hero h1 { font-size: clamp(2.1rem,3.75vw,3.5rem); line-height: 1.06; letter-spacing: -.045em; font-weight: 550; }
.hero .intro { max-width: 60ch; color: var(--muted); }
.grid { display: grid; grid-template-columns: minmax(0,1fr) 270px; gap: 18px; align-items: start; }
.panel { border-block: 1px solid var(--rule); }
.top,.trace-head,.aside,.playbar,.release { padding: 15px 20px; }
.top,.trace-head,.range-head { justify-content: space-between; gap: 12px; }
.top,.trace-head { border-bottom: 1px solid var(--rule); }
h2 { font-size: 1.28rem; font-weight: 575; letter-spacing: -.025em; line-height: 1.2; }
.clock,.counter,.label,.legend,.status,output,td,.code,.snippet { font-family: var(--mono); }
.clock,.counter,.label,.legend { font-size: .77rem; }
.plot { padding: 5px 10px 0; }
.state-marker { transform-box: fill-box; transform-origin: center; }
.plot svg { width: 100%; height: auto; display: block; }
.legend { padding: 0 18px 12px; }
.legend span { gap: 6px; }
.mark { width: 9px; height: 9px; border: 1px solid var(--ink); background: var(--muted); border-radius: 50%; }
.bar { width: 15px; height: 3px; background: var(--ink); }
.needle { height: 12px; border-left: 2px dashed var(--ink); }
.readout { padding: 10px 18px; border-block: 1px solid var(--rule); }
input[type=range] { width: 100%; margin: 9px 0 15px; accent-color: var(--blue); cursor: pointer; }
.range-head output { font-weight: bold; }
.buttons { gap: 7px; }
button,input,textarea { font: inherit; }
button,.download { min-height: 40px; padding: 8px 12px; background: var(--paper); color: var(--ink); border: 1px solid var(--muted); border-radius: 3px; font-size: .91rem; font-weight: 650; cursor: pointer; }
button.primary { background: var(--ink); color: var(--paper); }
button:hover:enabled { color: var(--ink); background: var(--rule); }
button.primary:hover:enabled { background: var(--muted); color: var(--paper); }
button:disabled { opacity: .52; cursor: default; }
:is(button,input,textarea,summary,a):focus-visible { outline: 2px solid var(--blue); outline-offset: 3px; }
.aside { border-left: 1px solid var(--rule); }
.clock,.counter,.label,.legend,.hint,.stat dt,details p,footer { color: var(--muted); }
.aside h2 { margin-bottom: 15px; }
.fields { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.field { display: flex; flex-direction: column; gap: 4px; margin-bottom: 13px; }
.field label { font-size: .85rem; }
input[type=number],textarea { display: block; width: 100%; min-height: 40px; padding: 7px 9px; border: 1px solid var(--muted); border-radius: 3px; font: .91rem/1.45 var(--mono); color: var(--ink); background: var(--paper); }
textarea { resize: vertical; }
.hint,.errors { margin: 9px 0 0; font-size: .83rem; }
.errors { padding-left: 8px; border-left: 2px solid var(--ink); font-weight: 550; }
.summary { display: grid; grid-template-columns: repeat(3,minmax(0,1fr)); border-top: 1px solid var(--rule); }
.stat { padding: 10px 14px; }
.stat + .stat { border-left: 1px solid var(--rule); }
.stat dt { font-size: .79rem; }
.stat dd { margin: 2px 0 0; font: 600 1.16rem/1.4 var(--mono); }
.stat .on { color: var(--blue); }
.state-up { font-weight: 650; }
.trace,.release { margin-top: 20px; }
table { width: 100%; border-collapse: collapse; font-size: .87rem; text-align: left; }
th,td { padding: 7px 18px; border-bottom: 1px solid var(--rule); }
th { font-weight: 600; }
.trace-empty,details { padding: 10px 18px; }
details { border-top: 1px solid var(--rule); font-size: .91rem; }
summary { cursor: pointer; }
details p,.release p { margin: 8px 0; max-width: 78ch; }
.code,.snippet { display: block; white-space: pre-wrap; overflow-wrap: anywhere; margin: 8px 0; padding: 10px 13px; background: transparent; border: 1px solid var(--rule); font-size: .86rem; }
.release h3 { margin: 19px 0 0; font-size: 1.1rem; }
.release-links { margin-block: 8px; font-size: .9rem; }
footer { margin-top: 24px; padding: 16px 0 26px; border-top: 1px solid var(--rule); font-size: .85rem; }
.a11y { position: absolute; width: 1px; height: 1px; margin: -1px; overflow: hidden; clip-path: inset(50%); }
[hidden] { display: none !important; }
@media(max-width:780px) {
main,header,footer { width: calc(100% - 30px); }
header { padding: 8px 0; }
.topnav { gap: 6px 12px; justify-content: flex-end; }
.topnav a { font-size: .84rem; }
.hero,.grid { grid-template-columns: 1fr; }
.aside { border-left: 0; }
.hero { gap: 12px; }
.top,.trace-head,.aside,.playbar,.release { padding-inline: 12px; }
.legend { padding-inline: 12px; }
.stat { padding: 8px; }
.stat dt { font-size: .73rem; }
th,td { padding: 6px 10px; }
}
</style>
</head>
<body>
<header><div class="brand">KthWake</div><nav class="topnav" aria-label="Project"><a href="https://github.com/pgg898200-ship-it/chronosieve/tree/7cca93890a5bfa1e120f6aaabda8d1b8d7957b1f/companions/kthwake">Source</a><a href="#release">Use in your scheduler ↓</a></nav></header>
<main>
<section class="hero">
<div><p class="category">Sliding-window threshold scheduler</p><h1>Wake on the third result.</h1></div>
<p class="intro">Give KthWake an ordered stream of tool completions. It tells your event loop when a rule turns on and when it will turn off if no more results arrive.</p>
</section>
<div class="grid">
<div class="panel">
<div class="top"><h2>Tool completion timeline</h2><span class="clock">Rule #0</span></div>
<div class="plot"><svg id="chart" viewBox="0 0 680 172" role="img" aria-labelledby="svg-title svg-description"><title id="svg-title">Arrivals and callback state over time</title><desc id="svg-description"></desc><g id="plot"></g></svg></div>
<div class="legend"><span><i class="mark"></i>Arrival</span><span><i class="bar"></i>Threshold met</span><span><i class="needle"></i>Clock</span></div>
<p id="readout" class="readout"></p>
<div class="playbar">
<div class="range-head"><label class="label" for="clock">Replay time</label><output id="clock-out" for="clock"></output></div>
<input id="clock" type="range" min="0" step="1" value="5" max="26">
<div class="buttons"><button class="primary" type="button" id="next">Next callback →</button><button type="button" id="tick">+1 ms</button><button type="button" id="push">Add arrival now</button></div>
</div>
<dl class="summary"><div class="stat"><dt>Window count</dt><dd id="count"></dd></div><div class="stat"><dt>Threshold met</dt><dd id="state"></dd></div><div class="stat"><dt>Clears if idle</dt><dd id="expiry"></dd></div></dl>
</div>
<form id="configure" class="panel aside">
<h2>Edit the rule</h2>
<div class="fields"><div class="field"><label for="k">Results required</label><input id="k" type="number" min="1" max="256" step="1" value="3" required></div>
<div class="field"><label for="w">Window (ms)</label><input id="w" type="number" min="1" max="100000" step="1" value="20" required></div></div>
<div class="field"><label for="arrivals">Completion times (ms)</label><textarea id="arrivals" rows="2" spellcheck="false">0, 0, 5</textarea></div>
<p class="errors" id="error" role="alert" hidden></p>
<div class="buttons"><button type="submit">Apply trace</button><button type="button" class="quiet" id="reset">Reset example</button></div>
<p class="hint">Separate times with commas. Repeat a time for results that finish together.</p>
</form>
</div>
<section class="panel trace"><div class="trace-head"><h2>Callback log</h2><span id="total" class="counter"></span></div>
<table id="log"><thead><tr><th scope="col">Time (ms)</th><th scope="col">State</th><th scope="col">Trigger</th></tr></thead><tbody></tbody></table><p class="trace-empty" id="empty" hidden>No callbacks through this tick.</p>
<details><summary>Read callback log as JSONL</summary><pre class="snippet"><code id="jsonl"></code></pre></details>
<details><summary>Drive the C++ index</summary><p>Pass each timestamp’s arrivals together. Use the next expiry to drive the clock during idle periods. At a shared timestamp, a single step applies expirations and arrivals before reporting changes.</p><code class="code">index.step(t, arrivals, callback);<br>auto deadline = index.next_expiry();</code></details>
</section>
<section class="panel release" id="release" aria-labelledby="release-title">
<h2 id="release-title">Use KthWake in your event loop</h2>
<p>Put one index after an ordered event stream. Pass the arrival count to <code>step</code>, dispatch the changed rule IDs, and arm one timer for the next idle deadline.</p>
<div class="release-links"><a class="download" href="https://raw.githubusercontent.com/pgg898200-ship-it/chronosieve/f6df7cdb54362fea22003a814ac83fcc7b179a8f/companions/kthwake/downloads/v0.1.0/kthwake-0.1.0.tar.gz" download>Download source v0.1.0 ↓</a><a href="https://raw.githubusercontent.com/pgg898200-ship-it/chronosieve/f6df7cdb54362fea22003a814ac83fcc7b179a8f/companions/kthwake/downloads/v0.1.0/kthwake.hpp" download>Download kthwake.hpp</a><a href="https://raw.githubusercontent.com/pgg898200-ship-it/chronosieve/f6df7cdb54362fea22003a814ac83fcc7b179a8f/companions/kthwake/downloads/v0.1.0/kthwake-linux-x86_64" download>Linux x86-64 CLI</a><a href="https://raw.githubusercontent.com/pgg898200-ship-it/chronosieve/f6df7cdb54362fea22003a814ac83fcc7b179a8f/companions/kthwake/downloads/v0.1.0/kthwake-0.1.0-cp312-cp312-linux_x86_64.whl" download>CPython 3.12 Linux wheel</a></div>
<h3>37.1 ms for 330,890 transitions</h3><p>On a held-out Azure trace with 4,096 modeled individual-rate policies, the fastest tested alternative took 75.0 ms. A dedicated heap won the other two Azure timer workloads. <a href="https://github.com/pgg898200-ship-it/chronosieve/blob/7cca93890a5bfa1e120f6aaabda8d1b8d7957b1f/companions/kthwake/EVIDENCE.md">Inspect all results</a>.</p>
<h3>Run the example</h3><p>In the extracted source directory, run the bundled trace through the native CLI.</p>
<pre class="snippet"><code>make example</code></pre>
<div class="release-links"><a href="https://github.com/pgg898200-ship-it/chronosieve/blob/7cca93890a5bfa1e120f6aaabda8d1b8d7957b1f/companions/kthwake/EVIDENCE.md">Benchmark results and limits ↗</a><a href="https://github.com/pgg898200-ship-it/chronosieve/tree/releases/kthwake-0.1.0/companions/kthwake#use-from-python">Python and C++ integration ↗</a><a href="https://raw.githubusercontent.com/pgg898200-ship-it/chronosieve/f6df7cdb54362fea22003a814ac83fcc7b179a8f/companions/kthwake/downloads/v0.1.0/SHA256SUMS">SHA-256 checksums</a><a href="https://github.com/pgg898200-ship-it/chronosieve/blob/7cca93890a5bfa1e120f6aaabda8d1b8d7957b1f/companions/kthwake/REPRODUCE.md">Share an independent result</a></div>
</section>
<div class="a11y" id="announcement" role="status" aria-live="polite"></div>
</main>
<footer>Interactive JavaScript illustration of the C++ index’s semantics. The explorer uses milliseconds. The native index accepts any consistent integer time unit. At tick t, the window includes arrivals after t − W through t. Runtime measurements belong to the native benchmark.</footer>
<script>
'use strict';
const byId = id => document.getElementById(id);
const initial = {k:3, w:20, times:[0,0,5], now:5};
let config = {...initial, times:[...initial.times]};
let transitions = [];
let horizon = 0;
let previousState = null;
const MAX_EVENTS = 256, MAX_TICK = 100000;
function calculateTrace(times,k,w) {
const changes = new Map();
for (const t of times) {
for(const [tick,field] of [[t,'in'],[t+w,'out']]) {
if (!changes.has(tick)) changes.set(tick,{in:0,out:0});
changes.get(tick)[field]++;
}
}
let count = 0;
const result = [];
for (const t of [...changes.keys()].sort((a,b)=>a-b)) {
const batch = changes.get(t), before = count>=k;
count += batch.in - batch.out;
if ((count>=k)!==before) result.push({t,on:count>=k,in:batch.in,out:batch.out});
}
return result;
}
function reindex() {
transitions = calculateTrace(config.times,config.k,config.w);
horizon = Math.max(config.w+1,(config.times.at(-1) ?? 0)+config.w+1,config.now);
byId('clock').max = String(horizon);
}
function svg(tag,attrs,content) {
const el=document.createElementNS('http://www.w3.org/2000/svg',tag);
for (const [k,v] of Object.entries(attrs)) el.setAttribute(k,String(v));
if (content!==undefined) el.textContent=String(content);
byId('plot').append(el);
return el;
}
function draw() {
byId('plot').replaceChildren();
const width = Math.max(290,Math.round(byId('chart').getBoundingClientRect().width));
const right=width-18, left=15, x=t=>left+(right-left)*t/horizon;
const ink='#141619', arrival='#555C65', soft='#555C65', line='#DADDE1', selected='#315BFF';
byId('chart').setAttribute('viewBox',`0 0 ${width} 172`);
const label=(tx,ty,s,anchor='start')=>svg('text',{x:tx,y:ty,fill:soft,'font-size':10,'font-family':'monospace','text-anchor':anchor},s);
for (let i=0;i<=4;i++) {
const tick=Math.round(i*horizon/4);
if(i>0 && tick===Math.round((i-1)*horizon/4)) continue;
svg('line',{x1:x(tick),x2:x(tick),y1:16,y2:145,stroke:line,'stroke-dasharray':'2 4'});
label(x(tick),161,tick,i===0?'start':i===4?'end':'middle');
}
svg('rect',{x:x(Math.max(0,config.now-config.w)),y:9,width:Math.max(0,x(config.now)-x(Math.max(0,config.now-config.w))),height:128,fill:ink,opacity:.055});
label(left,20,'COMPLETIONS');label(left,88,'STATE');
svg('line',{x1:left,x2:right,y1:52,y2:52,stroke:line});
const groups=new Map();
for(const t of config.times) groups.set(t,(groups.get(t)||0)+1);
for(const [t,n] of groups) {
const past=t<=config.now, cx=x(t);
svg('line',{x1:cx,x2:cx,y1:52,y2:59,stroke:arrival,opacity:past?1:.45});
for(let j=0;j<Math.min(3,n);j++)
svg('circle',{cx,cy:49-j*7,r:3.4,fill:past?arrival:'#FAFAFA',stroke:arrival,opacity:past?1:.65});
}
function stepPath(start,end) {
let on=false;
for(const c of transitions) if(c.t<=start) on=c.on;
const y=s=>s?101:131;
let path=`M${x(start)} ${y(on)}`;
for(const c of transitions) if(c.t>start && c.t<=end) path+=` H${x(c.t)} V${y(c.on)}`;
return path+` H${x(end)}`;
}
svg('path',{d:stepPath(0,config.now),stroke:ink,'stroke-width':2.6,fill:'none'});
svg('path',{d:stepPath(config.now,horizon),stroke:ink,'stroke-width':1.6,fill:'none',opacity:.68,'stroke-dasharray':'4 4'});
const cx=x(config.now);
svg('line',{x1:cx,x2:cx,y1:4,y2:145,stroke:selected,'stroke-dasharray':'3 4'});
svg('path',{d:`M${cx-3.5} 3h7l-3.5 5z`,fill:selected});
const active = transitions.filter(change => change.t <= config.now).at(-1)?.on;
return svg('circle', {cx, cy: active ? 101 : 131, r: 4, fill: selected,
stroke: '#FAFAFA', 'stroke-width': 1.5, class: 'state-marker'});
}
function render() {
const {times,k,w,now}=config;
const windowTimes=times.filter(t=>t<=now&&t>now-w), on=windowTimes.length>=k;
const deadline=on?windowTimes[windowTimes.length-k]+w:null;
const history=transitions.filter(c=>c.t<=now);
byId('clock').value=now;
byId('clock-out').textContent=now+' ms';
byId('count').textContent=windowTimes.length;
byId('state').textContent=on?'true':'false';
byId('state').classList.toggle('on',on);
byId('expiry').textContent=deadline===null?'—':deadline+' ms';
const rule = k+' or more results in '+w+' ms';
byId('readout').textContent=on
? 'Rule met · '+rule+'. With no more completions, the callback clears at '+deadline+' ms.'
: 'Waiting for '+rule+'. '+windowTimes.length+' in the window now.';
byId('jsonl').textContent=history.map(c=>JSON.stringify({t:c.t,id:0,active:c.on})).join('\n');
byId('expiry').title='Tick when the threshold clears if no more arrivals occur';
byId('total').textContent=history.length+' through '+now+' ms';
byId('next').disabled=!transitions.some(c=>c.t>now);
byId('tick').disabled=now>=horizon;
byId('push').disabled=now>MAX_TICK||times.length>=MAX_EVENTS;
byId('empty').hidden=history.length!==0;
byId('log').hidden=!history.length;
const tbody=byId('log').tBodies[0];tbody.replaceChildren();
for(const c of history.slice().reverse()){
const tr=tbody.insertRow();
tr.insertCell().textContent=c.t;
const state=tr.insertCell();state.textContent=c.on?'true':'false';state.className=c.on?'state-up':'state-down';
tr.insertCell().textContent=c.in&&c.out?'Arrival + expiry':c.in?'Arrival':'Idle expiry';
}
const desc=`At ${now} ms, ${windowTimes.length} arrivals are in the window. The threshold is ${on?'met':'unmet'}. ${history.length} callbacks so far.`;
byId('svg-description').textContent=desc+' Dotted state segments preview the scheduled input.';
byId('announcement').textContent=desc;
const marker = draw();
// Connect the state change to its location on the time axis.
if (previousState !== null && previousState !== on && typeof marker.animate === 'function' &&
window.matchMedia && !window.matchMedia('(prefers-reduced-motion: reduce)').matches) {
marker.animate([{ transform: 'scale(2)' }, { transform: 'scale(1)' }], {
duration: 250, easing: 'ease-out'
});
}
previousState = on;
}
function setNow(t){config.now=t;render();}
function fields(){byId('k').value=config.k;byId('w').value=config.w;byId('arrivals').value=config.times.join(', ');}
function showError(message=''){byId('error').textContent=message;byId('error').hidden=!message;}
byId('configure').addEventListener('submit',e=>{
e.preventDefault();
const raw=byId('arrivals').value.trim();
const items=raw===''?[]:raw.split(/[\s,]+/);
if(items.length>MAX_EVENTS || items.some(t=>!/^\d+$/.test(t)||!Number.isSafeInteger(Number(t))||Number(t)>MAX_TICK)){
showError('Enter up to 256 whole-number completion times from 0 to 100000 ms.');return;
}
showError();
config={k:Number(byId('k').value), w:Number(byId('w').value),times:items.map(Number).sort((a,b)=>a-b),now:0};
fields();reindex();render();
});
byId('clock').addEventListener('input',e=>setNow(Number(e.target.value)));
byId('tick').addEventListener('click',()=>setNow(Math.min(horizon,config.now+1)));
byId('next').addEventListener('click',()=>{const next=transitions.find(c=>c.t>config.now);if(next)setNow(next.t);});
byId('push').addEventListener('click',()=>{config.times.push(config.now);config.times.sort((a,b)=>a-b);fields();showError();reindex();render();});
byId('reset').addEventListener('click',()=>{config={...initial,times:[...initial.times]};fields();showError();reindex();render();});
window.addEventListener('resize',draw);
reindex();render();
</script>
</body></html>