Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Parallelism in .Net

I have been asked to show the benefits and limitations of Parallelism and evaluate it for use within our company. We are predominantly a data orientated business, and essentially load objects from the database, then put them through some business logic, display to the user, then save back to the DB. In my mind, there isn't too much in that pipe line that would benefit from running in parallel, but being fairly new to the concept, I could be completely wrong. Would there be any part of that simple pipe line that would benefit from running in parallel? And are there any guidelines for how to implement this style of programming?

Also, are there any tools (preferably that come with VS2010) that would show where bottle necks occur and would be able to visually show what's going on when I click "Go" on a simple app that runs a given amount of loops (pre-written simple maths loops e.g. for i as integer = 1 to 1000 - do some calculations) in parallel, then in series?

I need to be able to display the difference using a decent profiling tool.

like image 330
Ben Avatar asked Jun 04 '10 11:06

Ben


2 Answers

Yes, even from that simple model you could greatly benefit from parrallelism.

Say for instance that during a load of your data you're doing something like this:

foreach(var datarow in someDataSet)
{
    //put your data into some business objects here
}

you could optimize this with parrallelism by doing something like this:

Parrallel.ForEach(someDataSet, datarow =>
{
    //put your data into some business objects here
});

This could greatly increase your performance depending on how much data your processing here.

Each data row will now be processed asynchronously instead of in sequence like the typical foreach loop.

My suggestion to you would be to run some simple performance tests on an example as simple as this one and see what kind of results you get. Plot it out in a spreadsheet or something, and show it to your team. You might be suprised with the results you get.

like image 197
Joseph Avatar answered Sep 19 '22 12:09

Joseph


You may reap more benefit from implementing a caching layer (distributed or otherwise) than parallelizing your current pipeline.

With a caching layer, the objects you use frequently will reside in the in-memory cache, allowing for much greater read/write performance. There are a number of options for keeping the cache in sync, and these will vary depending on which vendor you choose.

I'd suggest having a look at MemCached and NCache and see if you think they would be a good fit.

EDIT: As far as profiling tools go, I've used dotTrace extensively and would highly recommend it. You can download a 30 day trial from JetBrains' website.

like image 35
Winston Smith Avatar answered Sep 18 '22 12:09

Winston Smith