From c2b171d7c4b2b1e968384946f3b4e98a84b3cf6d Mon Sep 17 00:00:00 2001 From: Luke Parker <10430890+Hona@users.noreply.github.com> Date: Sat, 19 Sep 2026 10:40:32 +1000 Subject: [PATCH] perf(client): poll for a starting service every 25 ms (#49780) --- packages/client/src/effect/service.ts | 4 +++- packages/client/src/service-timing.ts | 7 ++++--- packages/client/test/fixture/service-timing.ts | 1 - 3 files changed, 7 insertions(+), 5 deletions(-) diff --git a/packages/client/src/effect/service.ts b/packages/client/src/effect/service.ts index d0514e3b75a..db2d15e46e6 100644 --- a/packages/client/src/effect/service.ts +++ b/packages/client/src/effect/service.ts @@ -131,7 +131,9 @@ export const ensure = Effect.fn("service.ensure")(function* (options: EnsureOpti }).pipe( Effect.repeat({ until: Option.isSome, - schedule: Schedule.max([Schedule.spaced(timing.pollInterval), Schedule.recurs(timing.attempts)]), + // Probes run sequentially, so a slow probe stretches each iteration; bound the loop by wall clock + // like the Promise variant rather than by attempt count. + schedule: Schedule.spaced(timing.pollInterval).pipe(Schedule.upTo({ duration: timing.promiseTimeout })), }), Effect.ensuring(Effect.sync(() => contenders.forEach((contender) => contender.release()))), ) diff --git a/packages/client/src/service-timing.ts b/packages/client/src/service-timing.ts index 31a50c6b5d1..03db9f6cb2c 100644 --- a/packages/client/src/service-timing.ts +++ b/packages/client/src/service-timing.ts @@ -1,6 +1,5 @@ export type EnsureTiming = { readonly pollInterval: number - readonly attempts: number readonly requestTimeout: number readonly spawnDelay: number readonly maxSpawnDelay: number @@ -11,9 +10,11 @@ export type EnsureTiming = { const timings = new WeakMap() +// A freshly spawned service registers in ~250 ms, so the poll cadence is a large share of the +// time a client waits for it. Probes are sequential, so the wait between them only matters while +// the connection is refused; both variants give up after promiseTimeout of wall-clock time. export const defaultEnsureTiming: EnsureTiming = { - pollInterval: 100, - attempts: 1_200, + pollInterval: 25, requestTimeout: 2_000, spawnDelay: 5_000, maxSpawnDelay: 30_000, diff --git a/packages/client/test/fixture/service-timing.ts b/packages/client/test/fixture/service-timing.ts index f4db65ae1f5..8c9ff85e15a 100644 --- a/packages/client/test/fixture/service-timing.ts +++ b/packages/client/test/fixture/service-timing.ts @@ -2,7 +2,6 @@ import { withEnsureTiming } from "../../src/service-timing" const timing = { pollInterval: 20, - attempts: 120, requestTimeout: 100, spawnDelay: 200, maxSpawnDelay: 1_200,