mirror of
https://github.com/unshackle-dl/unshackle.git
synced 2026-11-26 10:55:08 +00:00
perf(pipeline): fix pool starvation, unlock vault writes, prep mux
Stop remounting adapters on shared sessions (restores dropped 429/5xx retries, ends 16-conn pool starvation, pool sized to 64); defer DRM vault write-backs off the global lock; add mux output_path groundwork for future parallelism.
This commit is contained in:
@@ -504,9 +504,8 @@ def requests(
|
||||
# once per batch; download() skips it for segments
|
||||
output_dir.mkdir(parents=True, exist_ok=True)
|
||||
|
||||
# Use provided session or create a new optimized requests.Session
|
||||
# When a session is provided (e.g., service's RnetSession), don't mutate headers/cookies/proxy —
|
||||
# they're already set and the session may be shared across tracks.
|
||||
# Provided sessions may be shared across tracks: don't mutate or remount them. Remounting
|
||||
# drops the service's 429/5xx Retry config and races get_adapter() in other track threads.
|
||||
if session is None:
|
||||
session = Session()
|
||||
if headers:
|
||||
@@ -516,10 +515,6 @@ def requests(
|
||||
session.cookies.update(cookies)
|
||||
if proxy:
|
||||
session.proxies.update({"all": proxy})
|
||||
|
||||
# Mount HTTPAdapter with connection pooling sized to worker count.
|
||||
# Safe to do on any requests.Session — improves connection reuse for parallel downloads.
|
||||
if _is_requests_session(session):
|
||||
adapter = HTTPAdapter(pool_connections=max_workers, pool_maxsize=max_workers, pool_block=True)
|
||||
session.mount("https://", adapter)
|
||||
session.mount("http://", adapter)
|
||||
|
||||
@@ -422,6 +422,7 @@ class RemoteService:
|
||||
"https://",
|
||||
HTTPAdapter(
|
||||
max_retries=Retry(total=5, backoff_factor=0.2, status_forcelist=[429, 500, 502, 503, 504]),
|
||||
pool_maxsize=64,
|
||||
pool_block=True,
|
||||
),
|
||||
)
|
||||
|
||||
@@ -328,6 +328,7 @@ class Service(metaclass=ABCMeta):
|
||||
"https://",
|
||||
HTTPAdapter(
|
||||
max_retries=Retry(total=5, backoff_factor=0.2, status_forcelist=[429, 500, 502, 503, 504]),
|
||||
pool_maxsize=64,
|
||||
pool_block=True,
|
||||
),
|
||||
)
|
||||
|
||||
@@ -473,6 +473,7 @@ class Tracks:
|
||||
audio_expected: bool = True,
|
||||
title_language: Optional[Language] = None,
|
||||
skip_subtitles: bool = False,
|
||||
output_path: Optional[Path] = None,
|
||||
) -> tuple[Path, int, list[str]]:
|
||||
"""
|
||||
Multiplex all the Tracks into a Matroska Container file.
|
||||
@@ -488,6 +489,9 @@ class Tracks:
|
||||
title_language: The title's intended language. Used to select the best video track
|
||||
for audio metadata when multiple video tracks exist.
|
||||
skip_subtitles: Skip muxing subtitle tracks into the container.
|
||||
output_path: Explicit destination for the muxed container. When None (default) the
|
||||
path is derived from the first track, so callers muxing several track groups that
|
||||
share a video list must pass distinct paths to avoid clobbering each other.
|
||||
"""
|
||||
if self.videos and not self.audio and audio_expected:
|
||||
video_track = None
|
||||
@@ -688,17 +692,18 @@ class Tracks:
|
||||
]
|
||||
)
|
||||
|
||||
output_path = (
|
||||
self.videos[0].path.with_suffix(".muxed.mkv")
|
||||
if self.videos
|
||||
else self.audio[0].path.with_suffix(".muxed.mka")
|
||||
if self.audio
|
||||
else self.subtitles[0].path.with_suffix(".muxed.mks")
|
||||
if self.subtitles
|
||||
else chapters_path.with_suffix(".muxed.mkv")
|
||||
if self.chapters
|
||||
else None
|
||||
)
|
||||
if output_path is None:
|
||||
output_path = (
|
||||
self.videos[0].path.with_suffix(".muxed.mkv")
|
||||
if self.videos
|
||||
else self.audio[0].path.with_suffix(".muxed.mka")
|
||||
if self.audio
|
||||
else self.subtitles[0].path.with_suffix(".muxed.mks")
|
||||
if self.subtitles
|
||||
else chapters_path.with_suffix(".muxed.mkv")
|
||||
if self.chapters
|
||||
else None
|
||||
)
|
||||
if not output_path:
|
||||
raise ValueError("No tracks provided, at least one track must be provided.")
|
||||
|
||||
|
||||
Reference in New Issue
Block a user