-
-
Notifications
You must be signed in to change notification settings - Fork 4.5k
fix: re-queue failed DB writes with bounded queue cap #15923
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
AlexsanderHamir
wants to merge
15
commits into
litellm_oct_alexsander_staging_three
Choose a base branch
from
litellm_mem_leak_on_db_failure
base: litellm_oct_alexsander_staging_three
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
fix: re-queue failed DB writes with bounded queue cap #15923
AlexsanderHamir
wants to merge
15
commits into
litellm_oct_alexsander_staging_three
from
litellm_mem_leak_on_db_failure
+184
−39
Conversation
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
- Add ProxyTimingMiddleware to capture request start time before auth - Ensures overhead measurement includes authentication, rate limiting, etc. - Update common_request_processing to use middleware timing - Middleware positioned before auth to measure complete proxy latency
Replace json.dumps with orjson.dumps in HTTP handler to reduce serialization latency for all LLM provider API calls.
Replace json.dumps/loads with orjson in streaming hot paths. Saves ~350ms per 1000-chunk streaming response.
- Move orjson from optional to required dependencies in pyproject.toml - Fixes ModuleNotFoundError when importing litellm core modules - orjson is used in llm_http_handler.py which is imported by core litellm
- Optimize jsonify_object() (24 call sites across codebase) - Optimize get_request_status() for metadata parsing Reduces CPU usage and improves database write latency.
- serialize_object() uses orjson for 3-5x faster dict serialization - get_prompt_caching_cache_key() skips encode/decode cycle - Maintains cache key compatibility
- Maintains circular reference detection - Preserves default=str fallback behavior - Used in 15+ files across proxy and integrations
- set_cache: orjson.dumps() returns bytes directly for S3 - get_cache: orjson.loads() parses bytes without decode step - 3-5x faster serialization + skips UTF-8 encode/decode
- Added @lru_cache(1024) to get_cooldown_cache_key() - Changed all 4 locations to use the cached method instead of recreating strings - Replaced f-strings with string concatenation for better performance Results: get_cooldown_cache_key dropped from 47MB to a few bytes and is no longer a top consumer. Memory leak still present. Next: Optimize heavy memory consumers so memory leaks become more obvious.
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
When database writes fail, flushed queue items were being dropped, leaving orphaned objects in memory until GC'd, adding pressure on the garbage collector. This change: - Re-queues failed transactions for retry when DB recovers - Caps re-queueing at MAX_QUEUE_SIZE_BEFORE_REQUEUE (5000 items) to prevent unbounded growth during prolonged DB outages - Drops transactions beyond cap to prioritize stability over completeness
60daf00 to
22557cf
Compare
305516f to
33db244
Compare
…leak_on_db_failure
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.
Title
fix: re-queue failed DB writes with bounded queue cap
Relevant issues
Pre-Submission checklist
Please complete all items before asking a LiteLLM maintainer to review your PR
tests/litellm/directory, Adding at least 1 test is a hard requirement - see detailsmake test-unitType
🧹 Refactoring
Changes
Impact