You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Skip asyncio.gather in the health check when there are no probes #337
HealthChecksInstrument.define_health_status (lite_bootstrap/instruments/healthchecks_instrument.py:55-60) always runs asyncio.gather over the framework check and every probe in health_checks_probes. With no probes, the default, that wraps one coroutine in a Task and costs two event-loop iterations per health request for nothing.
Measured on 2026-10-24 at 705d8a3 on Linux with 2 CPUs (CPython 3.14.9), against an equivalent plain handler, with "await the framework check directly when there are no probes" as a prototype:
Litestar in-process: +7.1 µs per health request today, +0.4 µs with the prototype;
Litestar on Granian (1 worker, ab -k -c 16): +5.3 µs against +1.2 µs;
FastAPI in-process: +22.6 µs against +9.3 µs (noisy, 16% spread).
On macOS one loop iteration costs about 12 µs (KqueueSelector.select(0) against 0.31 µs for EpollSelector on Linux), and asyncio.gather on one coroutine 42 µs. The saving per request is small and probes are infrequent, so this is a cheap cleanup rather than a priority. The tables and scripts are to be published with #335.
Work
Test first: with no probes configured, define_health_status() returns True without calling asyncio.gather (monkeypatch asyncio.gather in lite_bootstrap.instruments.healthchecks_instrument to raise). It fails today. test_healthchecks_probes_run_concurrently (tests/instruments/test_healthchecks_instrument.py:52-63) keeps covering the concurrent path.
In define_health_status, return await self._define_framework_health_status() when health_checks_probes is empty, and keep the gather otherwise. FastStream's override (lite_bootstrap/bootstrappers/faststream_bootstrapper.py:139-146) still pings its brokers through its own gather; leave it.
Verify: the new test and tests/instruments/test_healthchecks_instrument.py pass, along with the health-check tests on every framework.
Activity