Skip to content

perf(status): parallelize independent adapter reads (closes #31) - #32

Merged
AusafMo merged 1 commit into
mainfrom
perf/parallel-status-reads
Aug 2, 2026
Merged

perf(status): parallelize independent adapter reads (closes #31)#32
AusafMo merged 1 commit into
mainfrom
perf/parallel-status-reads

Conversation

@AusafMo

@AusafMo AusafMo commented Aug 2, 2026

Copy link
Copy Markdown
Owner

Follow-up to #28. After the cheap ref list + shared MongoClient, /api/state on a remote store was still ~5s — the independent reads ran serially, so each RTT summed on a cross-region link (as profiled in #31).

Fix

Add _gather() (a bounded ThreadPoolExecutor map) and route the two hot spots through it:

  • _all_refs — per-collection list_record_ids distincts + list_history_refs now run concurrently.
  • _batch_live_and_heads — the per-collection get_records + get_heads now run concurrently.

pymongo/psycopg release the GIL during network I/O, so the round-trips overlap instead of summing (~sum → ~max(single op)). Safe for both adapters: MongoClient is thread-safe/pooled, and the Postgres connection cache is already thread-local (each worker thread gets its own connection).

Verification

Net: on a remote store this should take the warm UI from ~5s to ~1–1.5s (and helps cold too). Local stores were already instant.

Also answers the '19s first time' question: cold load = one-time MongoClient TLS/SRV handshake (~2s, cached after) + cold Atlas caches on top of the serial round-trips; parallelizing collapses the round-trip portion whether warm or cold.

Follow-up to #28. After the cheap ref list + client cache, /api/state on a remote
store was still ~5s: the independent per-collection list_record_ids distincts,
the batch get_records/get_heads, and list_history_refs each cost one RTT and ran
serially, so they summed on a cross-region link.

Add _gather() (a bounded ThreadPoolExecutor map) and route _all_refs and
_batch_live_and_heads through it. pymongo/psycopg release the GIL during network
I/O, so the round-trips overlap instead of summing — ~sum becomes ~max(single
op). Safe for both adapters: MongoClient is thread-safe/pooled, and the Postgres
connection cache is already thread-local so each worker gets its own connection.

Verified: status() output is byte-identical to serial (50 rows, drift intact);
with a simulated 300ms/call RTT, status() drops from ~8.4s serial to ~1.5s.
@AusafMo
AusafMo merged commit ab33bfe into main Aug 2, 2026
2 checks passed
@AusafMo
AusafMo deleted the perf/parallel-status-reads branch August 2, 2026 09:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant