[AZ-180] Refactor detection event handling and improve SSE support

- Updated the detection image endpoint to require a channel ID for event streaming.
- Introduced a new endpoint for streaming detection events, allowing clients to receive real-time updates.
- Enhanced the internal buffering mechanism for detection events to manage multiple channels.
- Refactored the inference module to support the new event handling structure.

Made-with: Cursor
This commit is contained in:
Oleksandr Bezdieniezhnykh
2026-04-03 02:42:05 +03:00
parent 2c35e59a77
commit 8baa96978b
26 changed files with 819 additions and 413 deletions
+8 -34
View File
@@ -1,5 +1,4 @@
import json
import time
import pytest
@@ -19,20 +18,13 @@ def _percentile_ms(sorted_ms, p):
@pytest.mark.timeout(60)
def test_nft_perf_01_single_image_latency_p95(
warm_engine, http_client, image_small, auth_headers
warm_engine, image_detect, image_small
):
times_ms = []
for _ in range(10):
t0 = time.perf_counter()
r = http_client.post(
"/detect/image",
files={"file": ("img.jpg", image_small, "image/jpeg")},
headers=auth_headers,
timeout=8,
)
elapsed_ms = (time.perf_counter() - t0) * 1000.0
assert r.status_code == 200
_, elapsed_ms = image_detect(image_small, "img.jpg", timeout=8)
times_ms.append(elapsed_ms)
sorted_ms = sorted(times_ms)
p50 = _percentile_ms(sorted_ms, 50)
p95 = _percentile_ms(sorted_ms, 95)
@@ -47,34 +39,16 @@ def test_nft_perf_01_single_image_latency_p95(
@pytest.mark.timeout(60)
def test_nft_perf_03_tiling_overhead_large_image(
warm_engine, http_client, image_small, image_large, auth_headers
warm_engine, image_detect, image_small, image_large
):
t_small = time.perf_counter()
r_small = http_client.post(
"/detect/image",
files={"file": ("small.jpg", image_small, "image/jpeg")},
headers=auth_headers,
timeout=8,
)
small_ms = (time.perf_counter() - t_small) * 1000.0
assert r_small.status_code == 200
config = json.dumps(
{"altitude": 400, "focal_length": 24, "sensor_width": 23.5}
)
t_large = time.perf_counter()
r_large = http_client.post(
"/detect/image",
files={"file": ("large.jpg", image_large, "image/jpeg")},
data={"config": config},
headers=auth_headers,
_, small_ms = image_detect(image_small, "small.jpg", timeout=8)
_, large_ms = image_detect(
image_large, "large.jpg",
config=json.dumps({"altitude": 400, "focal_length": 24, "sensor_width": 23.5}),
timeout=20,
)
large_ms = (time.perf_counter() - t_large) * 1000.0
assert r_large.status_code == 200
assert large_ms < 30_000.0
print(
f"nft_perf_03_csv,baseline_small_ms,{small_ms:.2f},large_ms,{large_ms:.2f}"
)
assert large_ms > small_ms - 500.0