Here's the list of tasks that I need to complete:
- Read a chunk of the file (Disk IO Bound)
- Encrypt said chunk (CPU Bound)
- Upload said chunk (Network IO Bound)
- Repeat until file is uploaded
The problem lies in how to accomplish this with maximum efficiency and performance.
I've tried using Parallel.For
to encapsulate the entire operation block, but I don't think this is the best way about approaching this problem considering each operation has different characteristics about it that can be accounted for (as I point out in the list above).
After reading this TPL article suggested in this question, and after reviewing the empirical data in that question, I think TPL is the way I want to go. But how should I break this up for maximum efficiency and performance? Should I even bother trying to multi-thread the first two operations considering the upload is likely to be the bottleneck of the whole operation?
Thanks for your input.
Edit:
I've tried using Tasks and ContinueWith to let the OS deal with it, but I think I'm hitting another wall -- when I wait for all of my Upload tasks to complete, it seems like the garbage collector isn't cleaning up the data that I read in to upload and as such I end up running out of memory. Yet another bound to consider.