Skip to content

Parallelize keg downloads with ThreadPoolExecutor#111

Open
Smiie-2 wants to merge 1 commit into
0xf4b1:masterfrom
Smiie-2:fix/parallel-keg-downloads-upstream
Open

Parallelize keg downloads with ThreadPoolExecutor#111
Smiie-2 wants to merge 1 commit into
0xf4b1:masterfrom
Smiie-2:fix/parallel-keg-downloads-upstream

Conversation

@Smiie-2
Copy link
Copy Markdown

@Smiie-2 Smiie-2 commented Apr 7, 2026

Problem

keg fetches every file sequentially — one HTTP request completes before the next starts. For a full Hearthstone install this means downloading ~21,951 loose files at ~5-6s each, totalling ~36 hours.

The bottleneck is network round-trip latency, not bandwidth, so parallelism helps significantly.

Fix

Replace the sequential for item in queue.drain(): item.fetch() loops in keg/bin/ngdp with ThreadPoolExecutor (32 workers) for both:

  • Metadata phase (archive indices — 93 files)
  • Data phase (loose files — ~21,951 files)

Also fixes all os.makedirs calls in keg/keg/cdn.py to use exist_ok=True, preventing race conditions when concurrent threads try to create the same directory.

Result

~21,951 loose files at ~5s each:

  • Before: ~36 hours (sequential)
  • After: ~1-2 hours (32 workers)

Testing

Verified on EU region — full fresh install completed successfully with parallel downloads active. Game launches and is playable.

🤖 Generated with Claude Code

Replace sequential per-file HTTP fetching in keg with
concurrent.futures.ThreadPoolExecutor (32 workers) for both the
metadata (archive indices) and data (loose files) download phases.

Also fix all os.makedirs calls in keg/keg/cdn.py to use exist_ok=True
to prevent race conditions when multiple threads create the same
directory simultaneously.

With 21,951 loose files to download, this reduces install time from
~36 hours (sequential, ~6s/file) to ~1-2 hours (32 parallel workers).

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant