tracker
All repositories: gitoria
3.7 KB
// lib/slices.hl — SLICED TABLE SCANS for the background jobs (mission 044, trkmem 388: `find(null, null)` decodes EVERY row of a table// into one array — persons 621 K rows 11 s / 5.6 GB, episodes 1.4 M 9 s — and `iterate(null, null)` is eager too: the plugin's// find_all reads + decodes the whole file in ONE native call, so neither can be paused). The single-threaded server stalls for the// whole scan (page loads of 19–28 s). A SLICE here is a primary-key RANGE (`range('id', from, to)`: the in-RAM index is searched, only// the rows of that range are read + decoded): 256 slices by the first two hex digits of the key (ids are 16 hex chars, util.hl// newId); the bounds are inclusive, so a row whose key is exactly the upper bound is left to the next slice (its lower bound is// inclusive) — the 256 slices partition the table exactly (any key, hex or not: the first slice is open below, the last open above).// A scan keeps only its cursor; a job takes slices on its timer tick until its time budget (sliceBudgetMs) is spent, then the// event loop serves the pages. Order: key order (the full scans gave file order).import { now } from 'hl:time'import { env } from 'hl:proc'static sliceBudgetMs = env('TRACKER_SLICE_MS') != null ? toNumber(env('TRACKER_SLICE_MS')) : 15static hexDigits = '0123456789abcdef'// the key bound of slice k (1 … n-1) as `depth` hex digits; the first slice has no lower bound, the last none abovestatic sliceBound = (&k, &depth) => {let out = ''let v = klet i = 0while (i < depth) {out = hexDigits.slice(v % 16, v % 16 + 1) + outv = (v - v % 16) / 16i = i + 1}return out}// a scan of one table (nothing is read yet): 256 slices (2 hex digits), 4096 (3 digits) for a table of more than 200 K rows (persons// 621 K, episodes 1.4 M: ~2.4 K / 5.5 K rows per 2-digit slice would be a 25–40 ms block, ~150 / 350 per 3-digit slice a few ms)static sliceScan = (table) => {depth = env('TRACKER_SLICE_DEPTH') != null ? toNumber(env('TRACKER_SLICE_DEPTH')) : (table.count() > 200000 ? 3 : 2)return { table = table k = 0 depth = depth n = depth == 3 ? 4096 : 256 rows = 0 slices = 0 skipped = 0 }}static sliceDone = (&scan) => { return scan.k >= scan.n }// the rows of the next slice (an array, may be empty); null once the scan is finishedstatic sliceNext = (&scan) => {if (scan.k >= scan.n) { return null }lo = scan.k == 0 ? null : sliceBound(&scan.k, &scan.depth)hi = scan.k + 1 >= scan.n ? null : sliceBound(scan.k + 1, &scan.depth)out = []for (r of scan.table.range('id', lo, hi)) {// mission 045 guard: range() on the real persons table answered Numbers, not rows (Hybriel bug, Anton fixing): skip + count themif (hlTypeName(r) != 'Hybrid') { scan.skipped = scan.skipped + 1 }else if (hi == null || r.id != hi) { out.push(r) }}scan.k = scan.k + 1scan.rows = scan.rows + out.lengthscan.slices = scan.slices + 1return out}// ---- a sliced collection of the ids a job needs (only the ids are kept, never the rows) ---------------------------------------// pred(row) → true / 1: the id goes to `out`; 2: to `rest` (the details repair's second class); anything else: skippedstatic collectStart = (table) => { return { scan = sliceScan(table) out = [] rest = [] ms = 0 at = now() } }// takes slices until the budget is spent; true when the table is donestatic collectStep = (&c, pred) => {t0 = now()while (!sliceDone(&c.scan)) {for (r of sliceNext(&c.scan)) {v = pred(r)if (v == true || v == 1) { c.out.push(r.id) } else if (v == 2) { c.rest.push(r.id) }}if (now() - t0 >= sliceBudgetMs) { break }}c.ms = c.ms + (now() - t0)return sliceDone(&c.scan)}// the queue: out, then reststatic collected = (&c) => {for (id of c.rest) { c.out.push(id) }c.rest = []return c.out}
Branches
Latest commits
- c7cdef62Log: Apollo STOP, workers pausedmre
- d0c083fbLog: usage stopmre
- c6d464e5Log: Apollo GO backlog, AP56 and BS1 startedmre
- 1eb6f1a1Missions AP56, BS1mre
- 4871f8adLog: AP52 live on day52, browser gate greenmre
- d9bf2988Merge ap52: day52, tracker#58 server argument, #51 modal close rule, #56 keyed season rowsmre
- c4a60ef2Log: RT52 retest passed, AP52 startedmre
- 83760a55Browser gate: search results belong to the address form of the typed text (tracker#52 navigate replace)mre
- 6e951d91AP52: show-page rows are keyed records; closing a season is one upsert and removes (tracker#56, hybriel#331)mre
- 3bb4ccddAP52: modal close button refers to its nested rule with Style.buttonModalX (tracker#51, hybriel#333)mre
- ba16933fAP52: login callback and title route are static handlers taking the server as third argument (tracker#58, hybriel#332)mre
- 85153900AP52: re-vendor Hybriel set day52 (source 77cfca31, bin 0a8ed496)mre
- 7c051eddLog: hybriel#338 answermre
- d049b8b8Log: HM50 live, #52 donemre
- 6d05fa37Log: HM50 Part A mergedmre
- 1c7dab74HM50: the shell reads the framework's online state, netProbe removed (tracker#55)mre
- e8b91697HM50: search address follows the text via navigate(path, replace = true) (tracker#52)mre
- 6fe1896cHM50: re-vendor Hybriel set day50 (source 0ae38232, bin d3ef9d16)mre
- 2f391aa9Log: HM50 startedmre
- 4b59c03dHM50 mission: doc pathmre