Commit 93c99f18 authored by Vitaly Lipatov's avatar Vitaly Lipatov

web-api: speed test — sequential with early exit, 5s timeout

Test gateways one by one in order: igw, dgw, gre.hetzner, gre.beget, ikev2.hetzner, warp. Stop after two consecutive successful downloads. Reduces total check time from ~2min to ~15s. Co-Authored-By: 's avatarClaude Opus 4.6 <noreply@anthropic.com>
parent 00f935e7
......@@ -274,7 +274,11 @@ def _check_throttle(name, proxy, asset_url):
return (name, None)
SPEED_CHECK_TIMEOUT = 15
SPEED_CHECK_TIMEOUT = 5
# Order for speed test: likely-slow first, stop after two successes in a row
SPEED_CHECK_ORDER = ["igw", "dgw", "gre.hetzner", "gre.beget.ogw",
"ikev2.hetzner", "warp"]
def _check_speed(name, proxy, file_url):
......@@ -379,18 +383,25 @@ def check_site(domain, file_url=None):
if result:
throttle[gw_name] = result
# Phase 3: speed check — download file URL via all gateways in parallel
# Phase 3: speed check — sequential, stop after two fast results in a row
speed = {}
if file_url:
with concurrent.futures.ThreadPoolExecutor(max_workers=len(CHECK_GATEWAYS)) as pool:
speed_futures = [
pool.submit(_check_speed, name, proxy, file_url)
for name, proxy, _pv6 in CHECK_GATEWAYS
]
for future in concurrent.futures.as_completed(speed_futures):
gw_name, res = future.result()
if res:
speed[gw_name] = res
gw_by_name = {name: proxy for name, proxy, _pv6 in CHECK_GATEWAYS}
consecutive_ok = 0
for gw_name in SPEED_CHECK_ORDER:
proxy = gw_by_name.get(gw_name)
if proxy is None:
continue
_name, res = _check_speed(gw_name, proxy, file_url)
if res:
speed[gw_name] = res
# "success" = downloaded enough (not timeout/error with tiny size)
if res and not res.get("error") and res.get("time", 99) < SPEED_CHECK_TIMEOUT - 0.5:
consecutive_ok += 1
if consecutive_ok >= 2:
break
else:
consecutive_ok = 0
ips = resolve_domain(domain)
routes = find_in_routes(domain, ips)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment