perf(host): cache auth headers and parallelize status payloads - #4033
Conversation
Two follow-on speedups for omni host status: 1. Cache _remote_headers() per base_url within a process. Databricks SDK credential resolution (~3s) ran on every _host_http_json call. Since tokens are valid for the lifetime of a CLI invocation, resolving once and reusing is safe. A threading.Lock serialises concurrent first-time resolution for the same URL. 2. Build daemon status payloads in parallel with ThreadPoolExecutor. With the dead-process skip from the previous commit, only live daemons make HTTP calls. Parallelising them lets independent servers be queried concurrently instead of sequentially. Signed-off-by: Tomu Hirata <tomu.hirata@gmail.com>
Signed-off-by: Tomu Hirata <tomu.hirata@gmail.com>
|
/review |
|
_remote_headers() does file I/O and Databricks SDK calls that can raise OSError. The cache-populating call was outside the try block, so such a failure propagated unhandled. Under ThreadPoolExecutor (added in this PR) that aborted the entire omni host status listing. Move the resolution inside the existing try/except so auth/file errors remain recoverable and produce a status_code=0 result per daemon, matching the pre-change behaviour. Also adds test_host_http_json_handles_remote_headers_oserror to pin this contract. Signed-off-by: Tomu Hirata <tomu.hirata@gmail.com>
Signed-off-by: Tomu Hirata <tomu.hirata@gmail.com>
|
/review |
|
|
🏷️ Doc impact: Internal performance change adding header caching and parallel Auto-classified on merge. Set the label manually before merging to override. · run |
Related issue
N/A
Summary
Two follow-on speedups for
omni host statusbuilding on #4031.1. Cache
_remote_headers()per base URL_host_http_jsoncreates a newhttpx.Clienton every call and passes freshly-resolved headers. For Databricks URLs, resolving headers calls into_resolve_databricks_auth_for_hostwhich constructs a Databricks SDKConfigobject — this shells out to the Databricks CLI and takes ~3 s each time. Within a single CLI invocation the resulting token is valid for its full lifetime, so resolving once and caching is safe.A
threading.Lockwith a double-checked pattern serialises concurrent first-time resolution for the same URL; subsequent callers in other threads hit the cache without taking the lock.2. Build daemon status payloads in parallel
The payload loop in
host_statuswas a sequential list comprehension. With the dead-process skip from #4031, only live daemons issue HTTP calls — but each live remote daemon still takes ~4 s (auth + RTT). Switching toThreadPoolExecutor.maplets calls to independent servers overlap instead of stack. The header cache ensures each server's credentials are only resolved once across all threads.Combined effect on a workstation with 39 daemon records (2 live): ~14 s → ~5 s (from #4031) → same ~5 s for a single remote, but would scale down linearly with multiple live remote daemons.
Test Plan
tests/host/test_cli_host.pypass, including the new test from perf(host): skip host-status HTTP call for dead daemon processes #4031.omni host statusbefore/after on a workstation with 1 live remote daemon + 1 live local server.Demo
N/A
Type of change
Test coverage
Coverage notes
Changelog