gitoria

tracker

All repositories: gitoria

ReadmeCodePull requestsReleasesTicketsSettings
Commit5831e0e05831e0e0log: HM64 donemre5831e0e0/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

  • 5831e0e0log: HM64 donemre
  • ea8a759elog: #61 #62 live, DP63 and HM64 startedmre
  • 40439456Merge hm63-searchtext: tracker#63 packed search textmre
  • b7e6b48ePack normalized search text behind numeric offsetsmre
  • b35f53e1log: DP62 stale runtime decisionmre
  • f9593602log: Apollo deploy rule correctionmre
  • 3c95f7f3log: DP62 and HM63 startedmre
  • 9c4397c9mission HM63mre
  • 8dfe42c8mission DP62mre
  • e347fef4Merge rv44: tracker#61 #62 on Hybriel day44mre
  • 8274bcf1log: RV44 done, deploy held for the usage windowmre
  • 1ef7a3b1RV44: report day44 gates and migration/restart proofsmre
  • a5f62f6cRV44: re-vendor Hybriel set day44 (source 222edef7, bin 4f0f263e)mre
  • 6159a248Merge branch 'hm62-personindex' into rv44mre
  • a8923d93log: RV44 startedmre
  • cf28cf77mission RV44mre
  • 585782dfLog: tracker#60 Chrome look, STATUS rewrittenmre
  • 147d0172conductor: caramboleyo is the user, not owner/creatorApollo
  • 21dd0cfblog: #60 live measurement, reviewmre
  • 7793cf94HM62b report: person indexes with fixed mpackdbmre