gitoria

tracker

All repositories: gitoria

ReadmeCodePull requestsReleasesTicketsSettings
Commit3db7dc313db7dc31merge w44-jobs-slices into w43-trkmemmre3db7dc31/lib/slices.hl

3.5 KB

  1. // lib/slices.hl — SLICED TABLE SCANS for the background jobs (mission 044, trkmem 388: `find(null, null)` decodes EVERY row of a table
  2. // 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
  3. // find_all reads + decodes the whole file in ONE native call, so neither can be paused). The single-threaded server stalls for the
  4. // 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
  5. // 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
  6. // 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
  7. // inclusive) — the 256 slices partition the table exactly (any key, hex or not: the first slice is open below, the last open above).
  8. // A scan keeps only its cursor; a job takes slices on its timer tick until its time budget (sliceBudgetMs) is spent, then the
  9. // event loop serves the pages. Order: key order (the full scans gave file order).
  10. import { now } from 'hl:time'
  11. import { env } from 'hl:proc'
  12. static sliceBudgetMs = env('TRACKER_SLICE_MS') != null ? toNumber(env('TRACKER_SLICE_MS')) : 15
  13. static hexDigits = '0123456789abcdef'
  14. // the key bound of slice k (1 … n-1) as `depth` hex digits; the first slice has no lower bound, the last none above
  15. static sliceBound = (&k, &depth) => {
  16. let out = ''
  17. let v = k
  18. let i = 0
  19. while (i < depth) {
  20. out = hexDigits.slice(v % 16, v % 16 + 1) + out
  21. v = (v - v % 16) / 16
  22. i = i + 1
  23. }
  24. return out
  25. }
  26. // 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
  27. // 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)
  28. static sliceScan = (table) => {
  29. let depth = env('TRACKER_SLICE_DEPTH') != null ? toNumber(env('TRACKER_SLICE_DEPTH')) : (table.count() > 200000 ? 3 : 2)
  30. return { table = table k = 0 depth = depth n = depth == 3 ? 4096 : 256 rows = 0 slices = 0 }
  31. }
  32. static sliceDone = (&scan) => { return scan.k >= scan.n }
  33. // the rows of the next slice (an array, may be empty); null once the scan is finished
  34. static sliceNext = (&scan) => {
  35. if (scan.k >= scan.n) { return null }
  36. lo = scan.k == 0 ? null : sliceBound(scan.k, scan.depth)
  37. hi = scan.k + 1 >= scan.n ? null : sliceBound(scan.k + 1, scan.depth)
  38. out = []
  39. for (r of scan.table.range('id', lo, hi)) { if (hi == null || r.id != hi) { out.push(r) } }
  40. scan.k = scan.k + 1
  41. scan.rows = scan.rows + out.length
  42. scan.slices = scan.slices + 1
  43. return out
  44. }
  45. // ---- a sliced collection of the ids a job needs (only the ids are kept, never the rows) ---------------------------------------
  46. // pred(row) → true / 1: the id goes to `out`; 2: to `rest` (the details repair's second class); anything else: skipped
  47. static collectStart = (table) => { return { scan = sliceScan(table) out = [] rest = [] ms = 0 at = now() } }
  48. // takes slices until the budget is spent; true when the table is done
  49. static collectStep = (&c, pred) => {
  50. t0 = now()
  51. while (!sliceDone(c.scan)) {
  52. for (r of sliceNext(c.scan)) {
  53. v = pred(r)
  54. if (v == true || v == 1) { c.out.push(r.id) } else if (v == 2) { c.rest.push(r.id) }
  55. }
  56. if (now() - t0 >= sliceBudgetMs) { break }
  57. }
  58. c.ms = c.ms + (now() - t0)
  59. return sliceDone(c.scan)
  60. }
  61. // the queue: out, then rest
  62. static collected = (&c) => {
  63. for (id of c.rest) { c.out.push(id) }
  64. c.rest = []
  65. return c.out
  66. }

Branches

Latest commits

  • 3db7dc31merge w44-jobs-slices into w43-trkmemmre
  • 593dab6fmission 043: report, LOGmre
  • 1a5a4818boot scans back to iterate (slices measured slower: titles 114 s, episodes 141 s, persons failed); lambda per rowmre
  • 03d29893boot scans read primary-key slices (lib/slices.hl from mission 044): iterate is eager too; people view log line back; allShows/allEpisodes stay for toolsmre
  • 23375c58mission 044: report, LOG, STATUSmre
  • c6fd928emission 044: 4096 slices for tables over 200 K rows, 15 ms budget, TRACKER_SLICE_DEPTH for testsmre
  • fb057680mission 044: jobs.hl imports mergeLeft (gate found it), mission file, slices benchmre
  • 0d6293ebmission 043: mission filemre
  • d25bd14amission 044: sliced merge prepare + sliced collections prepare; jobs-dump old/new check + bulk fixturemre
  • 633ee210mission 044: sliced table scans (slices.hl, pk-range slices) for the adult/kind/status/art/credits/details-repair queuesmre
  • 55bbd619boot: one streamed pass per table (lib/bootscan.hl) instead of find(null,null) per module; follows/watches/franchises scans streammre
  • 1d465d3ere-vendor plugins to Hybriel master f9614007 (mpackdb #202 copy fix, libmpackdb sha 6fb3b9d6)mre
  • 6648ba44mission 042: real-browser E2E on ce6f2e0a re-vendor 69/0 at 390 + 1280mre
  • 3ed3a0efmission 042: gates old/new equal (browser #41 route-table regex accepts unescaped hl:web output), real-data TTFB, E2E blocked by lisbeth lockmre
  • d5b61e90LOG 042mre
  • 4acdbaccmission 042: memory comparison old vs ce6f2e0a (stopped: warm VmHWM higher), reportmre
  • d0f620d6mission 042: re-vendor Hybriel ce6f2e0a (plugins incl. mpackdb; bin runtime built from the same archive, git-ignored), compact=false keptmre
  • 5bd14e12mission 040: theme 76f99f6 gates + E2E green; 44 px fixes (skeleton row, type-word, genre-link/pill); README, reportmre
  • 77cfa45cmission 040: partial report (theme/modal/pagination re-copied, tilelist onPage, 44 px taps; gates new + E2E pending)mre
  • 4b14822fe2e-theme: menu marker by colourmre