Proxy: log slow segment transfers (TTFB>3s or total>8s)
Distinguishes CDN-side stalls (server sees slow TTFB) from client-path stalls (server fast, user still times out) when fragLoadTimeOut recurs.
This commit is contained in:
1 parent
19bc2afb32
commit
83a2953a1c
1 file changed
+15
-1
+15
-1
@@ -488,9 +488,12 @@ def _cache_put(url, ct, body):
|
|||||||
def _seg_stream(r, url, ct):
|
def _seg_stream(r, url, ct):
|
||||||
"""Forward the CDN's bytes as they arrive; keep the LRU warm for
|
"""Forward the CDN's bytes as they arrive; keep the LRU warm for
|
||||||
completed downloads (a truncated one would poison the cache)."""
|
completed downloads (a truncated one would poison the cache)."""
|
||||||
buf, complete = [], False
|
import time
|
||||||
|
t0, t_first, buf, complete = time.time(), None, [], False
|
||||||
try:
|
try:
|
||||||
for c in r.iter_content(chunk_size=256 * 1024):
|
for c in r.iter_content(chunk_size=256 * 1024):
|
||||||
|
if t_first is None:
|
||||||
|
t_first = time.time()
|
||||||
buf.append(c)
|
buf.append(c)
|
||||||
yield c
|
yield c
|
||||||
complete = True
|
complete = True
|
||||||
@@ -498,6 +501,17 @@ def _seg_stream(r, url, ct):
|
|||||||
r.close()
|
r.close()
|
||||||
if complete and buf:
|
if complete and buf:
|
||||||
_cache_put(url, ct, b"".join(buf))
|
_cache_put(url, ct, b"".join(buf))
|
||||||
|
# observability: a slow segment is the fragLoadTimeOut culprit. Log
|
||||||
|
# only the slow ones so normal playback stays quiet. TTFB>3s or
|
||||||
|
# total>8s means the CDN (or our upstream hop) stalled — that's what
|
||||||
|
# the browser times out on. If these show ~0s but the user still
|
||||||
|
# fails, the stall is in *their* path (HTTPS proxy / network), not ours.
|
||||||
|
ttfb = (t_first - t0) if t_first is not None else None
|
||||||
|
total = time.time() - t0
|
||||||
|
if (ttfb is not None and ttfb > 3) or total > 8:
|
||||||
|
name = url.rsplit("/", 1)[-1][:40]
|
||||||
|
print(f"[stream-slow] {name} ttfb={ttfb:.1f}s total={total:.1f}s "
|
||||||
|
f"bytes={sum(len(b) for b in buf)} complete={complete}", flush=True)
|
||||||
|
|
||||||
|
|
||||||
def _stream_playlist(url):
|
def _stream_playlist(url):
|
||||||
|
|||||||
Reference in new issue
Block a user