A Multithreading C# A Multithreading C# Data Synchronization Data Synchronization Program Program and Its Realization and Its Realization Course: ECE 1747H Parallel Programming Course: ECE 1747H Parallel Programming Professor: Christiana Amza Professor: Christiana Amza Student / Presenter: Bin Li Student / Presenter: Bin Li Dec. 12, 2006 @ University of Toronto Dec. 12, 2006 @ University of Toronto
29
Embed
A Multithreading C# Data Synchronization Program and Its Realization Course: ECE 1747H Parallel Programming Professor: Christiana Amza Student / Presenter:
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
A Multithreading C# A Multithreading C# Data Synchronization Program Data Synchronization Program
and Its Realizationand Its Realization
Course: ECE 1747H Parallel ProgrammingCourse: ECE 1747H Parallel ProgrammingProfessor: Christiana AmzaProfessor: Christiana AmzaStudent / Presenter: Bin LiStudent / Presenter: Bin Li
Dec. 12, 2006 @ University of TorontoDec. 12, 2006 @ University of Toronto
Parallel Programming Professor: Christiana Amza Student: Bin Li Dec.12, 2006 @ University of Toronto2
AgendaAgenda
BackgroundBackground
Problem & SolutionProblem & Solution
Parallel ImplementationParallel Implementation
Performance MeasuringPerformance Measuring
Other ApproachesOther Approaches
Future WorkFuture Work
Q & AQ & A
Parallel Programming Professor: Christiana Amza Student: Bin Li Dec.12, 2006 @ University of Toronto3
Parallel Programming Professor: Christiana Amza Student: Bin Li Dec.12, 2006 @ University of Toronto5
AgendaAgenda
BackgroundBackground Problem & SolutionProblem & Solution
Parallel ImplementationParallel Implementation
Performance MeasuringPerformance Measuring
Other ApproachesOther Approaches
Future WorkFuture Work
Q & AQ & A
Parallel Programming Professor: Christiana Amza Student: Bin Li Dec.12, 2006 @ University of Toronto6
Problem & SolutionProblem & SolutionScheduled Data Synchronization (Scheduled Data Synchronization (iSynciSync process) starts at 10 pm, and ends at process) starts at 10 pm, and ends at 12 am12 am
iSynciSync extracts and transforms data from extracts and transforms data from Windows into ASCII file (.dat), and sends Windows into ASCII file (.dat), and sends it to Unixit to Unix
Mass data modification takes Mass data modification takes iSynciSync quite a long time (4-5 hours) to run, quite a long time (4-5 hours) to run, which is over 2-hour schedule limit which is over 2-hour schedule limit
The latest change (i.e. prices) in head The latest change (i.e. prices) in head office cannot reach stores before the office cannot reach stores before the opening hour of the next business dayopening hour of the next business day
Parallel Programming Professor: Christiana Amza Student: Bin Li Dec.12, 2006 @ University of Toronto7
Problem & Solution Problem & Solution (cont’d)(cont’d)
The store-side information delay causes The store-side information delay causes inaccurate sales information in retail inaccurate sales information in retail storesstores
Bottleneck: Bottleneck: iSync iSync (only 10% CPU usage (only 10% CPU usage on a 4-CPU database server)on a 4-CPU database server)
Parallel Programming Professor: Christiana Amza Student: Bin Li Dec.12, 2006 @ University of Toronto8
Problem & Solution Problem & Solution (cont’d)(cont’d)
Sequential programSequential programiSynciSync generates .dat file generates .dat file by each storeby each store, , which is slowwhich is slow
Parallel solutionParallel solutionImplementing Implementing qSyncqSync to replace to replace iSynciSync (using (using Microsoft C# multithreading)Microsoft C# multithreading)
Parallelly generating .dat file Parallelly generating .dat file by store by store groupsgroups
Parallel Programming Professor: Christiana Amza Student: Bin Li Dec.12, 2006 @ University of Toronto9
AgendaAgenda
BackgroundBackground Problem & SolutionProblem & Solution Parallel ImplementationParallel Implementation
Performance MeasuringPerformance Measuring
Other ApproachesOther Approaches
Future WorkFuture Work
Q & AQ & A
Parallel Programming Professor: Christiana Amza Student: Bin Li Dec.12, 2006 @ University of Toronto10
Design/UML Tool: Microsoft Visio 2003Design/UML Tool: Microsoft Visio 2003
Development Tool: Microsoft Visual Development Tool: Microsoft Visual Studio .NET 2003Studio .NET 2003Programming Language: Visual C# 2.0 Programming Language: Visual C# 2.0 ((multithreading similar to Linux PThreads)multithreading similar to Linux PThreads)
Parallelization StepsParallelization StepsStore Data SegmentationStore Data Segmentation
Parallel Data ProcessingParallel Data Processing
Result Data Consolidation Result Data Consolidation
Parallel Programming Professor: Christiana Amza Student: Bin Li Dec.12, 2006 @ University of Toronto11
Parallel Programming Professor: Christiana Amza Student: Bin Li Dec.12, 2006 @ University of Toronto15
Sample Code Sample Code (cont’d)(cont’d)
for (int i=0; i<dtb.Rows.Count; i++)for (int i=0; i<dtb.Rows.Count; i++){{ //...//...
threadDelegate = new ThreadStart(clpComponent.ExtCLPPrice);threadDelegate = new ThreadStart(clpComponent.ExtCLPPrice);threadObj = new Thread(threadDelegate);threadObj = new Thread(threadDelegate);threadObj.Name = Convert.ToString(i);threadObj.Name = Convert.ToString(i);threadList.Add(threadObj);threadList.Add(threadObj);//Start the thread//Start the threadthreadObj.Start();threadObj.Start();
}}// Join the threads// Join the threadsfor (int i = 0; i<dtb.Rows.Count; i++)for (int i = 0; i<dtb.Rows.Count; i++){{
Parallel Data Synchronization(CPU % Usage Comparison)
CPU Usage (%)
0
5001000
1500
20002500
3000
1 2 3 5 10 15 20
Number of Threads
Parallel Data Synchronization(Execution Time - seconds)
Execution Time(seconds)
Parallel Programming Professor: Christiana Amza Student: Bin Li Dec.12, 2006 @ University of Toronto20
AgendaAgenda
BackgroundBackground Problem & SolutionProblem & Solution Parallel ImplementationParallel Implementation Performance MeasuringPerformance Measuring Other ApproachesOther Approaches
Future WorkFuture Work
Q & AQ & A
Parallel Programming Professor: Christiana Amza Student: Bin Li Dec.12, 2006 @ University of Toronto21
Other Approaches Other Approaches (Approach #2)(Approach #2)
““Locking Temp Files”Locking Temp Files”
Parallel Programming Professor: Christiana Amza Student: Bin Li Dec.12, 2006 @ University of Toronto22
Other Approaches Other Approaches (Approach #2 cont’d)(Approach #2 cont’d)
““Locking Temp Files”Locking Temp Files”All threads write to single .dat fileAll threads write to single .dat file
Using lock for file appendingUsing lock for file appending
Result: bad as sequentialResult: bad as sequential
Explanation: same disk file cannot be Explanation: same disk file cannot be shared simultaneously by different threads, shared simultaneously by different threads, needs to close/re-open (different from needs to close/re-open (different from shared memory)shared memory)
Parallel Programming Professor: Christiana Amza Student: Bin Li Dec.12, 2006 @ University of Toronto23
Other Approaches Other Approaches (Approach #3)(Approach #3)
““Locking Temp Tables”Locking Temp Tables”
Parallel Programming Professor: Christiana Amza Student: Bin Li Dec.12, 2006 @ University of Toronto24
Other Approaches Other Approaches (Approach #3 cont’d)(Approach #3 cont’d)
““Locking Temp Tables”Locking Temp Tables”All threads share single temporary All threads share single temporary database tabledatabase table
Using lock for table record insertingUsing lock for table record inserting
Result: much better than sequential, not as Result: much better than sequential, not as good as the Main Approachgood as the Main Approach
Explanation: database server has enough Explanation: database server has enough memory; lock brings slight delaymemory; lock brings slight delay
Parallel Programming Professor: Christiana Amza Student: Bin Li Dec.12, 2006 @ University of Toronto25
AgendaAgenda
BackgroundBackground Problem & SolutionProblem & Solution Parallel ImplementationParallel Implementation Performance MeasuringPerformance Measuring Other ApproachesOther Approaches Future WorkFuture Work
Q & AQ & A
Parallel Programming Professor: Christiana Amza Student: Bin Li Dec.12, 2006 @ University of Toronto26
Further WorkFurther Work
Database ParallelismDatabase ParallelismUpgrading SQL Server 2000 to 2005Upgrading SQL Server 2000 to 2005
Migrating C# code of data synchronization Migrating C# code of data synchronization to database stored procedures, optimizing to database stored procedures, optimizing SQL queriesSQL queries
Changing temporary table(s) to permanent Changing temporary table(s) to permanent schemaschema
Using SQL Server Integration Services (SSIS Using SQL Server Integration Services (SSIS 2005) to do parallel data load & 2005) to do parallel data load & transformationtransformation
Accessing permanent table (which contains Accessing permanent table (which contains final data to be synchronized) to final data to be synchronized) to generate .dat filegenerate .dat file
Parallel Programming Professor: Christiana Amza Student: Bin Li Dec.12, 2006 @ University of Toronto27
Q & AQ & A
Thanks!Thanks!
Parallel Programming Professor: Christiana Amza Student: Bin Li Dec.12, 2006 @ University of Toronto28
Additional Slide for Q&A Additional Slide for Q&A (C#)(C#)
Simple, modern, object oriented Simple, modern, object oriented programming language derived from C and programming language derived from C and C++C++
Aims to combine the high productivity of Aims to combine the high productivity of Visual Basic and the raw power of C++.Visual Basic and the raw power of C++.
C# vs JavaC# vs JavaSimilar but not same in language Similar but not same in language specificationsspecifications
Compilation: C# to Microsoft Intermediate Compilation: C# to Microsoft Intermediate Language (MSIL), and Java to Java bytecode Language (MSIL), and Java to Java bytecode
Running: C# in Common Language Running: C# in Common Language Runtime (CLR), Java in Java Virtual Machine Runtime (CLR), Java in Java Virtual Machine (JVM)(JVM)
Parallel Programming Professor: Christiana Amza Student: Bin Li Dec.12, 2006 @ University of Toronto29
Additional Slide Additional Slide for Q&A for Q&A (Main Approach vs Approach #3)(Main Approach vs Approach #3)
0
200
400
600
800
Number of Threads
10 20
Parallel Data Synchronization(Execution Time - Seconds)