litellm/docs/my-website/docs
Javier de la Torre e6a7cae7e1
fix(apscheduler): prevent memory leaks from jitter and frequent job intervals (#15846)
* fix(apscheduler): prevent memory leaks from jitter and frequent job intervals

Fixes critical memory leak in APScheduler that causes 35GB+ memory allocations
during proxy startup and operation. The leak was identified through Memray
analysis showing massive allocations in normalize() and _apply_jitter()
functions.

Key changes:
1. Remove jitter parameters from all scheduled jobs - jitter was causing
   expensive normalize() calculations leading to memory explosion
2. Configure AsyncIOScheduler with optimized job_defaults:
   - misfire_grace_time: 3600s (increased from 120s) to prevent backlog
     calculations that trigger memory leaks
   - coalesce: true to collapse missed runs
   - max_instances: 1 to prevent concurrent job execution
   - replace_existing: true to avoid duplicate jobs on restart
3. Increase minimum job intervals:
   - PROXY_BATCH_WRITE_AT: 30s (was 10s)
   - add_deployment/get_credentials jobs: 30s (was 10s)
4. Use fixed intervals with small random offsets instead of jitter for
   job distribution across workers
5. Explicitly configure jobstores and executors to minimize overhead
6. Disable timezone awareness to reduce computation

Memory impact:
- Before: 35GB with 483M allocations during startup
- After: <1GB with normal allocation patterns

Performance notes:
- Minimum job intervals increased from 10s to 30s (configurable via env vars)
- Jobs can still be distributed across workers using random start offsets
- No functional changes to job behavior, only timing and memory optimization

Testing:
- Added comprehensive test suite for scheduler configuration
- Verified no job execution backlog on startup
- Tested duplicate job prevention with replace_existing

Related issue: Memory leak in production proxy servers with APScheduler

\ud83e\udd16 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>

* docs: update PROXY_BATCH_WRITE_AT default value from 10s to 30s

Update documentation to reflect the new default value for PROXY_BATCH_WRITE_AT
changed in PR #15846. The default was increased from 10 seconds to 30 seconds
to prevent memory leaks in APScheduler.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>

* refactor: Move APScheduler config to constants.py

Address code review feedback from ishaan-jaff:
- Move scheduler configuration variables (coalesce, misfire_grace_time,
  max_instances, replace_existing) to litellm/constants.py
- Update all references in proxy_server.py to use the constants
- Improves maintainability and makes configuration values centralized

Requested-by: @ishaan-jaff
Related: #15846

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>

---------

Co-authored-by: Claude <noreply@anthropic.com>
2025-10-28 19:30:17 -07:00
..
adding_provider Guardrails - Responses API, Image Gen, Text completions, Audio transcriptions, Audio Speech, Rerank, Anthropic Messages API support via the unified apply_guardrails function (#15706) 2025-10-25 13:38:57 -07:00
caching [Redis IAM] Change documentation (#13306) 2025-08-05 15:04:46 -07:00
completion fix the wrong request body in json mode doc (#15729) 2025-10-20 08:44:14 -07:00
debugging Update local_debugging.md (#8308) 2025-02-06 16:19:32 -08:00
embedding (feat)Litellm x twelvelabs bedrock[Async Invoke Support] (#14871) 2025-10-02 18:52:33 -07:00
extras docs(creating_adapters.md): document how to write an adapter 2025-10-21 16:20:31 -07:00
guides feat(ssl): add configurable ECDH curve for TLS performance 2025-10-14 13:57:39 -07:00
integrations docs: Letta Guide (#14798) 2025-09-23 16:18:57 -07:00
langchain added tags to langchain 2025-09-10 00:32:26 -04:00
observability Add details in docs (#15721) 2025-10-21 16:57:51 -07:00
pass_through VertexAI Search Vector Store - Passthrough endpoint support + Vector store search Cost tracking support (#15824) 2025-10-25 13:17:15 -07:00
projects added railtracks to projects using litellm (#15144) 2025-10-02 14:21:38 -07:00
provider_registration Integration: Bytez as a model provider (#12121) 2025-07-12 10:50:39 -07:00
providers fix errors in videos documentation (#15996) 2025-10-28 14:48:04 -07:00
proxy fix(apscheduler): prevent memory leaks from jitter and frequent job intervals (#15846) 2025-10-28 19:30:17 -07:00
search [Feat] Add cost tracking for Search API requests - Google PSE, Tavily, Parallel AI, Exa AI (#15821) 2025-10-22 17:29:09 -07:00
tutorials [Feat] add support for dynamic client registration (#15921) (enables Atlassian MCP to work via Oauth on LiteLLM) 2025-10-26 10:13:46 -07:00
vector_stores fix(managed_files.py): don't raise error if managed object is not found + (Feat) Azure AI - Search Vector Stores + (Fix) Batches - “User default_user_id does not have access to the object” when object not in db + (fix) Vector Stores - show config.yaml vector stores on UI (#15873) 2025-10-25 12:06:24 -07:00
aiohttp_benchmarks.md docs benchmarks 2025-05-24 17:43:38 -07:00
anthropic_unified.md Guardrails - Responses API, Image Gen, Text completions, Audio transcriptions, Audio Speech, Rerank, Anthropic Messages API support via the unified apply_guardrails function (#15706) 2025-10-25 13:38:57 -07:00
apply_guardrail.md Implement Bedrock Guardrail apply_guardrail endpoint support (#15892) 2025-10-24 10:24:03 -07:00
assistants.md Use the -d flag in docs instead of -D (#12179) 2025-06-30 15:25:42 -07:00
audio_transcription.md Guardrails - Responses API, Image Gen, Text completions, Audio transcriptions, Audio Speech, Rerank, Anthropic Messages API support via the unified apply_guardrails function (#15706) 2025-10-25 13:38:57 -07:00
batches.md docs fix 2025-09-12 19:51:14 -07:00
bedrock_converse.md docs boto3 instructions 2025-10-16 16:34:56 -07:00
bedrock_invoke.md docs boto3 instructions 2025-10-16 16:34:56 -07:00
benchmarks.md fix: add missing context (#15688) 2025-10-17 17:39:21 -07:00
budget_manager.md docs - use consistent name for LiteLLM proxy server 2024-08-03 12:54:07 -07:00
contact.md docs add slack support 2025-06-30 10:45:37 -07:00
contributing.md docs: cleanup docs 2025-10-02 09:51:16 -07:00
data_retention.md docs - Custom Retention Policies 2025-01-20 07:29:48 -08:00
data_security.md docs(data_security.md): data_security.md 2025-06-09 17:53:11 -07:00
default_code_snippet.md update docs 2023-08-25 17:02:43 -07:00
enterprise.md Corrected docs updates sept 2025 (#14916) 2025-09-25 15:49:19 -07:00
exception_mapping.md [Bug fix] Misclassified 500 error on invalid image_url in /chat/completions request (#14149) 2025-09-01 15:26:27 -07:00
files_endpoints.md Litellm managed files docs (#9948) 2025-04-12 13:02:33 -07:00
fine_tuning.md Corrected docs updates sept 2025 (#14916) 2025-09-25 15:49:19 -07:00
generateContent.md [Feat] Add /search endpoint on LiteLLM Gateway (#15780) 2025-10-21 19:05:20 -07:00
getting_started.md Corrected docs updates sept 2025 (#14916) 2025-09-25 15:49:19 -07:00
image_edits.md Corrected docs updates sept 2025 (#14916) 2025-09-25 15:49:19 -07:00
image_generation.md Guardrails - Responses API, Image Gen, Text completions, Audio transcriptions, Audio Speech, Rerank, Anthropic Messages API support via the unified apply_guardrails function (#15706) 2025-10-25 13:38:57 -07:00
image_variations.md New stable release - release notes (#8148) 2025-01-31 10:02:59 -08:00
index.md Corrected docs updates sept 2025 (#14916) 2025-09-25 15:49:19 -07:00
load_test.md (docs) add 1k rps load test doc (#6059) 2024-10-04 16:56:34 +05:30
load_test_advanced.md Remove aiohttp_ prefix from config (#14920) 2025-09-25 16:09:41 -07:00
load_test_rpm.md docs: usaged-based routing perf warnings (#14080) 2025-08-29 17:31:12 -07:00
load_test_sdk.md (docs) add 1k rps load test doc (#6059) 2024-10-04 16:56:34 +05:30
mcp.md [Feat] add support for dynamic client registration (#15921) (enables Atlassian MCP to work via Oauth on LiteLLM) 2025-10-26 10:13:46 -07:00
mcp_control.md [MCP Gateway] QA/Fixes - Ensure Team/Key level enforcement works for MCPs (#15305) 2025-10-07 17:34:48 -07:00
mcp_cost.md [MCP Gateway] QA/Fixes - Ensure Team/Key level enforcement works for MCPs (#15305) 2025-10-07 17:34:48 -07:00
mcp_guardrail.md [MCP Gateway] QA/Fixes - Ensure Team/Key level enforcement works for MCPs (#15305) 2025-10-07 17:34:48 -07:00
mcp_usage.md [MCP Gateway] QA/Fixes - Ensure Team/Key level enforcement works for MCPs (#15305) 2025-10-07 17:34:48 -07:00
migration.md (docs) update migration 2023-11-21 11:22:54 -08:00
migration_policy.md docs migration policy 2024-08-09 18:06:37 -07:00
moderation.md Corrected docs updates sept 2025 (#14916) 2025-09-25 15:49:19 -07:00
ocr.md [Docs] Add Azure AI - OCR to docs (#15768) 2025-10-21 13:10:45 -07:00
oidc.md Azure OIDC provider improvements + OIDC audience bug fix (#10054) 2025-05-28 09:33:13 -07:00
old_guardrails.md Use the -d flag in docs instead of -D (#12179) 2025-06-30 15:25:42 -07:00
projects.md docs 2023-09-08 20:55:04 -07:00
proxy_api.md Corrected docs updates sept 2025 (#14916) 2025-09-25 15:49:19 -07:00
proxy_server.md Contributor PR - Support OPENAI_BASE_URL in addition to OPENAI_API_BASE (#9995) (#10423) 2025-04-29 21:27:37 -07:00
realtime.md docs(realtime): yaml config example for realtime model (#10489) 2025-05-01 21:43:48 -07:00
reasoning_content.md update docs 2025-09-06 21:15:59 +09:00
rerank.md Guardrails - Responses API, Image Gen, Text completions, Audio transcriptions, Audio Speech, Rerank, Anthropic Messages API support via the unified apply_guardrails function (#15706) 2025-10-25 13:38:57 -07:00
response_api.md (security) Responses API - prevent User A from retrieving User B's response, if response.id is leaked (#15757) 2025-10-25 13:41:59 -07:00
router_architecture.md docs(router_architecture.md): add router architecture docs 2024-11-26 12:54:38 +05:30
routing.md docs: usaged-based routing perf warnings (#14080) 2025-08-29 17:31:12 -07:00
rules.md docs(rules.md): adding rules to docs 2023-11-20 19:14:07 -08:00
scheduler.md docs: usaged-based routing perf warnings (#14080) 2025-08-29 17:31:12 -07:00
sdk_custom_pricing.md organize docs 2024-08-03 12:54:07 -07:00
secret.md docs(admin_ui_sso.md): document /fallback/login flow 2025-07-16 09:07:42 -07:00
set_keys.md Contributor PR - Support OPENAI_BASE_URL in addition to OPENAI_API_BASE (#9995) (#10423) 2025-04-29 21:27:37 -07:00
text_completion.md Guardrails - Responses API, Image Gen, Text completions, Audio transcriptions, Audio Speech, Rerank, Anthropic Messages API support via the unified apply_guardrails function (#15706) 2025-10-25 13:38:57 -07:00
text_to_speech.md Guardrails - Responses API, Image Gen, Text completions, Audio transcriptions, Audio Speech, Rerank, Anthropic Messages API support via the unified apply_guardrails function (#15706) 2025-10-25 13:38:57 -07:00
troubleshoot.md changed docs 2025-09-16 00:58:08 -04:00
vertex_batch_passthrough.md Litellm sameer oct staging (#15806) 2025-10-24 12:17:22 -07:00
videos.md fix errors in videos documentation (#15996) 2025-10-28 14:48:04 -07:00
wildcard_routing.md Litellm dev 12 28 2024 p2 (#7458) 2024-12-28 19:38:06 -08:00