From 4c68666c5cd62823635a51cb09c4ea8665a82a23 Mon Sep 17 00:00:00 2001 From: Benjamin Admin Date: Fri, 13 Mar 2026 16:55:07 +0100 Subject: [PATCH] fix: add warmup OCR call to avoid timeout on first request 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 --- docker-compose.coolify.yml | 2 ++ paddleocr-service/main.py | 7 +++++++ 2 files changed, 9 insertions(+) diff --git a/docker-compose.coolify.yml b/docker-compose.coolify.yml index 3c7463e..22ca9ee 100644 --- a/docker-compose.coolify.yml +++ b/docker-compose.coolify.yml @@ -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: diff --git a/paddleocr-service/main.py b/paddleocr-service/main.py index 04b7e77..455136d 100644 --- a/paddleocr-service/main.py +++ b/paddleocr-service/main.py @@ -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: