| 1 | /** |
| 2 | * The same probe as ZlibProbe.local.test.ts, against REAL Cloudflare: which |
| 3 | * synchronous exact-span inflate paths exist in production workerd, and |
| 4 | * what each costs per entry (client-measured wall time over 2,000 entries). |
| 5 | * DESIGN §22.4: this is what decides the push-ingest CPU story. |
| 6 | */ |
| 7 | import * as Alchemy from "@/index.ts"; |
| 8 | import * as Cloudflare from "@/Cloudflare"; |
| 9 | import * as Test from "@/Test/Alchemy"; |
| 10 | import { expect } from "alchemy-test"; |
| 11 | import * as Effect from "effect/Effect"; |
| 12 | import * as Schedule from "effect/Schedule"; |
| 13 | import * as HttpClient from "effect/http/HttpClient"; |
| 14 | import ZlibProbeWorker from "./fixtures/zlib-probe-worker.ts"; |
| 15 | |
| 16 | const { test, beforeAll, afterAll, deploy, destroy } = Test.make({ |
| 17 | providers: Cloudflare.providers(), |
| 18 | }); |
| 19 | |
| 20 | const Stack = Alchemy.Stack( |
| 21 | "ZlibProbeCloudStack", |
| 22 | { providers: Cloudflare.providers(), state: Cloudflare.state() }, |
| 23 | Effect.gen(function* () { |
| 24 | const worker = yield* ZlibProbeWorker; |
| 25 | return { url: worker.url.as<string>() }; |
| 26 | }), |
| 27 | ); |
| 28 | |
| 29 | const stack = beforeAll(deploy(Stack)); |
| 30 | afterAll.skipIf(!!process.env.NO_DESTROY)(destroy(Stack)); |
| 31 | |
| 32 | test( |
| 33 | "production workerd: which exact-span inflate paths work, and their cost", |
| 34 | Effect.gen(function* () { |
| 35 | const { url } = yield* stack; |
| 36 | const client = yield* HttpClient.HttpClient; |
| 37 | const get = (q: string) => |
| 38 | client.get(`${url}/?${q}`).pipe( |
| 39 | Effect.flatMap((res) => |
| 40 | res.status === 200 |
| 41 | ? res.json |
| 42 | : Effect.fail(new Error(`status ${res.status}`)), |
| 43 | ), |
| 44 | Effect.retry({ |
| 45 | schedule: Schedule.exponential("500 millis"), |
| 46 | times: 10, |
| 47 | }), |
| 48 | ); |
| 49 | const probe = (yield* get("path=probe")) as Record<string, unknown>; |
| 50 | console.log("[zlib-cloud] probe", JSON.stringify(probe)); |
| 51 | const N = 2000; |
| 52 | const nFor = (path: string) => (path.startsWith("deflate") ? 200 : N); |
| 53 | for (const path of [ |
| 54 | "processChunk", |
| 55 | "processChunkReuse", |
| 56 | "info", |
| 57 | "plain", |
| 58 | "stream", |
| 59 | "sha1", |
| 60 | "copy", |
| 61 | "jsloop", |
| 62 | "effect", |
| 63 | "deflate6", |
| 64 | "deflate1", |
| 65 | ]) { |
| 66 | yield* get(`path=${path}&n=50`); // warm |
| 67 | const t0 = performance.now(); |
| 68 | const n = nFor(path); |
| 69 | const r = (yield* get(`path=${path}&n=${n}`)) as { |
| 70 | ok: number; |
| 71 | error?: string; |
| 72 | }; |
| 73 | const ms = performance.now() - t0; |
| 74 | console.log( |
| 75 | `[zlib-cloud] ${path.padEnd(12)} ok ${r.ok}/${n} in ${ms.toFixed(0)}ms → ${(ms / n).toFixed(3)} ms/entry${r.error ? ` error: ${r.error}` : ""}`, |
| 76 | ); |
| 77 | } |
| 78 | expect(probe).toBeDefined(); |
| 79 | }), |
| 80 | { |
| 81 | tags: ["provider:cloudflare", "provider:cloudflare:worker", "live"], |
| 82 | timeout: 300_000, |
| 83 | }, |
| 84 | ); |