Repository navigation
perf(triangulation): keep API responsive during overlap work - #673
Merged
Merged
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #673 +/- ##
=======================================
Coverage 95.17% 95.18%
=======================================
Files 60 60
Lines 3402 3407 +5
=======================================
+ Hits 3238 3243 +5
Misses 164 164
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
frgfm
force-pushed
the
codex/extract-geospatial-inference
branch
from
October 15, 2026 13:19
6d997b7 to
c7fd372
Compare
frgfm
marked this pull request as ready for review
November 5, 2026 15:19
MateoLostanlen
approved these changes
Nov 6, 2026
MateoLostanlen
left a comment
Member
There was a problem hiding this comment.
Hi @frgfm, thanks for the PR!
Small, focused change with clear numbers, nice work. Moving the overlap work to a single bounded thread is the right trade-off here.
- The branch is 14 commits behind main, and main touched detections.py since. It merges cleanly, but please update the branch so CI runs on the merged state.
- (nit) The DB session stays open while a request waits for the geometry thread. Fine with current compute times, just something to watch if detections burst.
Happy to merge once the branch is updated and CI is green.
frgfm
force-pushed
the
codex/extract-geospatial-inference
branch
from
November 6, 2026 17:30
c7fd372 to
056300c
Compare
Member
Author
|
@MateoLostanlen all addressed ✅ |
Member
|
Hi @frgfm, thanks for the PR! Thanks for updating the branch and documenting the DB session trade-off. Everything looks good and CI is green. Merging now. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Triangulation blocks the backend's event loop, so unrelated requests wait for the calculation. Run the same calculation in one bounded worker thread per backend process. Keep the current algorithm, results, dependencies, and deployment.
This replaces the original service extraction with a smaller latency fix: 5 files, +9 net production lines, +45 net lines including tests. Both alert attachment and alert refresh use the same worker limit.
flowchart LR C["Requests"] --> A subgraph B["Existing backend process"] A["API event loop"] -->|"await"| T["One geometry worker thread"] T -->|"same result"| A end A --> D["Database and storage"]Queue and database-session limits
The limit applies to running geometry jobs, not waiting callers. Callers retain their database sessions and active transactions while waiting for a geometry slot. Transactions stay caller-owned so related writes still commit or roll back together. Bursts can increase connection occupancy; sustained overload and database-pool wait times have not been measured.
Measured results (2026-10-15)
Historical measurements against baseline
5d965ddon 2026-10-15. Same optimized algorithm and package versions, one backend worker, five fresh runs per option:5d965ddRSS is resident process memory. The memory column includes backend and compute processes. The p95 is the response time within which 95% of health requests finish. Values are medians of each run's peak memory, p95 health time, and median calculation time.
The thread cuts unrelated-request tail latency by 98.1%, with 2.9% more RSS. Calculation time stays roughly unchanged. The split adds 34.1% RSS at one backend worker, so this PR adds no service, HTTP call, token, network, or dependency.
At four backend workers, a separate two-run experiment saved 12.8% RSS and 8.6% proportionally shared memory with the split. That is a different deployment from the repository's one-worker configuration. Native libraries remain in the backend in this PR; process and database isolation are deferred.
Raw samples, pinned environment, benchmark code, and reproduction instructions.
Conditions: native Linux ARM64, CPython 3.11.17, one CPU quota shared by the whole stack. Each mixed-load condition sends the same 12 geometry requests and 96 scheduled health requests. All geometry and timezone output hashes match across all 21 conditions.
Limits: these are local synthetic HTTP diagnostics with real backend imports. Database, S3, notification delivery, and background jobs are excluded. The split is an optimistic loopback prototype. These are not VPS ingestion measurements or Docker image-size savings.
Test plan
make quality;make precommit.