open-webui/backend/open_webui/routers
G30 ee11069ef2
perf(ollama): offload multi-GB model file I/O with asyncio.to_thread (#25829)
The Ollama model upload and download handlers perform three stages
of sync file I/O on multi-GB model files inside async handlers:

1. Persist upload — file.file.read() + write() in a loop
2. SHA-256 hash — calculate_sha256() reads the file sequentially
3. Read for blob push — open().read() loads entire model into memory

All three stages block the event loop for the duration of the I/O.
For a 4GB model, each stage freezes the event loop for 10+ seconds
while every other user's request stalls.

Wrap each blocking stage in asyncio.to_thread() in both handlers:

- upload_model(): persist upload, calculate_sha256, blob read
- download_file_stream(): calculate_sha256, blob read

Benchmark (full pipeline: write + SHA-256 + read back, 3 trials):
- 200MB: max jitter 145ms → 1ms (145x improvement)
- 500MB: max jitter 1,026ms → 1ms (1,026x improvement)

File I/O is pure I/O — no GIL contention. asyncio.to_thread()
completely eliminates event loop blocking.
2026-06-29 03:48:48 -05:00
..
analytics.py refac 2026-06-29 01:38:41 -05:00
audio.py Escape voice-derived attributes in Azure TTS SSML (#25776) 2026-06-29 02:16:37 -05:00
auths.py refac 2026-06-29 03:42:36 -05:00
automations.py refac 2026-06-25 03:31:45 +01:00
calendar.py refac 2026-06-25 03:31:45 +01:00
channels.py fix: bind channel thread parent/reply to the URL channel (#25766) 2026-06-29 03:46:50 -05:00
chats.py fix(api): handle orphaned shared_chat rows when unsharing (#25632) 2026-06-29 03:20:46 -05:00
configs.py refac 2026-06-29 02:57:58 -05:00
evaluations.py refac 2026-06-25 03:31:45 +01:00
files.py perf(retrieval): make URL fetch and file hash non-blocking with asyncio.to_thread (#25822) 2026-06-29 03:46:24 -05:00
folders.py refac 2026-06-25 03:31:45 +01:00
functions.py refac 2026-06-25 03:31:45 +01:00
groups.py refac 2026-06-25 03:31:45 +01:00
images.py perf(images): offload validate_url() DNS resolution with asyncio.to_thread (#25825) 2026-06-29 02:31:24 -05:00
knowledge.py refac 2026-06-25 03:31:45 +01:00
memories.py refac 2026-06-29 00:35:54 -05:00
models.py refac 2026-06-29 02:43:14 -05:00
notes.py refac 2026-06-25 03:31:45 +01:00
ollama.py perf(ollama): offload multi-GB model file I/O with asyncio.to_thread (#25829) 2026-06-29 03:48:48 -05:00
openai.py refac 2026-06-25 03:31:45 +01:00
pipelines.py refac 2026-06-25 03:31:45 +01:00
prompts.py refac 2026-06-25 03:31:45 +01:00
retrieval.py refac 2026-06-29 03:21:41 -05:00
scim.py refac 2026-06-25 03:31:45 +01:00
skills.py feat(permissions): add workspace.skills_import and workspace.skills_export permissions (#25921) 2026-06-29 01:36:27 -05:00
tasks.py refac 2026-06-17 02:58:11 +02:00
terminals.py refac 2026-06-25 03:31:45 +01:00
tools.py solve-valves-icon-disappear-issue (#26256) 2026-06-29 00:56:44 -05:00
users.py perf(auth): make password hashing non-blocking and batch CSV user import (#25804) 2026-06-29 02:45:39 -05:00
utils.py refac 2026-06-17 02:52:35 +02:00