fix: add warmup OCR call to avoid timeout on first request
Some checks failed
Deploy to Coolify / deploy (push) Failing after 6s

PaddleOCR JIT-compiles on the first .ocr() call, which takes minutes
on CPU-only servers. This causes Traefik 504 Gateway Timeout.

Run a dummy OCR during startup so the first real request is fast.
Also simplify Traefik labels on paddleocr-service.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
Benjamin Admin
2026-03-13 16:55:07 +01:00
parent 46b1fdc20f
commit 4c68666c5c
2 changed files with 9 additions and 0 deletions

View File

@@ -157,6 +157,8 @@ services:
FLAGS_use_mkldnn: "0"
volumes:
- paddleocr_models:/root/.paddleocr
labels:
- "traefik.http.services.paddleocr.loadbalancer.server.port=8095"
deploy:
resources:
limits:

View File

@@ -48,6 +48,13 @@ def _load_model():
logger.info(f"PaddleOCR init strategy {i} failed: {e}")
else:
raise RuntimeError("All PaddleOCR init strategies failed")
# Warmup: run a dummy OCR to trigger JIT compilation
# Without this, the first real request takes minutes on CPU
logger.info("Running warmup OCR (JIT compilation)...")
dummy = np.ones((50, 200, 3), dtype=np.uint8) * 255
_engine.ocr(dummy)
logger.info("Warmup complete")
_ready = True
logger.info("PaddleOCR model loaded successfully — ready to serve")
except Exception as e: