tracker
All repositories: gitoria
6.4 KB
// lib/bootscan.hl — THE BOOT SCANS (tracker.worldapi.org#45, mission 043): ONE streamed pass per big table at start, feeding every// derived structure that needs that table, instead of one `find(null, null)` per module (each decoded the WHOLE table into one// 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// pauses those arrays caused — missions/388-trkmem-report.md in the Hybriel repo). `iterate(null, null)` hands the rows out one at a// time and frees each (but see eachRow: the plugin decodes the file into one native arena first).//// titles → catalog.hl (the public lists, genres) shows.hl (slug map) search.hl (title entries, TMDB / TVmaze ids, slugs)// shortids.hl (owners, queue) people.hl (cast photos)// episodes → catalog.hl (newest released / upcoming dates)// people → search.hl (person entries) shortids.hl people.hl (/people's order)//// Every module keeps its own lazy build (ensureIndex, ensureShortIds, …) built from the SAME per-record functions used here, so a// tool that imports one module still works; project.hl calls bootScan() once before the first request. The order inside a table is// the table's, as with the old per-module scans (search entries, short id ownership and the id queue come out the same).import { now } from 'hl:time'import { env, setEnv } from 'hl:proc'import { showsTable, episodesTable, personsTable, noteSlugsOf, markSlugIdsBuilt } from './shows.hl'import { beginIndex, noteIndexShow, noteIndexEpisode, finishIndex } from './catalog.hl'import { indexShow, noteIndexPerson, finishSearchIndex } from './search.hl'import { loadOldShortIds, noteShortIdRow, finishShortIds } from './shortids.hl'import { noteCastProfiles, markPeopleIndexesBuilt, noteViewRow, finishPeopleView } from './people.hl'import { warm } from './warm.hl'// THE SCAN IS RESUMABLE (mission T17): `bootStep(budgetMs)` takes rows from the table's cursor until the budget is used up and// answers true once all three passes are done. project.hl runs it a few seconds before the server is made (a small database is// then complete at the first request, as always) and goes on from a clock after the server listens, so the first request does not// 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// is built show a "starting up" note (components/warm*.hl, the parent of those pages) instead of being built on half a map.// The rows, the per-row functions and the order are the ones of the former blocking passes: the structures come out the same.static scanned = { titles = 0 episodes = 0 people = 0 castPhotos = 0 ms = 0 }static job = { started = false done = false phase = '' cursor = null t0 = 0 tPhase = 0 paced = false }// 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// cast + crew) against a small live heap, so it ran 350 times for the titles alone; a higher pacing lets the garbage grow// to a few hundred MB first. Per pass, sized to what is live then; the operator's own HL_GC_PACING is never touched.static paceOf = [8, 3, 1, 1]static pace = (&step) => {if (job.paced) { setEnv('HL_GC_PACING', '' + paceOf[step]) }return true}static beginScan = (&t) => {job.started = truejob.t0 = tjob.tPhase = tjob.paced = env('HL_GC_PACING') == nullif (env('TRACKER_GC_PACE') != null) {let k = 0for (v of env('TRACKER_GC_PACE').split(',')) { paceOf[k] = toNumber(v) k = k + 1 }}warm.running = truewarm.startedAt = twarm.phase = 'titles'beginIndex()loadOldShortIds()job.phase = 'titles'job.cursor = showsTable.cursor(null, null)pace(0)return true}static rowTitle = (&s) => {noteIndexShow(&s)noteSlugsOf(&s)indexShow(&s)noteShortIdRow('show', &s)scanned.castPhotos = scanned.castPhotos + noteCastProfiles(&s)scanned.titles = scanned.titles + 1return null}static rowEpisode = (&e) => {noteIndexEpisode(&e)scanned.episodes = scanned.episodes + 1return null}static rowPerson = (&p) => {noteIndexPerson(&p)noteShortIdRow('person', &p)noteViewRow(&p)scanned.people = scanned.people + 1return null}// a pass is out of rows: its closing work (the same calls, in the same order, as the blocking passes made), then the next passstatic endPass = () => {t = now()if (job.phase == 'titles') {markSlugIdsBuilt()console.log('boot scan: ' + scanned.titles + ' titles in ' + (t - job.tPhase) + ' ms')warm.titles = truejob.phase = 'episodes'warm.phase = 'episodes'job.tPhase = tjob.cursor = episodesTable.cursor(null, null)pace(1)} else if (job.phase == 'episodes') {finishIndex()console.log('boot scan: ' + scanned.episodes + ' episodes in ' + (t - job.tPhase) + ' ms')warm.catalog = truejob.phase = 'people'warm.phase = 'people'job.tPhase = tjob.cursor = personsTable.cursor(null, null)pace(2)} else {markPeopleIndexesBuilt(&scanned.castPhotos)finishSearchIndex(&job.t0)finishShortIds(&job.t0)finishPeopleView()console.log('boot scan: ' + scanned.people + ' people in ' + (t - job.tPhase) + ' ms')// tracker#37's log line (tests/browser.mjs reads it)console.log('people view: ' + scanned.people + ' people, ' + scanned.castPhotos + ' cast photos in ' + (t - job.tPhase) + ' ms')scanned.ms = t - job.t0console.log('boot scan: done in ' + scanned.ms + ' ms')job.done = truejob.cursor = nullwarm.people = truewarm.running = falsewarm.phase = 'done'warm.readyAt = tpace(3)}return true}// the scan is under way from here on (warm.running), before the first row — project.hl calls it when the server will listen firststatic bootBegin = () => {if (!job.started) { beginScan(now()) }return true}// rows for up to `budgetMs` (the clock is read every 32 rows); true when the whole scan is donestatic bootStep = (&budgetMs) => {if (job.done) { return true }t = now()if (!job.started) { beginScan(&t) }let n = 0while (!job.done) {r = job.cursor.next()if (r == null) { endPass() }else {if (job.phase == 'titles') { rowTitle(&r) } else if (job.phase == 'episodes') { rowEpisode(&r) } else { rowPerson(&r) }n = n + 1if (n % 32 == 0 && now() - t >= budgetMs) { return false }}}return true}// the whole scan at once (tools, and the way every start worked before mission T17)static bootScan = () => {bootStep(2000000000)return scanned}
Branches
Latest commits
- 73010cc0HM52: report replace-navigation search draft regressionmre
- 1742e92bstatus: DP64 and HM52 runningmre
- 29ad5b58log: #64 merged, DP64 and HM52 startedmre
- fafddbf9Merge hm64-catalog: tracker#64 catalog from packed entriesmre
- b2e2206dlog: #63 livemre
- 5831e0e0log: HM64 donemre
- 4042b923Flatten catalog membership rows into paired slotsmre
- 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