perf: per-key overlay cache locks and quantized bbox keys
Nearby pans share a 0.25° cache cell. Slow NWS/WFIGS factories no longer hold a process-wide lock that stalls trains/aircraft/radar fills.
This commit is contained in:
parent
07638288a9
commit
84532d505a
2 changed files with 91 additions and 8 deletions
|
|
@ -5,6 +5,7 @@ from live_layers import (
|
|||
bbox_center_radius_nm,
|
||||
filter_points_bbox,
|
||||
parse_bbox,
|
||||
quantize_bbox,
|
||||
rainviewer_tile_url,
|
||||
to_marker,
|
||||
transform_adsb_lol,
|
||||
|
|
@ -12,6 +13,8 @@ from live_layers import (
|
|||
transform_amtraker,
|
||||
transform_nhc_storms,
|
||||
transform_wfigs_incidents,
|
||||
_cache,
|
||||
_ttl_get,
|
||||
)
|
||||
|
||||
from camera_scraper import parse_caltrans_json
|
||||
|
|
@ -244,3 +247,43 @@ def test_parse_caltrans_skips_oos_and_maps_jpeg_hls():
|
|||
assert "I-80" in cam["location_name"]
|
||||
assert "rtsp://" not in cam["source_url"].lower()
|
||||
assert "rtsp://" not in cam["snapshot_url"].lower()
|
||||
|
||||
|
||||
def test_quantize_bbox_stable_under_jitter():
|
||||
a = quantize_bbox(*parse_bbox("-78.7912,35.7711,-78.6101,35.9102"))
|
||||
b = quantize_bbox(*parse_bbox("-78.7900,35.7700,-78.6110,35.9090"))
|
||||
assert a == b
|
||||
minlon, minlat, maxlon, maxlat = a
|
||||
assert minlon <= -78.7912
|
||||
assert minlat <= 35.7700
|
||||
assert maxlon >= -78.6101
|
||||
assert maxlat >= 35.9102
|
||||
|
||||
|
||||
def test_ttl_get_does_not_block_other_keys():
|
||||
import asyncio
|
||||
|
||||
_cache.clear()
|
||||
order = []
|
||||
|
||||
async def slow():
|
||||
order.append("slow-start")
|
||||
await asyncio.sleep(0.2)
|
||||
order.append("slow-end")
|
||||
return "S"
|
||||
|
||||
async def fast():
|
||||
order.append("fast")
|
||||
return "F"
|
||||
|
||||
async def run():
|
||||
t1 = asyncio.create_task(_ttl_get("slow", 5, slow))
|
||||
await asyncio.sleep(0.01)
|
||||
t2 = asyncio.create_task(_ttl_get("fast", 5, fast))
|
||||
await asyncio.gather(t1, t2)
|
||||
|
||||
asyncio.run(run())
|
||||
assert order.index("fast") < order.index("slow-end")
|
||||
assert _cache["slow"][1] == "S"
|
||||
assert _cache["fast"][1] == "F"
|
||||
_cache.clear()
|
||||
|
|
|
|||
Loading…
Reference in a new issue