fix: add warmup OCR call to avoid timeout on first request
Some checks failed
Deploy to Coolify / deploy (push) Failing after 6s
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:
@@ -157,6 +157,8 @@ services:
|
|||||||
FLAGS_use_mkldnn: "0"
|
FLAGS_use_mkldnn: "0"
|
||||||
volumes:
|
volumes:
|
||||||
- paddleocr_models:/root/.paddleocr
|
- paddleocr_models:/root/.paddleocr
|
||||||
|
labels:
|
||||||
|
- "traefik.http.services.paddleocr.loadbalancer.server.port=8095"
|
||||||
deploy:
|
deploy:
|
||||||
resources:
|
resources:
|
||||||
limits:
|
limits:
|
||||||
|
|||||||
@@ -48,6 +48,13 @@ def _load_model():
|
|||||||
logger.info(f"PaddleOCR init strategy {i} failed: {e}")
|
logger.info(f"PaddleOCR init strategy {i} failed: {e}")
|
||||||
else:
|
else:
|
||||||
raise RuntimeError("All PaddleOCR init strategies failed")
|
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
|
_ready = True
|
||||||
logger.info("PaddleOCR model loaded successfully — ready to serve")
|
logger.info("PaddleOCR model loaded successfully — ready to serve")
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
|
|||||||
Reference in New Issue
Block a user