java multi thread programming on cmp system

35
Pree Thiengburanathum Nopparat Suwannarat 1

Category:

Education


7 download

TRANSCRIPT

Page 1: Java multi thread programming on cmp system

Pree ThiengburanathumNopparat Suwannarat

1

Page 2: Java multi thread programming on cmp system

AgendaBackgroundMotivationContributionWorking environmentProgram design and ImplementationsMeasurementsWorkloadsBenchmarkAnalysisConclusionQuestion

2

Page 3: Java multi thread programming on cmp system

Background – quick overviewMulti-programmingMulti-processingMulti-threadingThreadHomogenous CMP system

3

Page 4: Java multi thread programming on cmp system

BackgroundJAVA API Thread

start()run()wait()join()sleep()getName()isAlive()Thread.isSleep()

4

Page 5: Java multi thread programming on cmp system

JAVA Thread APIWait : public final void wait(long timeout,

int nanos) Causes the current thread to wait until another

thread invokes the method for this object, or some other thread interrupts the current thread, or a certain amount of real time has elapsed

Start : public void start()Causes this thread to begin execution; the Java

Virtual Machine calls the run method of this thread.

Page 6: Java multi thread programming on cmp system

JAVA Thread APIRun : public void run()

If this thread was constructed using a separate Runnable run object, then that Runnable object's run method is called; otherwise, this method does nothing and returns. Subclasses of Thread should override this method

Stop : public final void stop()An application should not normally try to catch

ThreadDeath unless it must do some extraordinary cleanup operation . If a catch clause catches a ThreadDeath object, it is important to rethrow the object so that the thread actually dies.

Page 7: Java multi thread programming on cmp system

JAVA Thread APISleep : public static void sleep(long millis)

Causes the currently executing thread to sleep for the specified number of milliseconds, subject to the precision and accuracy of system timers and schedulers. The thread does not lose ownership of any monitors.

Join : public final void join()Waits for this thread to die.

Page 8: Java multi thread programming on cmp system

MotivationMultithreading with JAVA on large problems.

For large computation problems, we would like to know how much performance will be improved if we use thread-based programming instead of execute by one process.

How multi processors affects when programming with JAVA thread.

Advantages and disadvantages of multithread programming with real applications.

Gain experiences with JAVA Thread, multi-thread programming, CMP system, and various tools.

8

Page 9: Java multi thread programming on cmp system

ContributionsSoftware : A JAVA program benchmark.

Why JAVA? Portability, can easily test on different operating

systems. Synchronization

Three Workloads (input) modules. Want to see the performance when having multiple

processors compute the workloads in multiprogramming environment.

9

Page 10: Java multi thread programming on cmp system

Working EnvironmentsOperating Systems

Microsoft Window VistaUbuntu, Linux-based operating system.VMWare virtual machine.

Tools and language Eclipse IDE with JAVA JRE 1.6.03, JRE 1.5.0_13Project hosting at (Google code) Subversion

repository URL: http://code.google.com/p/thread-

programming-multiprocessors/

10

Page 11: Java multi thread programming on cmp system

Working EnvironmentsGoogle code project.

11

Page 12: Java multi thread programming on cmp system

BenchmarkThree input(workloads), large problems

which can be divided into small sub problems.Trapezoid’s ruleSorting arrayFibonacci number

12

Page 13: Java multi thread programming on cmp system

Workloads Trapezoid's Rule To compute the area under the function or

Integrate the function by compute the summation of the small rectangular.

13

Page 14: Java multi thread programming on cmp system

Workloads Trapezoid's Rule (cont.) Trapezoid's Rule – An example of the

complicate function, a = 0, b = 10

14

Page 15: Java multi thread programming on cmp system

Workloads Trapezoid's Rule(cont.) Trapezoid's Rule – two threads and how

they are assigned.

15

Page 16: Java multi thread programming on cmp system

Workloads Sorting ArraysSorting Random Integer Arrays.

16

8949 -3467 -2367101 4050 2766 2

8949 -3467 -2367101 4050 2766 2

Thread 1 Thread 2 Thread 3

Array before sort

Assign a chuck of array to each thread.

Page 17: Java multi thread programming on cmp system

Workloads Sorting Arrays (cont.)Sorting Random Integer Arrays.

17

-3467 -2367 1012 2766 4050 8949

The Array after sort

Page 18: Java multi thread programming on cmp system

Workloads Fibonacci numberthe Fibonacci numbers are a sequence of

numbers named after Leonardo of Pisa, known as Fibonacci. The first number of the sequence is 0the second number is 1each subsequent number is equal to the sum of

the previous two numbers of the sequence itself

Page 19: Java multi thread programming on cmp system

Fibonacci number (cont.)F 0 F 1 F 2 F 3 F 4 F 5

0 1 1 2 3 5

The family trees of cows and bees, the Fibonacci series, the Fibonacci Spiral and sea shell shapes, branching plants, flower petal and seeds, leaves and petal arrangements, on pineapples and in apples, pine cones and leaf arrangements. All involve the Fibonacci

Page 20: Java multi thread programming on cmp system

Fibonacci number (cont.)

Page 21: Java multi thread programming on cmp system

Fibonacci number (cont.)

Page 22: Java multi thread programming on cmp system

Program Design – UML

22

Page 23: Java multi thread programming on cmp system

Program ImplementationExamples of program inputrapry@Morphine:~/csc5573/ThreadSim/ java ThreadSim 1Run workloads with 1 thread(s).Start trapaziod workload...Thread-1 is running trapazoid workload.Start sorting workload...execution time is: 3879000 nanoseconds.

Running fibo workload...Done finding fibonacci number.execution time is: 12,192,912,000 nanoseconds.Finished all the workloads.Total execution time is: 12.19874 seconds.

23

Page 24: Java multi thread programming on cmp system

MeasurementsNumber of thread and performance of large

problems.Performance in multiple processors environment.Performance in various operating systems

Window/Linux and so on.

Measurements on:Intel Core 2 Duo, 3.0Ghz, 2G RAM, Vista, UbuntuIntel Centrino Duo, 1.44Ghz, 2G RAM, VistaRun 3 times and find the average of the total

execution time.

24

Page 25: Java multi thread programming on cmp system

Benchmark – 1 Vista

25

JAVA Thread(s) run for each workload

Time in seconds

Page 26: Java multi thread programming on cmp system

Benchmark – 2 Vista

26Time in seconds

Page 27: Java multi thread programming on cmp system

Benchmark – 1 Ubuntu

27

JAVA Thread(s) run for each workload

Time in seconds

Page 28: Java multi thread programming on cmp system

Benchmark – 2 Ubuntu

28Time in seconds

Page 29: Java multi thread programming on cmp system

Results AnalysisBenchmark 1 (divide large problem into sub

problems)If we assign right number of thread to compute

the problems, better execution time.The more thread assign to the problem, the

worse performance we get.Benchmark 2 (a pack of workloads)

The more thread we assign to compute those problems, the worse execution time we will have.

29

Page 30: Java multi thread programming on cmp system

Results AnalysisFor a better results we will need

CPU Intensive application Need very large problem to compute in order to see

an improvement.I/O Intensive application

See significantly improvement of execution time. Example.

30

Page 31: Java multi thread programming on cmp system

ConclusionJAVA ThreadsAdvantages

Better interaction with user.Exploitation of multiple processors.Do other things while waiting for Slow I/O

operations.Simplify object modelingSynchronized, lock objects and classesInter-thread communication support

wait(), notify()

31

Page 32: Java multi thread programming on cmp system

Conclusion(cont.)JAVA Threads

Disadvantages Memory resources

Two stacks assigned by JavaVM One is used to keep track of java method calls and vars. The other stack is used to keep track of native code

calls Processor resources

Overhead, context switch Thread operations (start, stop, destroy). When adding additional threads to the design of a

system, these costs should be considered.

32

Page 33: Java multi thread programming on cmp system

Conclusion(cont.)JAVA Multi-thread programming

Less effective in single processor?Need to assign right number of thread, more thread

doesn’t mean good.No synchronization need. No critical section in the

program.Effective when the problem require intensive I/O

operation.Programmer has to know the problem well in order to

use thread-based programming to archive the maximum. utilization of system resources.

Easy to start, tough to master. Auto-garbage collection Tasks such as getting lock, releasing lock are simplified.

33

Page 34: Java multi thread programming on cmp system

References[1] JAVA Standard Edition 6 API, Sun Microsystems,

http://java.sun.com/javase/6/docs/api/, 2006[2] Eclipse IDE, www.eclipse.org, 2008

[3] Paul, H., Java Thread Programming, 1999[4] Scott O., Henry W., Java Threads 2nd edition, 2001[4] Operating System Concepts, by Silberschatz.

Galvin, and Gangne, 7th Edition , Wiley 2005.Fibonacci,

http://britton.disted.camosun.bc.ca/fibslide/jbfibslide.htmhttp://en.wikipedia.org/wiki/Fibonacci_number

34

Page 35: Java multi thread programming on cmp system

Question

35