How Surge Optimizes Downloads
Surge is designed to maximize download speeds by overcoming the limitations of standard browser downloads.
The Problem with Browser Downloads
Section titled “The Problem with Browser Downloads”A standard browser usually opens one HTTP connection to the server. A server usually limits the bandwidth it gives to a single connection to make it fair for all users. Download managers (like Surge) open multiple requests at once (16 by default in Surge). They use them to split the file into smaller parts and download those parts individually.
Connection Variability
Section titled “Connection Variability”Now all connections are also not created equal, there are fast connections and slow connections. because of stuff like load balancers and CDN’s and stuff. Download managers have a bunch of ways to optimize these connections.
The Top Optimizations in Surge
Section titled “The Top Optimizations in Surge”- Large chunks: We split the download into $num_workers parts and give each worker $(fileSize/numworkers) bytes to download. This ensures that each connection is large and efficient.
- HealthCheck: We find the mean speed of all workers. If there is a worker performing less than 0.3x of mean, we restart it in the hopes that it will get a better pathway to the server which will be faster.
- StealWork: Near the end, when fast workers are done and slow workers are still doing their work, we make the fast idle workers “steal work” from the slow workers.