I am creating a module (an exe, based on Dotnet) using which I am supposed to churn a huge data (100 million records) from a NoSql database (MongoDB) in shortest possible time and the logic consists of costly operations like encryption, decryption and this is critical data, so we need to be really careful with the same.
Currently the basic logic is in place but it is currently running really really slow ( i.e. 50 records / 5 mins using one single main thread). Now, to multi-thread it I am thinking to use, Task parallel library in which there might be two approaches:
- Using Parallel.For: this is an easier approach, in which the code will work as different threads.
- Using Different tasks for Batches: This approach has different tasks having lower - upper bounds using which the executions are separated and hence will not create a fuss. Though in this method still we need to figure out how to properly manage some task failures.
But mainly here the execution time is the burning issue. Which method here can give me better throughput? Or if any other method can be used?
Though I am building POCs for both, but any guidance will be helpful.