This commit is contained in:
Team3
2026-07-05 13:07:12 +02:00
parent 6a765b7d89
commit fb3e967fdb
7 changed files with 122 additions and 57 deletions

View File

@@ -205,6 +205,9 @@ async def _race(topic: str, label: str, slots: list[dict], quorum: int, timeout:
born: dict[asyncio.Task, float] = {}
hedged: set[int] = set() # slot got its one twin — no hedge cascades
fertig: set[int] = set() # slot delivered a valid result (late twins are ignored)
# Hedge-Schwelle relativ zum Call-Timeout (HEDGE_NACH_S = Untergrenze): pauschale 90 s
# hedgten jeden gesunden langen Call — z. B. Guide-Fixes, die normal 110135 s laufen.
hedge_s = max(_HEDGE_NACH_S, timeout / 2) if _HEDGE_NACH_S else 0
loop = asyncio.get_running_loop()
start = loop.time()
min_deadline = start + min_runtime if min_runtime else None
@@ -266,14 +269,14 @@ async def _race(topic: str, label: str, slots: list[dict], quorum: int, timeout:
# Hedge: a slot running HEDGE_NACH_S without result gets ONE parallel twin
# (key -h) — first valid result wins. Stalled provider calls burned the full
# timeout cap before the restart even began (measured: 160230 s per stall).
if _HEDGE_NACH_S:
if hedge_s:
now = loop.time()
for t in [t for t in list(tasks) if tasks[t] not in hedged | fertig
and now - born[t] >= _HEDGE_NACH_S]:
and now - born[t] >= hedge_s]:
i = tasks[t]
hedged.add(i)
spawn(i, suffix="-h")
_log(topic, f"{label} {i + 1}: {_HEDGE_NACH_S}s ohne Ergebnis — Hedge-Zwilling gestartet")
_log(topic, f"{label} {i + 1}: {round(hedge_s)}s ohne Ergebnis — Hedge-Zwilling gestartet")
# Wake up for the earliest relevant deadline (grace, min, max, or next hedge).
waits = []
if deadline is not None and len(results) >= quorum:
@@ -282,8 +285,8 @@ async def _race(topic: str, label: str, slots: list[dict], quorum: int, timeout:
waits.append(min_deadline - loop.time())
if max_deadline is not None:
waits.append(max_deadline - loop.time())
if _HEDGE_NACH_S:
naechste = [born[t] + _HEDGE_NACH_S - loop.time() for t in tasks
if hedge_s:
naechste = [born[t] + hedge_s - loop.time() for t in tasks
if tasks[t] not in hedged | fertig]
if naechste:
waits.append(max(0.0, min(naechste)))