mirror of
https://github.com/open-webui/open-webui.git
synced 2026-07-10 04:20:44 +02:00
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.