Pro Yearly is on sale from $80 to $50! »

A Comprehensive Study on the Energy Efficiency of Java Thread-Save Collections

Be6953eb1929f548597c7ebf2be91a22?s=47 Gustavo Pinto
January 14, 2018
29

A Comprehensive Study on the Energy Efficiency of Java Thread-Save Collections

Be6953eb1929f548597c7ebf2be91a22?s=128

Gustavo Pinto

January 14, 2018
Tweet

Transcript

  1. A Comprehensive Study on the Energy Efficiency of Java Thread-Safe

    Collections Fernando Castor Kenan Liu Gustavo Pinto David Liu 1
  2. Disclaimer 2

  3. 3 Miguel turns 8mo today!

  4. Motivations 4

  5. First, energy consumption is not only a concern for unwired

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

    devices, but also for data centers 6 Second, multicore CPUs are ubiquitous
  7. 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
  8. In case you are a Java programmer… 8

  9. 9 List<Object> lists = …; • ArrayList • LinkedList

  10. 10 List<Object> lists = new ArrayList<>();

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

  12. 12 • ArrayList • LinkedList • Vector • Collections.synchronizedList() •

    CopyOnWriteArrayList List<Object> lists = …; Non Thread-Safe Thread-Safe
  13. 13 List<Object> lists = new Vector<>();

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

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

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

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

  18. 18 List<Object> lists = new CopyOnWriteArrayList<>();

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

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

  21. 21 List<Object> lists = …; • ArrayList • LinkedList •

    Vector • Collections.synchronizedList() • CopyOnWriteArrayList Non Thread-Safe Thread-Safe
  22. 22 List<Object> lists = …; Set<Objects> sets = …; Map<Object,

    Object> maps = …;
  23. 23 List<Object> lists = …; Set<Objects> sets = …; Map<Object,

    Object> maps = …;
  24. 24 List<Object> lists = …; Set<Objects> sets = …; Map<Object,

    Object> maps = …; And how about energy consumption?
  25. 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
  26. 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
  27. 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
  28. 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
  29. 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.
  30. 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
  31. 31 More details about how the experiments were conducted? http:/

    /icsme2016.github.io/program/accepted.html
  32. Results 32

  33. 33 Traversal Insertion Removal Intel CPU AMD CPU Traversal Insertion

    Removal Lists
  34. 34 ArrayList Vector Lists Collections.synchronizedList()

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

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

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

  38. Traversal Insertion Removal Intel CPU AMD CPU 38 38 Traversal

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

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

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

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

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

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

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

    Insertion Removal
  46. 46 Maps Intel CPU Traversal Insertion Removal AMD CPU Traversal

    Insertion Removal Less energy than the non thread-safe implementation!
  47. Case Study 47

  48. 48 Tomcat > A web server > More than 170K

    lines of Java code > More than 300 Hashtables
  49. 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
  50. 50 For each Hashtable instance, change it for a ConcurrentHashMap

    one. Do it again for ConcurrentHashMapV8 Task:
  51. 51 Tomcat Hashtable to CHM: -12.21% Hashtable to CHM8: -17

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

    -17 .82% Hashtable to CHM: -5.82% Hashtable to CHM8: -9.32%
  53. 53 So, lets change all Hashtable instances to ConcurrentHashMap! Not

    so fast, young padawan…
  54. 54 Hashtable ConcurrentHashMap Map 
 implements

  55. 55 Hashtable ConcurrentHashMap Cloneable 
 Map 
 implements

  56. 56 Hashtable ConcurrentHashMap List<Object> obj = new Hashtable<>(); obj.clone(); Cloneable

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

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

    
 Map 
 / / works fine / / compiler error implements List<Object> obj = new ConcurrentHashMap<>(); obj.clone(); Danny Dig Opportunity for improving refactoring tools!
  59. Take Away Messages 59

  60. 60 Small changes can have GREAT impacts, when it comes

    to energy consumption
  61. 61 Doug Lea Stay up-to-date with the new releases of

    the java.util.concurrent library
  62. In Summary 62

  63. 63

  64. 64 THANKS

  65. A Comprehensive Study on the Energy Efficiency of Java Thread-Safe

    Collections Fernando Castor Kenan Liu Gustavo Pinto David Liu 65
  66. 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.
  67. 67 Maps (scaling number of threads) Intel CPU Traversal Insertion