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,
- Run the database calls, calculations & notifying the GUI of the changes in data in a separate thread/task for each graph.
- 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.
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.