Slide 1

Slide 1 text

A Comprehensive Study on the Energy Efficiency of Java Thread-Safe Collections Fernando Castor Kenan Liu Gustavo Pinto David Liu 1

Slide 2

Slide 2 text

Disclaimer 2

Slide 3

Slide 3 text

3 Miguel turns 8mo today!

Slide 4

Slide 4 text

Motivations 4

Slide 5

Slide 5 text

First, energy consumption is not only a concern for unwired devices, but also for data centers 5

Slide 6

Slide 6 text

First, energy consumption is not only a concern for unwired devices, but also for data centers 6 Second, multicore CPUs are ubiquitous

Slide 7

Slide 7 text

First, energy consumption is not only a concern for unwired devices, but also for data centers 7 Second, multicore CPUs are ubiquitous Third, data structures are the fundamentals of computer programming

Slide 8

Slide 8 text

In case you are a Java programmer… 8

Slide 9

Slide 9 text

9 List lists = …; • ArrayList • LinkedList

Slide 10

Slide 10 text

10 List lists = new ArrayList<>();

Slide 11

Slide 11 text

11 List lists = new ArrayList<>(); Thread

Slide 12

Slide 12 text

12 • ArrayList • LinkedList • Vector • Collections.synchronizedList() • CopyOnWriteArrayList List lists = …; Non Thread-Safe Thread-Safe

Slide 13

Slide 13 text

13 List lists = new Vector<>();

Slide 14

Slide 14 text

14 List lists = new Vector<>(); Thread

Slide 15

Slide 15 text

15 Thread Thread-safe! List lists = new Vector<>();

Slide 16

Slide 16 text

16 Thread { } … List lists = new Vector<>();

Slide 17

Slide 17 text

17 Thread { } … List lists = new Vector<>();

Slide 18

Slide 18 text

18 List lists = new CopyOnWriteArrayList<>();

Slide 19

Slide 19 text

19 Thread Thread-safe! List lists = new CopyOnWriteArrayList<>();

Slide 20

Slide 20 text

List lists = new CopyOnWriteArrayList<>(); 20 { } Thread Thread-safe!

Slide 21

Slide 21 text

21 List lists = …; • ArrayList • LinkedList • Vector • Collections.synchronizedList() • CopyOnWriteArrayList Non Thread-Safe Thread-Safe

Slide 22

Slide 22 text

22 List lists = …; Set sets = …; Map maps = …;

Slide 23

Slide 23 text

23 List lists = …; Set sets = …; Map maps = …;

Slide 24

Slide 24 text

24 List lists = …; Set sets = …; Map maps = …; And how about energy consumption?

Slide 25

Slide 25 text

16 Collections 25 List ArrayList Vector Collections.syncList() CopyOnWriteArrayList Set LinkedHashSet Collections.syncSet() CopyOnWriteArraySet ConcurrentSkipListSet ConcurrentHashSet ConcurrentHashSetV8 Map LinkedHashMap Hashtable Collections.syncMap() ConcurrentSkipListMap ConcurrentHashMap ConcurrentHashMapV8

Slide 26

Slide 26 text

16 Collections 26 List ArrayList Vector Collections.syncList() CopyOnWriteArrayList Set LinkedHashSet Collections.syncSet() CopyOnWriteArraySet ConcurrentSkipListSet ConcurrentHashSet ConcurrentHashSetV8 Map LinkedHashMap Hashtable Collections.syncMap() ConcurrentSkipListMap ConcurrentHashMap ConcurrentHashMapV8 Non thread-safe Thread-safe

Slide 27

Slide 27 text

16 Collections 27 List ArrayList Vector Collections.syncList() CopyOnWriteArrayList Set LinkedHashSet Collections.syncSet() CopyOnWriteArraySet ConcurrentSkipListSet ConcurrentHashSet ConcurrentHashSetV8 Map LinkedHashMap Hashtable Collections.syncMap() ConcurrentSkipListMap ConcurrentHashMap ConcurrentHashMapV8 Java 7 Java 8

Slide 28

Slide 28 text

16 Collections 28 List ArrayList Vector Collections.syncList() CopyOnWriteArrayList Set LinkedHashSet Collections.syncSet() CopyOnWriteArraySet ConcurrentSkipListSet ConcurrentHashSet ConcurrentHashSetV8 Map LinkedHashMap Hashtable Collections.syncMap() ConcurrentSkipListMap ConcurrentHashMap ConcurrentHashMapV8 x 3 Operations Traversal Insertion Removal

Slide 29

Slide 29 text

2 Environments AMD CPU: A 2×16-core, running Debian, 2.4 GHz, 64GB of memory, JDK version 1.7 .0 11, build 21. 29 Intel CPU: A 2×8-core (32-cores w/ hyper-threading), running Debian, 2.60GHz, with 64GB of memory, JDK version 1.7 .0 71, build 14.

Slide 30

Slide 30 text

2 Environments AMD CPU: A 2×16-core, running Debian, 2.4 GHz, 64GB of memory, JDK version 1.7 .0 11, build 21. 30 Intel CPU: A 2×8-core (32-cores w/ hyper-threading), running Debian, 2.60GHz, with 64GB of memory, JDK version 1.7 .0 71, build 14. Hardware-based energy measurement Software-based energy measurement

Slide 31

Slide 31 text

31 More details about how the experiments were conducted? http:/ /icsme2016.github.io/program/accepted.html

Slide 32

Slide 32 text

Results 32

Slide 33

Slide 33 text

33 Traversal Insertion Removal Intel CPU AMD CPU Traversal Insertion Removal Lists

Slide 34

Slide 34 text

34 ArrayList Vector Lists Collections.synchronizedList()

Slide 35

Slide 35 text

35 Lists ArrayList Vector Collections.synchronizedList() Energy (Joules)

Slide 36

Slide 36 text

36 Lists ArrayList Vector Energy (Joules) Power (Watts) Collections.synchronizedList()

Slide 37

Slide 37 text

37 Lists ArrayList Vector Energy (Joules) Power (Watts) Collections.synchronizedList()

Slide 38

Slide 38 text

Traversal Insertion Removal Intel CPU AMD CPU 38 38 Traversal Insertion Removal Lists

Slide 39

Slide 39 text

39 Traversal Insertion Removal Intel CPU AMD CPU 39 Traversal Insertion Removal Lists

Slide 40

Slide 40 text

40 Maps Intel CPU Traversal Insertion Removal AMD CPU Traversal Insertion Removal

Slide 41

Slide 41 text

41 Maps Intel CPU Traversal Insertion Removal AMD CPU Traversal Insertion Removal

Slide 42

Slide 42 text

42 Maps Intel CPU Traversal Insertion Removal AMD CPU Traversal Insertion Removal

Slide 43

Slide 43 text

43 Maps Intel CPU Traversal Insertion Removal AMD CPU Traversal Insertion Removal

Slide 44

Slide 44 text

44 Maps Intel CPU Traversal Insertion Removal AMD CPU Traversal Insertion Removal

Slide 45

Slide 45 text

45 Maps Intel CPU Traversal Insertion Removal AMD CPU Traversal Insertion Removal

Slide 46

Slide 46 text

46 Maps Intel CPU Traversal Insertion Removal AMD CPU Traversal Insertion Removal Less energy than the non thread-safe implementation!

Slide 47

Slide 47 text

Case Study 47

Slide 48

Slide 48 text

48 Tomcat > A web server > More than 170K lines of Java code > More than 300 Hashtables

Slide 49

Slide 49 text

49 Tomcat Xalan > Parses XML in HTML documents > More than 188K lines of Java code > More than 140 Hashtables > A web server > More than 170K lines of Java code > More than 300 Hashtables

Slide 50

Slide 50 text

50 For each Hashtable instance, change it for a ConcurrentHashMap one. Do it again for ConcurrentHashMapV8 Task:

Slide 51

Slide 51 text

51 Tomcat Hashtable to CHM: -12.21% Hashtable to CHM8: -17 .82%

Slide 52

Slide 52 text

52 Tomcat Xalan Hashtable to CHM: -12.21% Hashtable to CHM8: -17 .82% Hashtable to CHM: -5.82% Hashtable to CHM8: -9.32%

Slide 53

Slide 53 text

53 So, lets change all Hashtable instances to ConcurrentHashMap! Not so fast, young padawan…

Slide 54

Slide 54 text

54 Hashtable ConcurrentHashMap Map 
 implements

Slide 55

Slide 55 text

55 Hashtable ConcurrentHashMap Cloneable 
 Map 
 implements

Slide 56

Slide 56 text

56 Hashtable ConcurrentHashMap List obj = new Hashtable<>(); obj.clone(); Cloneable 
 Map 
 / / works fine implements

Slide 57

Slide 57 text

57 Hashtable ConcurrentHashMap List obj = new Hashtable<>(); obj.clone(); Cloneable 
 Map 
 / / works fine / / compiler error implements List obj = new ConcurrentHashMap<>(); obj.clone();

Slide 58

Slide 58 text

58 Hashtable ConcurrentHashMap List obj = new Hashtable<>(); obj.clone(); Cloneable 
 Map 
 / / works fine / / compiler error implements List obj = new ConcurrentHashMap<>(); obj.clone(); Danny Dig Opportunity for improving refactoring tools!

Slide 59

Slide 59 text

Take Away Messages 59

Slide 60

Slide 60 text

60 Small changes can have GREAT impacts, when it comes to energy consumption

Slide 61

Slide 61 text

61 Doug Lea Stay up-to-date with the new releases of the java.util.concurrent library

Slide 62

Slide 62 text

In Summary 62

Slide 63

Slide 63 text

63

Slide 64

Slide 64 text

64 THANKS

Slide 65

Slide 65 text

A Comprehensive Study on the Energy Efficiency of Java Thread-Safe Collections Fernando Castor Kenan Liu Gustavo Pinto David Liu 65

Slide 66

Slide 66 text

Experimental Environments 66 AMD CPU: A 2×16-core, running Debian, 2.4 GHz, 64GB of memory, JDK version 1.7 .0 11, build 21. Intel CPU: A 2×8-core (32-cores w/ hyper-threading), running Debian, 2.60GHz, with 64GB of memory, JDK version 1.7 .0 71, build 14.

Slide 67

Slide 67 text

67 Maps (scaling number of threads) Intel CPU Traversal Insertion