Public: anyone can read this; the crew can change it.
A request for the clock, review and a deal page is timed in a test and fails over 50 ms on the sample book #291
Check · Review · Land · Live done — Landed and live in production.
mason/deal-clock:mason/285-a-request-for-the-clock-review-and-a-dea → main 3 commits fork 3 threads · 3 unresolved
1 file
changed +55
−1
src/speed.test.ts +55 −1
| @@ -1,5 +1,5 @@ | ||
| 1 | 1 | /** The clock, a deal page and the client timeline stay fast with a large book. */ |
| 2 | import { afterAll, beforeAll, beforeEach, expect, test } from "bun:test"; | |
| 2 | import { afterAll, beforeAll, beforeEach, describe, expect, test } from "bun:test"; | |
| 3 | 3 | import { mkdtempSync } from "node:fs"; |
| 4 | 4 | import { tmpdir } from "node:os"; |
| 5 | 5 | import { join } from "node:path"; |
| @@ -154,3 +154,57 @@ test("the clock does not carry sheets; a deal's sheets come on demand", async () | ||
| 154 | 154 | expect(await sheets.text()).toContain('popover id="sheet-'); |
| 155 | 155 | expect((await fetch(`${base}/deals/999999/sheets`, { headers })).status).toBe(404); |
| 156 | 156 | }); |
| 157 | ||
| 158 | // The sample book: what a person sees first. Its own data directory and | |
| 159 | // server, so the 200-deal book above does not change what is measured. | |
| 160 | // Cap: 50 ms on the median of 5 requests after a warm-up. Measured (ms): | |
| 161 | // / 1.9, review 2.7, /week 1.7, /people 3.0, /profile 1.7, each open deal page 5.1 to 8.4 (4 deals). Measured on a | |
| 162 | // quiet machine, every page answers in a few milliseconds, | |
| 163 | // so the cap leaves an order of magnitude of headroom for a loaded one. | |
| 164 | describe("the sample book", () => { | |
| 165 | const sampleDir = mkdtempSync(join(tmpdir(), "app-speed-sample-")); | |
| 166 | let sampleServer: ReturnType<typeof serve>; | |
| 167 | let sampleBase = ""; | |
| 168 | let sampleHeaders: Record<string, string> = {}; | |
| 169 | let openDealIds: number[] = []; | |
| 170 | ||
| 171 | beforeAll(async () => { | |
| 172 | openDb(sampleDir).close(); // seeds the samples once | |
| 173 | sampleServer = serve({ port: 0, dataDir: sampleDir, identityKey: KEY }); | |
| 174 | sampleBase = `http://${sampleServer.hostname}:${sampleServer.port}`; | |
| 175 | const identity = `u2|bea|user|${Date.now() + 600_000}`; | |
| 176 | sampleHeaders = { "x-forge-identity": identity, "x-forge-signature": sign(identity, KEY) }; | |
| 177 | const deals = (await (await fetch(`${sampleBase}/api/deals`, { headers: sampleHeaders })).json()) as { id: number; closed: boolean; fell_through: boolean }[]; | |
| 178 | openDealIds = deals.filter((d) => !d.closed && !d.fell_through).map((d) => d.id); | |
| 179 | }); | |
| 180 | afterAll(() => sampleServer.stop(true)); | |
| 181 | ||
| 182 | async function median(path: string): Promise<number> { | |
| 183 | const get = async () => { | |
| 184 | const start = performance.now(); | |
| 185 | const res = await fetch(sampleBase + path, { headers: sampleHeaders }); | |
| 186 | const took = performance.now() - start; | |
| 187 | expect(res.status).toBe(200); | |
outdated
Guessing two response shapes and carrying unused closed/status fields. Use the real shape, and filter to open deals so openIds means what it says. |
||
| 188 | await res.arrayBuffer(); | |
| 189 | return took; | |
| 190 | }; | |
| 191 | await get(); | |
| 192 | const times: number[] = []; | |
| 193 | for (let i = 0; i < 5; i++) times.push(await get()); | |
| 194 | return mid(times); | |
| 195 | } | |
| 196 | ||
| 197 | test.each(["/", "/reminders/today", "/week", "/people", "/profile"])("%s answers in under 50 ms on the sample book", async (path) => { | |
| 198 | forgetRationing(); | |
| 199 | const took = await median(path); | |
| 200 | expect(took).toBeLessThan(BUDGET_MS); | |
| 201 | }); | |
| 202 | ||
| 203 | test("every open sample deal's page answers in under 50 ms", async () => { | |
| 204 | expect(openDealIds.length).toBeGreaterThan(0); | |
| 205 | for (const id of openDealIds) { | |
| 206 | forgetRationing(); | |
| 207 | expect(await median(`/deals/${id}`)).toBeLessThan(BUDGET_MS); | |
| 208 | } | |
| 209 | }); | |
| 210 | }); |
new above
offline
Add the measured median for the deal pages here; the box asks for the measured numbers in the test.