Can you make file copying faster through multiple threading?
Edit: To clarify, suppose you were implementing CopyFile(src, tgt). It seems logical that under certain circumstances you could use multiple threads to make it go faster.
Edit Some more thoughts:
Naturally, it depends on the HW/storage in question.
If you're copying from one disk to another, for example, it's pretty clear that you can read/write at the same time using two threads, thus saving the performance cost of the fastest of the two (usually reading). But you don't really need multiple threads for reading/writing in parallel, just async-IO.
But if async-IO can really speed things up (up to 2x) when reading/writing from different disks, why isn't this the default implementation of CopyFile? (or is it?)
If you are not careful you can make it slower. Disks are good at serialized access, if you have multiple threads the disk heads will be all over the place. Now if you are dealing with a high performance SAN maybe you have an improvement in performance, and the SAN will deal with optimizing the disk access.
Here's a blog post about file copy performance improvements in Vista SP1:
http://blogs.technet.com/markrussinovich/archive/2008/02/04/2826167.aspx
Doing high performance file copy is crazy and you have to take into account things like the cache behavior and network drivers limitations.
So always use the OS file copy function (under Windows it's FileCopyEx) and don't write your own.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With