
Thesis no: URI: urn:nbn:se:bth-16548 Parallelism in Go and Java A Comparison of Performance Using Matrix Multiplication Tobias Andersson and Christoffer Brenden Faculty of Computing Blekinge Institute of Technology SE-371 79 Karlskrona Sweden This thesis is submitted to the Faculty of Computing at Blekinge Institute of Technology in partial fulfillment of the requirements for the bachelor degree in Software Engineering. The thesis is equivalent to 10 weeks of full time studies. Contact Information: Authors: Tobias Andersson Email: [email protected] Christoffer Brenden Email: [email protected] University advisor: Dr. Fabian Fagerholm Department of Software Engineering Faculty of Computing Internet : www.bth.se Blekinge Institute of Technology Phone : +46 455 38 50 00 SE-371 79 Karlskrona, Sweden Fax : +46 455 38 50 57 i ABSTRACT This thesis makes a comparison between the performance of Go and Java using parallelized implementations of the Classic Matrix Multiplication Algorithm (CMMA). The comparison attempts to only use features for parallelization, goroutines for Go and threads for Java, while keeping other parts of the code as generic and comparable as possible to accurately measure the performance during parallelization. In this report we ask the question of how programming languages compare in terms of multithreaded performance? In high-performance systems such as those designed for mathematical calculations or servers meant to handle requests from millions of users, multithreading and by extension performance are vital. We would like to find out if and how much of a difference the choice of programming language could benefit these systems in terms of parallelism and multithreading. Another motivation is to analyze techniques and programming languages that have emerged that hide the complexity of handling multithreading and concurrency from the user, letting the user specify keywords or commands from which the language takes over and creates and manages the thread scheduling on its own. The Go language is one such example. Is this new technology an improvement over developers coding threads themselves or is the technology not quite there yet? To these ends experiments were done with multithreaded matrix multiplication and was implemented using goroutines for Go and threads for Java and was performed with sets of 4096x4096 matrices. Background programs were limited and each set of calculations was then run multiple times to get average values for each calculation which were then finally compared to one another. Results from the study showed that Go had ~32-35% better performance than Java between 1 and 4 threads, with the difference diminishing to ~2-5% at 8 to 16 threads. The difference however was believed to be mostly unrelated to parallelization as both languages maintained near identical performance scaling as the number of threads increased until the scaling flatlined for both languages at 8 threads and up. Java did continue to gain a slight increase going from 4 to 8 threads, but this was believed to be due to inefficient resource utilization on Java’s part or due to Java having better utilization of hyper-threading than Go. In conclusion, Go was found to be considerably faster than Java when going from the main thread and up to 4 threads. At 8 threads and onward Java and Go performed roughly equal. For performance difference between the number of threads in the languages themselves no noticeable performance increase or decrease was found when creating 1 thread versus running the matrix multiplication directly on the main thread for either of the two languages. Coding multithreading in Go was found to be easier than in Java while providing greater to equal performance. Go just requires the ‘go’ keyword while Java requires thread creation and management. This would put Go in favor for those trying to avoid the complexity of multithreading while also seeking its benefits. Keywords: Goroutines, Threads, Comparison, Matrices CONTENTS ABSTRACT ...........................................................................................................................................I CONTENTS .......................................................................................................................................... 1 GLOSSARY .......................................................................................................................................... 2 1. INTRODUCTION ....................................................................................................................... 3 MOTIVATION ......................................................................................................................... 3 SCOPE .................................................................................................................................... 4 2. RESEARCH QUESTIONS ......................................................................................................... 5 GOALS ................................................................................................................................... 5 RESEARCH QUESTIONS .......................................................................................................... 5 EXPECTED OUTCOME ............................................................................................................. 6 3. RESEARCH METHOD .............................................................................................................. 7 LITERATURE RESEARCH ......................................................................................................... 7 EXPERIMENT .......................................................................................................................... 7 4. LITERATURE REVIEW ......................................................................................................... 10 A FOCUS ON MULTICORE PROCESSORS ................................................................................. 10 JAVA .................................................................................................................................... 11 GO ....................................................................................................................................... 12 MATRIX MULTIPLICATION AND IMPLEMENTATIONS ............................................................. 13 LANGUAGE COMPARISONS AND ANALYSIS ........................................................................... 14 5. RESULTS ................................................................................................................................... 16 EXPERIMENTATION RESULTS ............................................................................................... 16 6. DISCUSSION ............................................................................................................................. 18 RESEARCH QUESTIONS ........................................................................................................ 18 LIMITATIONS AND VALIDITY THREATS ................................................................................. 21 7. CONCLUSION .......................................................................................................................... 22 8. FUTURE WORK ....................................................................................................................... 23 9. REFERENCES ........................................................................................................................... 24 10. ANNEXES .............................................................................................................................. 26 1 GLOSSARY CMMA Abbreviation for ‘Classic Matrix Multiplication Algorithm’. The algorithm is used because of its simple and similar implementation between programming languages. Concurrency Techniques that allow the execution of multiple tasks out-of-order or in partial order, as opposed to running them sequentially where each execution must finish before the next can start. Parallelism Techniques that allow the simultaneous execution of multiple tasks using multiple processing units. Thread A thread is a structure of values within a process that can be scheduled for execution. Several threads can exist within the same process where they share the process’ address space and resources, allowing the threads to also execute concurrently or in parallel. Multithreading Technique which allows a single program to be executed over multiple threads. Hyperthreading Technique available on Intel processors that allows 2 threads to run on, or share, a single processor core and its resources, theoretically increasing performance. 2 1. INTRODUCTION Parallelism and multithreading has become an important area in software development as newer processors are made with an increasing number of processing-cores, cores that can also manage a greater number of threads than their predecessors. At the same time new programming languages are being developed or old ones are being improved with features to allow software to better utilize threading and parallelism. As such it would be a good idea to compare a number of these languages to ascertain how well they handle multithreaded processes. Finding the languages that have the best performance when running multithreaded processes is important as it could help software developers when choosing the most beneficial languages for developing their systems. It
Details
-
File Typepdf
-
Upload Time-
-
Content LanguagesEnglish
-
Upload UserAnonymous/Not logged-in
-
File Pages48 Page
-
File Size-