gitoria

tracker

All repositories: gitoria

ReadmeCodePull requestsReleasesTicketsSettings
Commit08e5525508e55255log: HM56 done, T36A startedmre08e55255/tests/realdata-027-bench.mjs

5.0 KB

  1. // tests/realdata-027-bench.mjs — mission 027 (re-vendor 06617221: old 190aa11d vs new); copy of realdata-074-bench.mjs, mission 025 (tracker#30: /my/* after the first-start jobs; a copy of realdata-071-bench.mjs with
  2. // the /my/ pages), NOT the gate: the big pages on a COPY of live
  3. // storage/, signed in as the creator (cookie from $REAL_SID_FILE), $REAL_LOADS (20) loads per page. Each load: the server's own
  4. // answer (node fetch, whole body) and the full browser load (to hydrated + visible images; Picard also clicks the cast "Show all"
  5. // and waits for "Show less"); the server's RSS after each load (/proc/$REAL_PID). Env: REAL_PORT, REAL_CHROME, REAL_SID_FILE,
  6. // REAL_PID, REAL_OUT (a .json with every number), REAL_LOADS, REAL_PATHS (only these, comma list of path prefixes). Procedure: STATUS.md mission 071.
  7. import { writeFileSync, readFileSync } from 'node:fs';
  8. import { launchBrowser } from './cdp.mjs';
  9. process.env.HL_CHROME ||= '/opt/google/chrome/chrome';
  10. const PORT = Number(process.env.REAL_PORT || 8758), BASE = `http://127.0.0.1:${PORT}`, LOADS = Number(process.env.REAL_LOADS || 20);
  11. const SID = readFileSync(process.env.REAL_SID_FILE, 'utf8').trim(), PID = process.env.REAL_PID;
  12. const rss = () => Math.round(Number(readFileSync(`/proc/${PID}/status`, 'utf8').match(/VmRSS:\s+(\d+)/)[1]) / 1024);
  13. const browser = await launchBrowser({ debugPortRange: [Number(process.env.REAL_CHROME || 8759), Number(process.env.REAL_CHROME || 8759)] });
  14. const page = await browser.newPage();
  15. await page.send('Emulation.setDeviceMetricsOverride', { width: 1280, height: 900, deviceScaleFactor: 1, mobile: false });
  16. await page.send('Network.setCookie', { name: 'trackersid', value: SID, url: BASE });
  17. const hydrated = () => page.waitFor('!!window.__hl && window.__hl.socket && window.__hl.socket.readyState === 1 && document.readyState === "complete"', { timeout: 120000, label: 'hydrated' });
  18. const load = async (path, showAll) => {
  19. const t = Date.now(); await page.goto(BASE + path, { timeout: 120000 }); await hydrated();
  20. await page.waitFor(`Array.from(document.querySelectorAll('img')).filter(i => { const r = i.getBoundingClientRect(); return r.top < innerHeight && r.bottom > 0 }).every(i => i.complete)`, { timeout: 15000, label: 'images' }).catch(() => {});
  21. if (showAll) { await page.click('#casttoggle'); await page.waitFor(`document.querySelector('#casttoggle').innerText.includes('Show less')`, { timeout: 30000, label: 'show less' }); }
  22. return Date.now() - t;
  23. };
  24. const serverTime = async (path) => {
  25. const t = Date.now(); const r = await fetch(BASE + path, { headers: { cookie: 'trackersid=' + SID } }); const body = await r.text();
  26. return { ms: Date.now() - t, status: r.status, kb: Math.round(body.length / 1024) };
  27. };
  28. try {
  29. // a franchise page and a timeline from /franchises itself (the first ones listed; the seed makes timelines without a franchise)
  30. await load('/franchises');
  31. const hrefOf = (sel) => page.evaluate(`(document.querySelector('${sel}') || { getAttribute: () => null }).getAttribute('href')`);
  32. const franchise = await hrefOf('a.franchise-row'), timeline = await hrefOf('a.timeline-link');
  33. let PAGES = [['/my/series'], ['/my/unwatched'], ['/series/Star-Trek-Picard', true], ['/series'], ['/franchises']];
  34. // REAL_PATHS (comma list): only these of the pages above
  35. if (process.env.REAL_PATHS) PAGES = PAGES.filter(([p]) => process.env.REAL_PATHS.split(',').some(x => p.startsWith(x)));
  36. const out = { pid: PID, rssStart: rss(), pages: [] };
  37. for (const [path, showAll] of PAGES) {
  38. const p = { path: path + (showAll ? ' + Show all' : ''), server: [], browser: [], rss: [], rows: null };
  39. const before = rss();
  40. for (let i = 0; i < LOADS; i++) {
  41. const s = await serverTime(path); if (s.status !== 200) throw new Error(path + ' answered ' + s.status);
  42. p.server.push(s.ms); p.kb = s.kb;
  43. p.browser.push(await load(path, showAll));
  44. p.rss.push(rss());
  45. }
  46. p.rows = await page.evaluate(`document.querySelectorAll('my-show-row, a.tile, a.timeline-item, a.franchise-row, a.timeline-link, episode-row, show-cast a.artist-link, a.unwatched-show, a.schedule-show').length`);
  47. const st = (a) => ({ avg: Math.round(a.reduce((x, y) => x + y, 0) / a.length), min: Math.min(...a), max: Math.max(...a), first5: Math.round(a.slice(0, 5).reduce((x, y) => x + y, 0) / 5), last5: Math.round(a.slice(-5).reduce((x, y) => x + y, 0) / 5) });
  48. p.sum = { server: st(p.server), browser: st(p.browser), rssBefore: before, rssAfter: p.rss[p.rss.length - 1] };
  49. out.pages.push(p);
  50. console.log(`${p.path.padEnd(42)} server avg ${p.sum.server.avg} ms (first5 ${p.sum.server.first5}, last5 ${p.sum.server.last5}, max ${p.sum.server.max}) browser avg ${p.sum.browser.avg} ms (first5 ${p.sum.browser.first5}, last5 ${p.sum.browser.last5}, max ${p.sum.browser.max}) RSS ${before} → ${p.sum.rssAfter} MB ${p.kb} kB, ${p.rows} rows`);
  51. }
  52. out.rssEnd = rss();
  53. console.log(`RSS over the whole run: ${out.rssStart} → ${out.rssEnd} MB`);
  54. if (process.env.REAL_OUT) writeFileSync(process.env.REAL_OUT, JSON.stringify(out, null, 1));
  55. } catch (e) { console.error(e); await browser.close().catch(() => {}); process.exit(1); }
  56. await browser.close();
  57. process.exit(0);

Branches

Latest commits

  • 08e55255log: HM56 done, T36A startedmre
  • 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
  • 1742e92bstatus: DP64 and HM52 runningmre
  • 29ad5b58log: #64 merged, DP64 and HM52 startedmre
  • fafddbf9Merge hm64-catalog: tracker#64 catalog from packed entriesmre
  • b2e2206dlog: #63 livemre