Most download accelerators make fast downloads slower. Here's how I fixed mine.
Why opening 16 parallel connections backfires on fast CDNs, and how adaptive ramping, finish-last work stealing, and probe reuse fixed it in Veloce.
When I ran the first automated benchmark for Veloce against the Linux kernel archives, my multi-connection download accelerator lost to a plain single-stream GET. Not by a rounding error: the single stream finished at 11.05 MB/s, while Veloce 1.0 stumbled across the finish line at 5.62 MB/s. That's almost 2x slower.
Opening sixteen parallel TCP sockets up front to fetch a 6.6 MB archive was actively destroying throughput. The tool I had built to speed up transfers was penalizing users whenever the remote server was already fast. Here is why conventional multi-connection downloading backfires, and how I redesigned Veloce to fix it.
Why "More Connections" Backfires
Most download accelerators, my own v1.0 included, operate on a naive assumption: if one connection is good, sixteen connections must be sixteen times better. On real-world networks and modern content delivery infrastructure, that mental model breaks down in four distinct ways.
Handshake latency and round-trip penalties. Establishing a TCP socket requires a three-way handshake (SYN, SYN-ACK, ACK). Securing it with TLS 1.3 adds another full round trip for key exchange and certificate verification (TLS 1.2 requires two). On a cross-continental connection with a 140 ms RTT, opening sixteen sockets burns hundreds of milliseconds and significant CPU cycles in TLS crypto before a single application byte transfers. For small-to-medium files, the download would already be half-finished over an existing connection before the fifteenth worker socket even completes its TLS handshake.
TCP slow start contention. Every newly established TCP socket begins in slow start with an initial congestion window () of roughly 10 packets (~14 KB). Sockets must probe the path for available bandwidth by doubling their window each RTT until packet loss occurs. When you spawn sixteen sockets simultaneously over a consumer bottleneck link, sixteen uncoordinated slow-start ramps immediately saturate the router's queue. The resulting bufferbloat causes tail drops, packet loss, and simultaneous multiplicative window decreases across all sockets right at the beginning of the transfer.
CDNs that already saturate the pipe. In 2005, web servers ran un-tuned TCP stacks over distant transit links, and single-stream throughput often hovered well below line rate. In 2026, edge CDNs (Fastly, Cloudflare, Akamai) terminate connections at local edge points of presence with modern congestion control algorithms (such as BBR or paced CUBIC). A single warmed-up TCP connection frequently saturates the user's entire downlink. Slicing that stream into sixteen un-warmed chunks adds fragmentation and protocol overhead with zero possible throughput gain.
Server-side per-IP rate limits. Many high-traffic mirrors and open-source archives enforce aggregate rate limiting per client IP using token buckets. If a server restricts your IP to 2.5 MB/s, opening sixteen sockets does not yield 40 MB/s. It splits 2.5 MB/s across sixteen competing sockets, increasing latency, jitter, and segment synchronization overhead without moving the needle on completion time.
The Adaptive Engine Architecture
To solve these bottlenecks without abandoning multi-stream acceleration where it actually helps (such as throttled hosts like the Internet Archive), I rewrote Veloce's core scheduling around adaptive measurement, work stealing, and socket reuse. The engine is standard-library Python with zero runtime dependencies; the scheduler lives in one file, engine/segmenter.py.
Here are the key design mechanisms.
1. The Probe IS the Download
Conventional download managers send a HEAD request or a dummy Range: bytes=0-0 request to verify whether the server supports byte ranges, discard the connection, and then launch new worker threads. That wastes an entire round trip.
Veloce opens an open-ended Range: bytes=0- request immediately as its probe. The server begins streaming the payload from byte 0. If the file is non-resumable, small, or already saturated, the first worker simply inherits the primed socket and continues streaming without dropping a single byte or renegotiating TLS.
def _probe(self, ranged: bool): """The probe IS the download: `Range: bytes=0-`, kept open ("primed") so the first worker keeps reading it. No extra round trip, no extra TLS.""" headers = self._resolve_headers() if ranged: headers["Range"] = "bytes=0-" return _urlopen(urllib.request.Request(self.url, headers=headers), timeout=12)2. Measure, Then Decide
Rather than guessing concurrency upfront based on static file sizes, Veloce streams the first connection for exactly 0.4 seconds (FANOUT_DELAY) and measures the empirical throughput. It calculates the estimated time to completion (). If a single stream will finish within roughly 1.0 second (SINGLE_STREAM_ETA), the engine never fans out at all.
if not fanned_out: if now - started < FANOUT_DELAY: continue fanned_out = True done = self._downloaded() speed = done / max(now - started, 1e-3) remaining = self.total_size - done eta = remaining / speed if speed > 0 else float("inf") if eta < SINGLE_STREAM_ETA: ramping = False # one stream is enough else: # Long transfers fan out wider straight away; short ones gently target = 8 if eta > 4 else INITIAL_CONNECTIONS spawn(min(target, self._initial_connections()) - 1) window_start, window_bytes = now, done continueIf the file is a 6.6 MB kernel tarball streaming at 11 MB/s, it will finish in ~0.6 seconds. Veloce detects this at 0.4 seconds and leaves the single stream alone. Total handshakes: 1. Total speed: 10.39 MB/s.
3. Ramp Concurrency Only While Throughput Grows
When a download is large enough to warrant fan-out, opening sixteen sockets immediately is still risky. Veloce adds connections in increments of four (RAMP_STEP = 4).
Because newly spawned sockets take roughly one round trip () to exit slow start, judging their impact immediately produces false negatives. Veloce waits for an evaluation window of before evaluating aggregate throughput. If speed grew by at least 10% (RAMP_MIN_GAIN = 1.10), another 4 connections are added. If two consecutive evaluation windows fail to deliver improvement, the ramp permanently halts.
# New connections need ~TTFB before they deliver anything; judge them after that.if now - window_start < max(RAMP_INTERVAL, 2.5 * self.ttfb): continuewindow_speed = (self._downloaded() - window_bytes) / (now - window_start)window_start, window_bytes = now, self._downloaded() if self.adaptive: self.manager.shed_slow_connections() if ramping: has_room = self.manager.splittable_bytes() >= 4 * MIN_SPLIT_SIZE if not has_room or len(threads) >= self.num_connections: ramping = False elif last_window_speed == 0.0 or window_speed >= last_window_speed * RAMP_MIN_GAIN: last_window_speed = max(last_window_speed, window_speed) ramp_misses = 0 spawn(RAMP_STEP) else: # Throughput is noisy: only conclude "more sockets stopped helping" # (server cap, CDN edge, or the local link) after two flat windows in a row. ramp_misses += 1 if ramp_misses >= 2: ramping = False4. Dynamic Work Stealing: Split the Tail, Not the Biggest Piece
When a worker finishes its segment early, it steals work from an active worker by bisecting its remaining byte range. Almost every existing download accelerator implements work stealing by finding the segment with the largest remaining byte count (max(remaining)).
On real networks, that is the wrong metric. Consider this real scenario:
- Connection A has 10 MB remaining, transferring over a fast edge node at 10 MB/s. Its completion time is 1.0 second.
- Connection B has 4 MB remaining, stuck behind a congested router transferring at 0.5 MB/s. Its completion time is 8.0 seconds.
A naive downloader steals from Connection A because 10 MB > 4 MB. But Connection A was going to finish in one second anyway! Slicing Connection A does not accelerate the download; the entire process remains blocked for eight seconds waiting for Connection B to finish its tail.
Veloce evaluates each active segment by its estimated time to finish: . It bisects the segment that will finish last, stealing from the genuine bottleneck.
def split_largest_segment(self) -> Optional[Segment]: """ Dynamic Segmentation (work stealing): Picks the active segment that will finish *last* (largest remaining / its connection's speed) and bisects it. Pure largest-remaining-bytes picking ignores that a slow connection with less left can still be the tail that the whole download waits on. Segments whose speed isn't measurable yet fall back to remaining bytes. """ with self.lock: candidates = [ s for s in self.segments if s.active and not s.completed and s.remaining >= (MIN_SPLIT_SIZE * 2) ] if not candidates: return None now = time.monotonic() rated = [(s, s.rate(now)) for s in candidates] measured = [(s, r) for s, r in rated if r > 0] if measured: target = max(measured, key=lambda sr: sr[0].remaining / sr[1])[0] else: target = max(candidates, key=lambda s: s.remaining) rem = target.end - target.current + 1 split_point = target.current + (rem // 2) old_end = target.end target.end = split_point5. Shedding Slow Connections
Internet routing is non-deterministic. In a pool of eight sockets to an Anycast CDN, seven might hit a regional cache 15 ms away, while one socket gets routed to an origin across an ocean or gets placed on an oversubscribed line card.
Veloce gives every connection a 2.0-second grace period (SHED_GRACE) to ramp past TCP slow start. After that, any connection running slower than 25% of the fastest connection (best / 4) is actively shed. Its socket is closed immediately, and its uncompleted byte range is released back to the manager to be re-requested on a fresh connection.
def shed_slow_connections(self) -> int: """Flags connections far slower than the best one; their workers drop and re-request the range.""" with self.lock: now = time.monotonic() judged = [(s, s.rate(now)) for s in self.segments if s.active and not s.completed and now - s.assigned_at >= SHED_GRACE] if len(judged) < 2: return 0 best = max(r for _, r in judged) shed = 0 for s, r in judged: if (s.shed_count < SHED_MAX_PER_SEGMENT and r * SHED_RATIO < best and s.remaining > max(r, 1.0) * SHED_MIN_ETA): s.shed = True s.shed_count += 1 shed += 1 return shed6. Positional Writes, Crash-Safe Sidecars, and Worker Thread Safety
Many download managers write each chunk to a temporary file on disk (part1, part2), and then concatenate them when all segments finish. On a 10 GB file, concatenation forces the operating system to perform 10 GB of redundant disk I/O at the end of the download, spiking disk usage and stalling the machine.
Veloce pre-allocates a sparse temporary file <final>.veloce.part upfront. Worker threads write incoming chunks directly into their exact positional byte offsets using os.pwrite.
On POSIX systems, os.pwrite(fd, data, offset) is an atomic system call that does not modify the file descriptor's internal offset pointer, allowing multiple threads to write concurrently without file-pointer locks. On Windows, where pwrite is absent from the C runtime, Veloce provides a mutex-protected seek+write wrapper.
def _make_pwrite(): """os.pwrite is POSIX-only; on Windows emulate it with a locked seek+write.""" if hasattr(os, "pwrite"): return os.pwrite lock = threading.Lock() def _pwrite(fd: int, data: bytes, offset: int) -> int: with lock: os.lseek(fd, offset, os.SEEK_SET) return os.write(fd, data) return _pwriteA critical bug in multi-threaded downloaders involves file descriptor lifecycle races. If a download is paused or encounters an error and the main thread calls os.close(fd) while worker threads are still running, an active worker inside pwrite() might write data into an unrelated file descriptor that the operating system reallocated to another subsystem.
Veloce guarantees that all worker threads are signalled and joined before the underlying file descriptor is closed:
finally: # Stop workers and wait for them *before* closing the fd: a worker still inside # pwrite() after close() could write into an unrelated file that reused the fd number. self._stop_event.set() for t in threads: t.join() if self._fd is not None: os.close(self._fd) self._fd = None self.release_probe()Furthermore, in-progress downloads write to <final>.veloce.part alongside an atomic JSON sidecar (<final>.veloce.json) that records ETag, Last-Modified, and segment completion boundaries. Only when all segments pass strict byte-count verification does an os.replace atomically rename the .part file to the final destination.
7. Never Trust Accept-Ranges: Require HTTP 206
Many CDNs and application servers advertise Accept-Ranges: bytes in response headers, but silently ignore the Range header on actual requests, for instance when serving dynamic or un-cacheable content.
If an accelerator requests Range: bytes=1048576-2097151 and the server responds with HTTP 200 streaming the file from byte 0, writing those bytes at offset 1,048,576 corrupts the downloaded binary without triggering an I/O error.
Veloce validates that every ranged request returns HTTP 206 with a valid Content-Range: bytes START-END/TOTAL header. If a server ever returns HTTP 200 to a range slice mid-transfer, Veloce immediately aborts with RangeNotSupported to protect file integrity.
resp = self._take_primed(seg) or client.get(self.url, headers)if resp.status != 206: raise RangeNotSupported( f"Server ignored a Range request (HTTP {resp.status}); stopped to avoid a corrupt file" )Benchmarks
To evaluate the adaptive engine, I ran three rounds of automated tests comparing a single plain GET request, Veloce 1.0 (16 connections up front), and Veloce 1.1 (adaptive engine).
Methodology:
- One home connection in Kathmandu, Nepal, on 2026-11-12.
- Three runs per source, alternating between configurations each round to distribute transit noise evenly.
- Speeds reported are means of three runs.
Source Size Single Stream Veloce 1.0 Veloce 1.1----------------------------------------------------------------------------Internet Archive 59 MB 0.43 MB/s 4.47 MB/s 5.33 MB/sKernel.org CDN 6.6 MB 11.05 MB/s 5.62 MB/s 10.39 MB/sPython.org (Fastly) 19 MB 6.97 MB/s 7.47 MB/s 8.35 MB/sApache Archive 9.4 MB 1.42 MB/s 2.84 MB/s 2.59 MB/sSoundHelix 8.5 MB 1.87 MB/s 1.78 MB/s 1.50 MB/sWhat the Numbers Show
- Throttled servers win massively: On Internet Archive, single-stream transfers are capped at around 400 KB/s per connection. Veloce ramps connections up to the saturation limit, achieving 5.33 MB/s (~12x speedup).
- Fast CDNs don't regress: On Kernel.org's CDN, Veloce 1.0 was roughly 2x slower than a plain GET (5.62 MB/s vs 11.05 MB/s) due to slow start and TLS connection setup overhead. Veloce 1.1 detects that one stream will finish in under a second and stays on a single connection, matching plain GET at 10.39 MB/s.
- Where parallel connections cannot help: Apache's archive limits each IP, and SoundHelix varied a lot run to run. On both, Veloce 1.1 was slower than 1.0 or a single stream in my runs. When a host caps bandwidth per client IP, no download accelerator can bypass it. Veloce detects the lack of throughput gain and halts ramping, avoiding pointless socket churn.
What I Would Do Differently and Open Problems
- HTTP/2 and HTTP/3 Multiplexing: Slicing multiple
Rangerequests across streams over a single TCP/TLS connection or QUIC session would eliminate TCP connection overhead entirely. However, many CDN edges disable HTTP/2 byte-range multiplexing or throttle concurrent streams per session. - BBR vs CUBIC Dynamics: On lossy consumer links, CUBIC treats packet drops as congestion, cutting window size by 30-50%. Multiple parallel CUBIC streams artificially compete against each other. Benchmarking how adaptive ramping interacts with BBR v2/v3 is an active area of investigation.
- Dynamic Threshold Calibration: Hardcoded heuristics (
FANOUT_DELAY = 0.4s,SINGLE_STREAM_ETA = 1.0s) work well across standard broadband lines, but tuning them dynamically based on measured round-trip time () and bandwidth-delay product () would improve performance on satellite and high-latency cellular links.
Conclusion
Veloce is a lightweight desktop app and Chromium extension with an MIT-licensed, standard-library Python engine (about 22 MB of memory idle). It also grabs video through yt-dlp in a child process, but that is a story for another post.
The project is open source on GitHub: github.com/Firojpaudel/veloce.
You can inspect the engine in engine/segmenter.py and run the automated benchmark suite on your own connection via python3 scripts/benchmark_suite.py.