NOODB: Read Performance Improvement via Parallel.ForEach()

2 Simple changes resulted in a dramatic improvement in the read.

  1. Changed one of the for-loops to be a Parallel.ForEach
  2. 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.)

Leave a Reply

Please log in using one of these methods to post your comment: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: