Skip to content

Commit cd483db

Browse files
committed
check pt
1 parent d7a5484 commit cd483db

2 files changed

Lines changed: 16 additions & 8 deletions

File tree

api/v1/endpoints/detection.py

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
from fastapi import APIRouter, HTTPException, UploadFile, File, Query, Depends, Body
22
from typing import List, Optional, Dict, Any
3+
import asyncio
34
import io
45
import base64
56
from PIL import Image
@@ -95,10 +96,13 @@ async def detect_objects(
9596
threshold = confidence_threshold or default_threshold
9697
logger.debug(f"Using confidence threshold: {threshold}")
9798

98-
# Perform detection
99+
# Perform detection (run in thread pool to avoid blocking the event loop
100+
# so health probes can still respond during long-running inference).
99101
start_time = time.time()
100102
try:
101-
detections = detector.detect(processed_image, confidence_threshold=threshold)
103+
detections = await asyncio.to_thread(
104+
detector.detect, processed_image, confidence_threshold=threshold
105+
)
102106
detection_time = time.time() - start_time
103107
logger.info(f"Detection completed: {len(detections)} objects found in {detection_time*1000:.1f}ms")
104108

@@ -228,7 +232,9 @@ async def describe_image(
228232

229233
start_time = time.time()
230234
try:
231-
description = detector.describe(processed_image, length=length)
235+
description = await asyncio.to_thread(
236+
detector.describe, processed_image, length=length
237+
)
232238
process_time = time.time() - start_time
233239
logger.info(f"Describe completed in {process_time*1000:.1f}ms")
234240
logger.info(f"Description result: {description}")
@@ -291,7 +297,9 @@ async def query_image(
291297

292298
start_time = time.time()
293299
try:
294-
answer = detector.query(processed_image, question=question)
300+
answer = await asyncio.to_thread(
301+
detector.query, processed_image, question=question
302+
)
295303
process_time = time.time() - start_time
296304
logger.info(f"Query completed in {process_time*1000:.1f}ms")
297305
logger.info(f"Query answer: {answer}")

k8s/deployment.yaml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -79,10 +79,10 @@ spec:
7979
httpGet:
8080
path: /health
8181
port: 8000
82-
initialDelaySeconds: 10
83-
periodSeconds: 30
84-
timeoutSeconds: 10
85-
failureThreshold: 3
82+
initialDelaySeconds: 15
83+
periodSeconds: 60
84+
timeoutSeconds: 30
85+
failureThreshold: 5 # ~5 min of unresponsiveness before kill
8686
volumes:
8787
- name: hf-cache
8888
persistentVolumeClaim:

0 commit comments

Comments
 (0)