Comparison of Concurrency Frameworks for the Java Virtual Machine
Total Page:16
File Type:pdf, Size:1020Kb
Universität Ulm Fakultät für Ingenieurwissenschaften und Informatik Institut für Verteilte Systeme, Bachelorarbeit im Studiengang Informatik Comparison of Concurrency Frameworks for the Java Virtual Machine Thomas Georg Kühner vorgelegt am 25. Oktober 2013 VS-B13-2013 Gutachter Prof. Dr. Frank Kargl Fassung vom: December 8, 2013 cbnd Diese Arbeit ist lizensiert unter der Creative Commons Namensnennung-Keine kommerzielle Nutzung-Keine Bearbeitung 3.0 Deutschland Lizenz. Nähere Informationen finden Sie unter: http://creativecommons.org/licenses/by-nc-nd/3.0/de/ oder senden Sie einen Brief an: Creative Commons, 171 Second Street, Suite 300, San Francisco, California, 94105, USA. Contents 1. Introduction 1 1.1. Motivation..........................................1 1.2. Scope of this Thesis.....................................2 1.3. Methodology........................................2 1.4. Road Map for this thesis..................................2 2. Basics and Background about Concurrency and Concurrent Programming3 2.1. Terminology.........................................3 2.2. Small History of Concurrency Theory..........................5 2.3. General Programming Models for Concurrency....................6 2.4. Traditional Concurrency Issues..............................7 2.4.1. Race Condition...................................7 2.4.2. Dead-Lock......................................8 2.4.3. Starvation......................................8 2.4.4. Priority Inversion..................................9 2.5. Summary...........................................9 3. JVM Fundamentals 11 3.1. Motivation for the JVM................................... 11 3.2. Approach to Concurrency................................. 12 3.3. Java Memory Model.................................... 13 3.4. Summary........................................... 14 4. Models and Concepts for Concurrent Programming 15 4.1. Models............................................ 15 4.1.1. Shared State and Threads............................. 15 4.1.2. Actor Model..................................... 16 4.1.3. Dataflow....................................... 17 4.1.4. Sequential Processes................................ 18 4.2. Concepts........................................... 18 4.3. Summary........................................... 20 5. Design of the Comparison 23 5.1. Levels of Measurement................................... 23 5.2. Qualitative Properties................................... 23 5.3. Quantitative Properties................................... 24 6. Generic concurrency problems 25 6.1. Characteristics of Generic Concurrency Problems................... 25 6.2. Specific Problems for Comparison............................ 28 Contents 6.2.1. Counting Server and Computation Intensive Server.............. 28 6.2.2. Transactions between Spaceships......................... 29 6.2.3. Frequency of Visits................................. 30 6.3. Summary........................................... 31 7. Overview of Frameworks 33 7.1. Requirements of the Frameworks............................. 33 7.2. JSCOOP........................................... 33 7.3. Guava............................................. 34 7.4. Disruptor........................................... 34 7.5. GPars............................................. 35 7.6. Vert.x............................................. 36 7.7. Akka............................................. 36 7.8. Summary........................................... 37 8. Qualitative Comparison 39 8.1. Available Programming Languages............................ 39 8.2. Approaches to Concurrency................................ 40 8.2.1. Approach of Vert.x................................. 40 8.2.2. Approaches of Gpars................................ 41 8.2.3. Approach of Akka................................. 45 8.3. Akka actors vs GPars actors................................ 48 8.4. Akka Dataflow vs GPars Dataflow............................ 49 8.5. Vert.x Multireactor Pattern vs Actor Model....................... 50 8.6. Usability........................................... 50 8.7. Scalability/Distribution.................................. 52 8.8. Summary........................................... 55 9. Implementation 57 9.1. Requirements and Specifications for Transactions between Spaceships....... 57 9.1.1. Implementation with Java............................. 58 9.1.2. Implementation with Vert.x............................ 58 9.1.3. Implementation with Akka............................ 59 9.1.4. Implementation with GPars............................ 60 9.2. Requirements and Specifications for Frequency of Visits............... 61 9.2.1. Implementation with Java............................. 61 9.2.2. Implementation with Akka............................ 63 9.2.3. Implementation with GPars............................ 63 9.3. Requirements and Specifications Counting Server and Computation Intensive Server 64 9.3.1. Implementation with Java............................. 65 9.3.2. Implementation with Akka............................ 66 9.3.3. Implementation with Vert.x............................ 66 9.4. Summary........................................... 67 10.Quantitative Comparison 69 10.1. Benchmarking on the JVM................................. 69 10.2. Actual Benchmarks..................................... 70 10.3. Results............................................ 72 10.4. Summary........................................... 75 iv Contents 11.Conclusion 77 A. Appendix 79 A.1. Settings............................................ 79 A.2. Results............................................ 84 Bibliography 111 v 1. Introduction 1.1. Motivation Research on the field of concurrency goes back to the early 1960s. According to "The origin of concurrent programming", "The development of concurrent programming was originally motivated by the desire to develop reliable operating systems. From the beginning, however, it was recognized that principles of concurrent programming have a general utility that goes beyond operating systems"[22]. The consequences of this statement, can be recognized today. Usually all modern programming languages allow to develop concurrent programs. Yet, concurrent programming is still a topic programmers often struggle with. Even worse, bugs caused by concurrent issues can draw fatal consequences. They can cause a total failure of an application. Furthermore, debugging can be like looking for a needle in a haystack. In terms of hardware, there was a huge paradigm shift. Over many decades new computer chips improved by having more transistors while requiring less space and increasing the clock frequency. At some point, chips vendors reached the physical limits. Increasing the clock frequency of one processor caused too much heat. In order to keep increasing the number of transistors, they decided to put multiple processors on one chip. These share a common memory, enabling to execute parts of concurrent software simultaneously. In the past, only few people from the industry and research had computers with such an architecture. But today, the common run of mankind owns computers with multiple cores. Thus, it is important to benefit from this additional power when developing software for daily use. Programmers should be aware of handling concurrent programming more than ever before. On the other hand, the variety of hardware devices on which software is expected to run on is huge today. Especially, the demand for mobile devices increased enormously. In consequence to the large number of different operating and hardware, platform independence has taken on great significance. A popular solution to provide platform independence is the Java Virtual Machine of Oracle. Regarding the need of portable and concurrent applications, a broad support for concurrency appeared for the JVM. Besides its native support for concurrency, multiple other approaches are offered in the form of frameworks. The reason for that is that its native approach to concurrency with languages such as Java is often seen as too complex and error-prone for building large applications. Frameworks try to tackle that by providing appropriate abstractions and applying other concurrency models. However, developers who decided to use the JVM to create concurrent software have the agony of choice. Several frameworks exists but there is no reference which compares them. This thesis shell counteract that circumstance. It intends to figure out what frameworks exist, pick out the promising ones and compare them based on qualitative and quantitative properties. 1. Introduction 1.2. Scope of this Thesis Each comparison requires a basic set of elements to be compared. Thus, picking out promising concurrency frameworks forms the basis of this thesis. Dedicated frameworks are compared based on qualitative and quantitative properties. Measuring quantitative properties is done by evaluating implementations of specific problems. In order to define these problems, essential characteristics for concurrent applications are deduced. In multiple benchmarks, theses imple- mentation are evaluated to retrieve quantitative results. On top of the results of the comparison, it is concluded which frameworks suits in which situations. This thesis does not replace detailed references how to program with one of the frameworks. Moreover, it offers no guideline for developing whole applications. Instead, it focuses on describing advantages, disadvantages and limits of models and concepts provided differently