gitoria

tracker

All repositories: gitoria

ReadmeCodePull requestsReleasesTicketsSettings
Commit5525785255257852log: #53 live, #56 mergedmre55257852/lib/bootscan.hl

6.4 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 (/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, 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. noteViewRow(&p)
  76. scanned.people = scanned.people + 1
  77. return null
  78. }
  79. // 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
  80. static endPass = () => {
  81. t = now()
  82. if (job.phase == 'titles') {
  83. markSlugIdsBuilt()
  84. console.log('boot scan: ' + scanned.titles + ' titles in ' + (t - job.tPhase) + ' ms')
  85. warm.titles = true
  86. job.phase = 'episodes'
  87. warm.phase = 'episodes'
  88. job.tPhase = t
  89. job.cursor = episodesTable.cursor(null, null)
  90. pace(1)
  91. } else if (job.phase == 'episodes') {
  92. finishIndex()
  93. console.log('boot scan: ' + scanned.episodes + ' episodes in ' + (t - job.tPhase) + ' ms')
  94. warm.catalog = true
  95. job.phase = 'people'
  96. warm.phase = 'people'
  97. job.tPhase = t
  98. job.cursor = personsTable.cursor(null, null)
  99. pace(2)
  100. } else {
  101. markPeopleIndexesBuilt(&scanned.castPhotos)
  102. finishSearchIndex(&job.t0)
  103. finishShortIds(&job.t0)
  104. finishPeopleView()
  105. console.log('boot scan: ' + scanned.people + ' people in ' + (t - job.tPhase) + ' ms')
  106. // tracker#37's log line (tests/browser.mjs reads it)
  107. console.log('people view: ' + scanned.people + ' people, ' + scanned.castPhotos + ' cast photos in ' + (t - job.tPhase) + ' ms')
  108. scanned.ms = t - job.t0
  109. console.log('boot scan: done in ' + scanned.ms + ' ms')
  110. job.done = true
  111. job.cursor = null
  112. warm.people = true
  113. warm.running = false
  114. warm.phase = 'done'
  115. warm.readyAt = t
  116. pace(3)
  117. }
  118. return true
  119. }
  120. // the scan is under way from here on (warm.running), before the first row — project.hl calls it when the server will listen first
  121. static bootBegin = () => {
  122. if (!job.started) { beginScan(now()) }
  123. return true
  124. }
  125. // rows for up to `budgetMs` (the clock is read every 32 rows); true when the whole scan is done
  126. static bootStep = (&budgetMs) => {
  127. if (job.done) { return true }
  128. t = now()
  129. if (!job.started) { beginScan(&t) }
  130. let n = 0
  131. while (!job.done) {
  132. r = job.cursor.next()
  133. if (r == null) { endPass() }
  134. else {
  135. if (job.phase == 'titles') { rowTitle(&r) } else if (job.phase == 'episodes') { rowEpisode(&r) } else { rowPerson(&r) }
  136. n = n + 1
  137. if (n % 32 == 0 && now() - t >= budgetMs) { return false }
  138. }
  139. }
  140. return true
  141. }
  142. // the whole scan at once (tools, and the way every start worked before mission T17)
  143. static bootScan = () => {
  144. bootStep(2000000000)
  145. return scanned
  146. }

Branches

Latest commits

  • 55257852log: #53 live, #56 mergedmre
  • 78b39f1bMerge hm56-rows: tracker#56 list builders insert oncemre
  • 6da612fclog: T36A tool defectmre
  • 08e55255log: HM56 done, T36A startedmre
  • 91bcdf0eAvoid per-row list copies and reproduce keyed-row blockersmre
  • 5fd2ac75status: #36 GOmre
  • 0d253b45mission: T36Amre
  • 2aa22d23log: #36 GOmre
  • 833aee2flog: #50 closed, HM56 startedmre
  • ac58c1e5mission: HM56mre
  • 58979c0clog: HM54 held for decision, DP65 startedmre
  • bb2ebc67log: #64 live, #53 mergedmre
  • 27cde42fMerge hm53-dom: tracker#53 inputs bound to membersmre
  • 2156cc7flog: HM54 reviewmre
  • 9fb82efclog: HM54 gap, fill continuesmre
  • b632eb8dlog: HM53 done, HM54 startedmre
  • ccb1a263tracker#53: bind editor drafts and use key event focus targetmre
  • 3356fcfclog: #52 blocked, HM53 startedmre
  • 833dcfc9Merge hm52-search: report only, tracker#52 blocked by framework gapmre
  • 73010cc0HM52: report replace-navigation search draft regressionmre