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?)
You can see a benefit particularly if the files are on different devices in which case the I/O can be very effectively overlapped.
However, there are also cases where where you could easily cause thrashing of the hardware, so I don’t think it’s an optimization that should be taken lightly.
As far as the additional question you added:
I don’t know the internals of
CopyFile(), but I wouldn’t be surprised if they do not do it for a couple reasons:This is not to say it couldn’t or shouldn’t be done (or even that it isn’t done – I don’t know) – these are just a couple possible reasons why it might not be done.