gitoria

tracker

All repositories: gitoria

ReadmeCodePull requestsReleasesTicketsSettings
Commita016e9aba016e9abReapply "Merge branch 'rv39'"mrea016e9ab/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

  • a016e9abReapply "Merge branch 'rv39'"mre
  • f29e2502log: RV39 gate fixmre
  • ad529ac1log: m572 verdictmre
  • 1b37d404RV39 on hold: hybriel#308mre
  • f9127c68Revert "Merge branch 'rv39'"mre
  • cd39f3d3log: hybriel#308mre
  • 51341d6elog: RV39 deploy startedmre
  • c9e29e06Merge branch 'rv39'mre
  • 0f8d1fdclog: RV39 report, browser 387/2mre
  • 50249b0bRV39: reportmre
  • 10ed9581compose: HL_GC_STATS=1mre
  • 955da19bRV39: re-vendor Hybriel set day39 (source 51e921d7, bin 6b481aa7)mre
  • 64b8d1dclog: RV39 startedmre
  • 1f2df72amission RV39mre
  • 6c1936f9log+status: GC planmre
  • 2846a840log: m569 result, GC hypothesismre
  • b24cd2d5log: Anton on hl:fetch, mission 569mre
  • 7d42cac1log+status: SL1 measured, fetch stalls remainmre
  • 8e5f2ceflog: SL1 deployedmre
  • 29f34212log: SL1 deploy startedmre