tags:

views:

75

answers:

3

We need to develop a dashboard application for a giant screen. What it is does is collect all KPIs(Key Performance Indicators) and shows it on the giant screen in realtime in a visual manner so that the management leads know whats going on.

So giant screen will have 20 to 30 independent graphs & pie charts(the number might increase soon) data needs to be refreshed at a configurable amount of time. What it technically means is lot of database calls to pull the data and notify the data changes to the GUI. As there are many individual graphs to update, I do not want to update them synchronously because a time consuming database query of one graph will delay the update of another graph.

So I have two choices here,

  1. Run the database calls, calculations & notifying the GUI of the changes in data in a separate thread/task for each graph.
  2. Write all the database calls as asynchronous methods, implement calculations and notifying the GUI in the callbacks

Though either of the method will suffice the purpose, I want to know which solution is better especially considering the fact the hardware has 16 cores. What are the advantages and disadvantages of both of these methods? or Is there any better approach for this problem?

We are planning to use .NET 4.0 & WPF for the UI & C# as development language.

A: 

Each of those methods will use multi-threading to achieve your goal.

Asynchronous methods just make the heavy lifting portion a little easier (they are asynchronous because they start on another thread and notify the original thread upon completion).

Justin Niessner
+5  A: 

I think the key points about the two techniques are following:

  • Multi-threaded approach limits the number of operations you can do in parallel, because threads are relatively expensive resources. However if you need something like ~20 threads, you won't have any troubles. It may be easier to write this in C#, because you can use usual sequential programming style.

  • Asynchronous calls allow you to perform much larger number of I/O bound operations "in parallel", because each call does not occupy an entire thread, so this is more efficient and also benefits from the multiple cores on the system (because asynchronous operations are handled using thread pool). This may be more difficult to use from C#, because you need to use the APM methods such as BeginXyz (which makes some usual programming patterns hard to encode).

You can use some advanced libraries for writing asynchronous code in C# - for example AsynchronousEnumerator gives you a relatively comfortable programming style. You may also consider using F# which has asynchronous workflows and message passing concurrency, which would be quite likely a perfect match for your problem.

Tomas Petricek
Any other language do you suggest to make async easier. I kind of liking the asynchronous approach than the threads.
funwithcoding
+2  A: 

I recommend using PLINQ and the task parallel library if possible. They include optimum partitioning, thread scaling, and work stealing all built-in.

Stephen Cleary