tracker
All repositories: gitoria
6.5 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 (slug map, TMDB ids, /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, noteSlugOfPerson, noteTmdbOfPerson, 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)noteSlugOfPerson(p)noteTmdbOfPerson(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
- a9eb9827records: mpackdb integrity clean, all 12 tablesmre
- 6cf40dbdrecords: mpackdb integrity check, shows uncheckedmre
- 1880f42arecords: day38 deploy may swap normallymre
- 9d806e35records: mpackdb freeze until day38mre
- a660239drecords: day37 lacks #277, wait for day38mre
- b0abfdeaLOG: Anton hybriel#277 fix ready for day37mre
- 7b5b2918Tracker: hybriel#277 fix comes in day37mre
- 7ddbeec8Tracker: RV28c blocked on day35 regressionmre
- bf401884Tracker: RV28c startedmre
- 0ff4ecd4Tracker: RV28c briefmre
- 06565b1fRecords: day35 relay note, tickets subscription idmre
- c6dc3e86RV28b: switch to set day35mre
- 24e401b8Tracker: TR7 watch cleanmre
- b0412957Tracker: RV28b handed overmre
- 456940c8Tracker: RULINGS pathmre
- b87a8fdcTracker: worldapi-conductor paths backmre
- 641f3b54Tracker: Apollo answermre
- 8b3cbddaTracker: status, TR7 fix livemre
- ec30162aTracker: TR7 fix livemre
- 54cbec80compose: ignore SIGPIPE (TR7 crash loop, exit 141)mre