Click here to Skip to main content
15,890,186 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hi guys!

I'm creating an application for multi-segment downloading (many threads per single download) ...but I have a BIG QUESTION:

My program analyzes the remote file and creates segments/sections with equal ranges
so each thread downloads its own segment...Say, I want to download a file 70MB in size and
my program creates two threads to download ranges ( 0 - 35 MB; 35 - 70 MB)..
Each thread saves downloaded content in its OWN TEMPORARY FILE...

When download is complete my program simply merges those files, creates the final resulting FILE of them and when done DELETES those temporary files...

Is it effective to have several files per download?? IS it more effective to have one
temporary file and to use LOCKS to allow only one thread write downloaded content
in time and than try to sort bytes somehow and create the resulting file???

How do you think what choice is better???

I personally think that when I use many files per download I can easily merge them
cause my program tracks each segment and assigns index to it...so when download
is complete it sorts those segments by index and merges files easily BUT on other
side many files and many threads make hard drive to switch between hard drive clusters and tracks...

PLEASE HELP...
Posted
Updated 10-Oct-11 16:37pm
v7

Nick,

My personal choice would be running each thread per file. No need to have multiple threads for single file. Becaz of the application requirement.

Your application needs to download multiple files at the same time. Right? In that scenario, thread per file is the better option. Key reason is performance. CPU clock cycle is added up due to the file split algorithm + multi thread management for the single file + later merging. I don't think it will greatly add the performance value due to multithread per file.
 
Share this answer
 
Hello Nick,

I learned a lot creating my own downloader some time ago and I'd like to offer some suggestions.

First, 1 thread per download.
Create any number of connections you need for the segments in the same thread.
I actually tried 1 thread per segment, totally unnecessary.

Second, 1 file per download would be easier and requires no locking if you also use 1 thread per download.
Managing many files per download can be challenging, and if the download is big, merging would take some time.

Good luck with your code.
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900