feat: backpressure, search budget and fast ngram comparison#10
Open
loris-av wants to merge 1 commit intolivingdata-co:mainfrom
Open
feat: backpressure, search budget and fast ngram comparison#10loris-av wants to merge 1 commit intolivingdata-co:mainfrom
loris-av wants to merge 1 commit intolivingdata-co:mainfrom
Conversation
Queue backpressure: - Add maxSize option to createQueue to reject requests when full - Purge aborted requests before rejecting to reclaim slots - Add totalSize() and purgeAborted() methods - Configurable via ADDOK_MAX_QUEUE_SIZE env (default: numNodes * 4) Request timeout: - Add requestTimeout option to reject queued requests after delay - Configurable via ADDOK_REQUEST_TIMEOUT env (default: 5000ms) - Returns HTTP 408 on timeout, 503 on queue full Python performance optimizations in bridge.py: - Search budget: cap collector pipeline time (ADDOK_SEARCH_BUDGET_MS, default 200ms) to prevent slow queries from blocking workers indefinitely - fast_compare_ngrams: pure Python bigram comparison ~3x faster than ngram.NGram.compare(), avoiding object re-creation on every call Tests: - Add queue tests for maxSize, purgeAborted, totalSize
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
Three performance improvements for production workloads:
1. Queue backpressure
createQueue({maxSize})rejects new requests when the queue is full (HTTP 503)ADDOK_MAX_QUEUE_SIZEenv var (default:numNodes * 4)2. Request timeout
ADDOK_REQUEST_TIMEOUTenv var (default:5000ms)3. Python performance optimizations (bridge.py)
Search budget — Caps the collector pipeline time to prevent slow queries from blocking workers:
Search.__call__andSearch.intersectto track elapsed timeADDOK_SEARCH_BUDGET_MSenv var (default:200ms,0to disable)fast_compare_ngrams — Pure Python bigram comparison ~3x faster than
ngram.NGram.compare():addok.helpers.results.compare_ngramsat startupTest plan
xo)