2 Simple changes resulted in a dramatic improvement in the read.
- Changed one of the for-loops to be a Parallel.ForEach
- Changed a Collection<string> to SynchronizedCollection<string>
I performed a read of 1,000 objects 20 times.
Before (previous post): 10143ms to 10956ms
After: 3549ms to 4009ms. (most are 3600 – 3800).
That’s a dramatic increase. Yay microsoft!
However, in cases when there are only 1 or a few objects, using Parallel may be slower. I’ll have to test that, too, and see if its worthwhile to be sometimes parallel and sometimes not.
I took a look at the WRITE; There isn’t any opportunity to use PARRALLEL there, yet, because it only accepts one object at a time. When I add an overload to accept multiple, then maybe. The write is pretty basic at this point; it’s only doing inserts, not updates. The concurrency issues there are going to be delicate.
The client does the insert within a loop. I can change that the a parallel and get the records in quicker, but the numbers wouldn’t mean anything until the update is in there. (IE: it’s inserting the same author 1,000 times. It should be unique by id.)