I have attached the code to my combo of ChunkCopyManager (ActiveX exe with "5 - MultiUse" instancing) and ChunkCopyWorker (ActiveX exe with "3- Single Use" instancing).
You can call the ChunkCopyManager to copy a file like this:
Code:
Public Sub StartCopyFile(ByVal uSourceFilePath As String, ByVal uDestinationFilePath As String, ByVal uMaxWorkers As Long, ByVal uChunkSizeDefault4096 As Currency)
and it will create a copy, and a freely definable number of workers will each copy a chunk of the original file to this newly created copy.
I expected it to be faster than using a single process to do this, but it is significantly slower.
Would anybody willing to have a look if I made a mistake that would explain this degrade in speed?
Thank you.
Here are the timings that I observe:
Number of workers: 1
Duration (ms): 1781
Source: "D:\weg\bigfile.db"
Destination: "d:\weg\copy3.backup"
times:
Worker 1 took 1547 ms
Number of workers: 3
Duration (ms): 3234
Source: "D:\weg\bigfile.db"
Destination: "d:\weg\copy3.backup"
times:
Worker 1 took 1656 ms
Worker 2 took 2547 ms
Worker 3 took 2907 ms
Number of workers: 6
Duration (ms): 3282
Source: "D:\weg\bigfile.db"
Destination: "d:\weg\copy3.backup"
times:
Worker 1 took 969 ms
Worker 2 took 2109 ms
Worker 3 took 2453 ms
Worker 4 took 2422 ms
Worker 5 took 2656 ms
Worker 6 took 2859 ms
Number of workers: 51
Duration (ms): 4219
Source: "D:\weg\bigfile.db"
Destination: "d:\weg\copy3.backup"
times:
Worker 1 took 31 ms
Worker 2 took 32 ms
Worker 3 took 31 ms
Worker 4 took 79 ms
Worker 5 took 47 ms
Worker 6 took 31 ms
Worker 7 took 47 ms
Worker 8 took 31 ms
Worker 9 took 31 ms
Worker 10 took 79 ms
Worker 11 took 47 ms
Worker 12 took 31 ms
Worker 13 took 63 ms
Worker 14 took 47 ms
Worker 15 took 31 ms
Worker 16 took 32 ms
Worker 17 took 32 ms
Worker 18 took 47 ms
Worker 19 took 32 ms
Worker 20 took 63 ms
Worker 21 took 46 ms
Worker 22 took 32 ms
Worker 23 took 32 ms
Worker 24 took 31 ms
Worker 25 took 31 ms
Worker 26 took 141 ms
Worker 27 took 141 ms
Worker 28 took 1406 ms
Worker 29 took 1922 ms
Worker 30 took 2140 ms
Worker 31 took 2578 ms
Worker 32 took 2531 ms
Worker 33 took 2484 ms
Worker 34 took 2437 ms
Worker 35 took 2421 ms
Worker 36 took 2390 ms
Worker 37 took 2359 ms
Worker 38 took 2296 ms
Worker 39 took 2297 ms
Worker 40 took 2281 ms
Worker 41 took 2250 ms
Worker 42 took 2172 ms
Worker 43 took 2156 ms
Worker 44 took 2109 ms
Worker 45 took 2063 ms
Worker 46 took 2031 ms
Worker 47 took 1984 ms
Worker 48 took 1938 ms
Worker 49 took 1906 ms
Worker 50 took 1859 ms
Worker 51 took 859 ms
Edit: I tried again to find out more about the problem, then I stumbled across Olaf Schmidt's async CopyFolderTo Threading example, and I was devastated as this code runs almost 3 times faster than mine.
To make it short: I gave it and bow down to such a great solution. I hope I will once find the time to find out what he is doing what I am not doing.
In any case: Thank you for the cpu cycles saved, I guess? If not: Thanks for the lifetime saved. :-)
I expected it to be faster than using a single process to do this, but it is significantly slower.
Would anybody willing to have a look if I made a mistake that would explain this degrade in speed?
I don't think that copying files can benefit from multi-threading.