gitoria

tracker

All repositories: gitoria

ReadmeCodePull requestsReleasesTicketsSettings
Commit52e09eb252e09eb2boot: sync window 1000 ms (the gates ask for a complete start), README boot-time sectionmre52e09eb2/lib/bootscan.hl

6.5 KB

  1. // lib/bootscan.hl — THE BOOT SCANS (tracker.worldapi.org#45, mission 043): ONE streamed pass per big table at start, feeding every
  2. // derived structure that needs that table, instead of one `find(null, null)` per module (each decoded the WHOLE table into one
  3. // array: persons 621 K rows 11 s and 5.6 GB, episodes 1.4 M rows 9 s and +3 GB, five times over; 54 % of the boot was the GC
  4. // pauses those arrays caused — missions/388-trkmem-report.md in the Hybriel repo). `iterate(null, null)` hands the rows out one at a
  5. // time and frees each (but see eachRow: the plugin decodes the file into one native arena first).
  6. //
  7. // titles → catalog.hl (the public lists, genres) shows.hl (slug map) search.hl (title entries, TMDB / TVmaze ids, slugs)
  8. // shortids.hl (owners, queue) people.hl (cast photos)
  9. // episodes → catalog.hl (newest released / upcoming dates)
  10. // people → search.hl (person entries) shortids.hl people.hl (slug map, TMDB ids, /people's order)
  11. //
  12. // Every module keeps its own lazy build (ensureIndex, ensureShortIds, …) built from the SAME per-record functions used here, so a
  13. // tool that imports one module still works; project.hl calls bootScan() once before the first request. The order inside a table is
  14. // the table's, as with the old per-module scans (search entries, short id ownership and the id queue come out the same).
  15. import { now } from 'hl:time'
  16. import { env, setEnv } from 'hl:proc'
  17. import { showsTable, episodesTable, personsTable, noteSlugsOf, markSlugIdsBuilt } from './shows.hl'
  18. import { beginIndex, noteIndexShow, noteIndexEpisode, finishIndex } from './catalog.hl'
  19. import { indexShow, noteIndexPerson, finishSearchIndex } from './search.hl'
  20. import { loadOldShortIds, noteShortIdRow, finishShortIds } from './shortids.hl'
  21. import { noteCastProfiles, markPeopleIndexesBuilt, noteSlugOfPerson, noteTmdbOfPerson, noteViewRow, finishPeopleView } from './people.hl'
  22. import { warm } from './warm.hl'
  23. // THE SCAN IS RESUMABLE (mission T17): `bootStep(budgetMs)` takes rows from the table's cursor until the budget is used up and
  24. // answers true once all three passes are done. project.hl runs it a few seconds before the server is made (a small database is
  25. // then complete at the first request, as always) and goes on from a clock after the server listens, so the first request does not
  26. // wait for the full scan of 2.3 M rows. lib/warm.hl says how far it is (titles → catalog → all); the pages that need more than
  27. // is built show a "starting up" note (components/warm*.hl, the parent of those pages) instead of being built on half a map.
  28. // The rows, the per-row functions and the order are the ones of the former blocking passes: the structures come out the same.
  29. static scanned = { titles = 0 episodes = 0 people = 0 castPhotos = 0 ms = 0 }
  30. static job = { started = false done = false phase = '' cursor = null t0 = 0 tPhase = 0 paced = false }
  31. // Hybriel's collector waits for as much new garbage as the live heap held (HL_GC_PACING 1). The passes allocate fat rows (a title's
  32. // cast + crew) against a small live heap, so it ran 350 times for the titles alone; a higher pacing lets the garbage grow
  33. // to a few hundred MB first. Per pass, sized to what is live then; the operator's own HL_GC_PACING is never touched.
  34. static paceOf = [8, 3, 1, 1]
  35. static pace = (&step) => {
  36. if (job.paced) { setEnv('HL_GC_PACING', '' + paceOf[step]) }
  37. return true
  38. }
  39. static beginScan = (&t) => {
  40. job.started = true
  41. job.t0 = t
  42. job.tPhase = t
  43. job.paced = env('HL_GC_PACING') == null
  44. if (env('TRACKER_GC_PACE') != null) {
  45. let k = 0
  46. for (v of env('TRACKER_GC_PACE').split(',')) { paceOf[k] = toNumber(v) k = k + 1 }
  47. }
  48. warm.running = true
  49. warm.startedAt = t
  50. warm.phase = 'titles'
  51. beginIndex()
  52. loadOldShortIds()
  53. job.phase = 'titles'
  54. job.cursor = showsTable.cursor(null, null)
  55. pace(0)
  56. return true
  57. }
  58. static rowTitle = (&s) => {
  59. noteIndexShow(s)
  60. noteSlugsOf(s)
  61. indexShow(s)
  62. noteShortIdRow('show', s)
  63. scanned.castPhotos = scanned.castPhotos + noteCastProfiles(s)
  64. scanned.titles = scanned.titles + 1
  65. return null
  66. }
  67. static rowEpisode = (&e) => {
  68. noteIndexEpisode(e)
  69. scanned.episodes = scanned.episodes + 1
  70. return null
  71. }
  72. static rowPerson = (&p) => {
  73. noteIndexPerson(p)
  74. noteShortIdRow('person', p)
  75. noteSlugOfPerson(p)
  76. noteTmdbOfPerson(p)
  77. noteViewRow(p)
  78. scanned.people = scanned.people + 1
  79. return null
  80. }
  81. // a pass is out of rows: its closing work (the same calls, in the same order, as the blocking passes made), then the next pass
  82. static endPass = () => {
  83. t = now()
  84. if (job.phase == 'titles') {
  85. markSlugIdsBuilt()
  86. console.log('boot scan: ' + scanned.titles + ' titles in ' + (t - job.tPhase) + ' ms')
  87. warm.titles = true
  88. job.phase = 'episodes'
  89. warm.phase = 'episodes'
  90. job.tPhase = t
  91. job.cursor = episodesTable.cursor(null, null)
  92. pace(1)
  93. } else if (job.phase == 'episodes') {
  94. finishIndex()
  95. console.log('boot scan: ' + scanned.episodes + ' episodes in ' + (t - job.tPhase) + ' ms')
  96. warm.catalog = true
  97. job.phase = 'people'
  98. warm.phase = 'people'
  99. job.tPhase = t
  100. job.cursor = personsTable.cursor(null, null)
  101. pace(2)
  102. } else {
  103. markPeopleIndexesBuilt(scanned.castPhotos)
  104. finishSearchIndex(job.t0)
  105. finishShortIds(job.t0)
  106. finishPeopleView()
  107. console.log('boot scan: ' + scanned.people + ' people in ' + (t - job.tPhase) + ' ms')
  108. // tracker#37's log line (tests/browser.mjs reads it)
  109. console.log('people view: ' + scanned.people + ' people, ' + scanned.castPhotos + ' cast photos in ' + (t - job.tPhase) + ' ms')
  110. scanned.ms = t - job.t0
  111. console.log('boot scan: done in ' + scanned.ms + ' ms')
  112. job.done = true
  113. job.cursor = null
  114. warm.people = true
  115. warm.running = false
  116. warm.phase = 'done'
  117. warm.readyAt = t
  118. pace(3)
  119. }
  120. return true
  121. }
  122. // the scan is under way from here on (warm.running), before the first row — project.hl calls it when the server will listen first
  123. static bootBegin = () => {
  124. if (!job.started) { beginScan(now()) }
  125. return true
  126. }
  127. // rows for up to `budgetMs` (the clock is read every 32 rows); true when the whole scan is done
  128. static bootStep = (&budgetMs) => {
  129. if (job.done) { return true }
  130. t = now()
  131. if (!job.started) { beginScan(t) }
  132. let n = 0
  133. while (!job.done) {
  134. r = job.cursor.next()
  135. if (r == null) { endPass() }
  136. else {
  137. if (job.phase == 'titles') { rowTitle(r) } else if (job.phase == 'episodes') { rowEpisode(r) } else { rowPerson(r) }
  138. n = n + 1
  139. if (n % 32 == 0 && now() - t >= budgetMs) { return false }
  140. }
  141. }
  142. return true
  143. }
  144. // the whole scan at once (tools, and the way every start worked before mission T17)
  145. static bootScan = () => {
  146. bootStep(2000000000)
  147. return scanned
  148. }

Branches

Latest commits

  • 52e09eb2boot: sync window 1000 ms (the gates ask for a complete start), README boot-time sectionmre
  • c87149e8tests/warmstart.mjs: the progressive start proven over HTTP (note in the window, 503 short id, after: everything); bootBeginmre
  • 593a6350boot: resumable start-up scan, the server listens first (T17)mre
  • be4890a0reports: H2 hydration audit (no test change needed)mre
  • 1f9c8bf4re-vendor Hybriel 5406d146 (hl:web batches 9+10: #72 emits while the socket is closed delivered after reconnect, browser boot linear, faster list appends; contains int 6–14 + m406)mre
  • c1df88eddocker-compose: HL_GC_TABLE_LOAD=62 (tracker mission 048, T16 real-data numbers)mre
  • d0a82867mission 048: report, LOG (HL_GC_TABLE_LOAD=62 measured)mre
  • 2d4be66fre-vendor Hybriel 5df4eb7e (GC: HL_GC_TABLE_LOAD knob, mission 406)mre
  • 99e7c8b9tests: realdata-m035-radii, repro-t38, realdata-060-backfill ports from env (REAL_PORT, REAL_CHROME, REPRO_CHROME), defaults unchangedmre
  • 4625aa22re-vendor Hybriel 6f8a0689 (int 6–11: streaming cursors, #203 index heal + close() fix, fd403 listDir/cursor fds, hl:time browser side, hl:web batches 5+6)mre
  • a6dfd6ecdeploy: person-lookup gate (tracker#46)mre
  • 33ad4bd5Merge commit 'f57f64f'mre
  • 7d38cec4docker-compose: nofile 65536 (default soft 1024 refused boot: errno 24 in fs.listDir, Hybriel 528bc89f)mre
  • f57f64f0mission 046: report, LOGmre
  • 5965963adeploy: backup copies index files first and *.mpack data last (hot-copy skew, hybriel #203)mre
  • efe1b485mission 046: re-vendor Hybriel master 60b2817b (integration 8, #203): plugins mpackdb + web (bin/ git-ignored: hybriel, libhlrt.a, hlc.o, hlrt/ from native/zig-out)mre
  • 53099ffbmission 046: person page reads a slim per-title credit row cache (no whole-record fetch per credit); gate tests/person-lookup.mjsmre
  • 9b3828aemission 046a: report, LOGmre
  • 4b37356emission 046: franchise seed supersedeCollections reads the curated timelines once (10 s one-tick block at the end of boot)mre
  • ac6268e3mission 046a: re-vendor Hybriel 528bc89f (integration 6): plugins mpackdb/time/web (bin/ git-ignored)mre