The Influence of the Java Collection
Framework on Overall Energy
Consumption
Rui Pereira*, Marco Couto*, Jácome Cunha§,
João Paulo Fernandes‡, and João Saraiva*
greenlab.di.uminho.pt
* HASLab/INESC Tec, Universidade do Minho
§ NOVA LINCS, Universidade Nova de Lisboa
‡ RELEASE, Universidade da Beira Interior
{ruipereira, mcouto, jas}@di.uminho.pt, jacome@fct.unl.pt, jpf@di.ubi.pt
Going Green
greenlab.di.uminho.pt
2
+ =
Global energy system is unsustainable
greenlab.di.uminho.pt
3
Green Computing
 Caught the attention of many companies allowing them to save:
greenlab.di.uminho.pt
4
“close to 50% of the energy costs of an organization can be
attributed to the IT departments”
- [PICMET, 2009]
“up to 90% of energy used by ICT hardware can be attributed to
software”
- [The Greenhouse Gas Protocol Report, 2013]
Green Software
 Reducing energy consumption through software analysis and optimization
 Problem:
 How to analyze
 How to interpret
 How to improve
greenlab.di.uminho.pt
5
Green Software
 Problems (extend to programmers):
 How to analyze
 How to interpret
 How to improve
greenlab.di.uminho.pt
6
Mining questions about software energy consumption
- [MSR’14]
Integrated energy-directed test suite optimization
- [ISTA’14]
Can we save energy by refactoring Java
programs to use different data structure
implementations?
greenlab.di.uminho.pt
7
Research Questions
greenlab.di.uminho.pt
8
 (RQ1) Can we define an energy consumption quantification of Java data
structures and their methods?
 (RQ2) Can we use such quantification to decrease the energy consumption
of software systems?
Towards a Ranking of Java data structures
greenlab.di.uminho.pt
9
Design
 Simple scenario of:
 Storing
 Retrieving
 Deleting
 String values
greenlab.di.uminho.pt
10
 Java Collections Framework (JCF) library
ConcurrentSkipListSet ArrayList ConcurrentHashMap
CopyOnWriteArraySet AttributeList ConcurrentSkipListMap
HashSet CopyOnWriteArrayList HashMap
LinkedHashSet LinkedList Hashtable
TreeSet RoleList IdentityHashMap
RoleUnresolvedList LinkedHashMap
Stack Properties
Vector SimpleBindings
TreeMap
UIDefaults
WeakHashMap
Sets Lists Maps
Towards a Ranking of Java data structures
Design – Data Structures
greenlab.di.uminho.pt
11
add add clear
addAll addAll containsKey
clear add(index) containsValue
contains addAll(index) entrySet
containsAll clear get
iterateAll contains iterateAll
iterator containsAll keySet
remove get put
removeAll indexOf putAll
retainAll iterator remove
toArray lastIndexOf values
listIterator
listIterator(index)
remove
removeAll
Continues…
Sets Lists Maps
Towards a Ranking of Java data structures
Design - Methods
greenlab.di.uminho.pt
12
 Defined population sizes (popsize) of
 25,000
 250,000
 1,000,000
 When a second data structure is needed (i.e. addAll)
 SecondaryCol = 10% of popsize
 Half existing & half new (shuffled)
Towards a Ranking of Java data structures
Design - Benchmark
greenlab.di.uminho.pt
13
 Linux 3.13.0-74-generic OS
 8GB Ram
 Intel(R) Core(TM) i3-3240 CPU @ 3.40GHz
 Java Interpreter/Compiler versions 1.8.0_66
 RAPL/jRAPL
Towards a Ranking of Java data structures
Execution - Specifications
greenlab.di.uminho.pt
14
 Warm-up
 Instantiated
 Populated w/ popsize
 Performed simple actions on the data structure
 Each test x20
 Extracted time/Joules consumed
 Removed lowest/highest 20%
 336 different test (Collection.method) configurations
 6720 executions for each popsize
 20,000+ different executions
Towards a Ranking of Java data structures
Execution – For every test
greenlab.di.uminho.pt
15
Towards a Ranking of Java data structures
Results (25k pop)
greenlab.di.uminho.pt
16
Towards a Ranking of Java data structures
greenlab.di.uminho.pt
17
Towards a Ranking of Java data structures
greenlab.di.uminho.pt
18
Towards a Ranking of Java data structures
Is faster, Greener?!
greenlab.di.uminho.pt
19
Is slower, Greener?!
Faster
Slower
Research Questions
greenlab.di.uminho.pt
20
 (RQ1) Can we define an energy consumption quantification of Java data
structures and their methods?
 (RQ2) Can we use such quantification to decrease the energy consumption
of software systems?
Optimizing Energy Consumption of Java Programs
greenlab.di.uminho.pt
21
Methodology
1. Compute which implementations/methods are used in the programs
2. Look up the appropriate energy tables for the used implementations/methods
3. Choose the most energy efficient alternative
Optimizing Energy Consumption of Java Programs
greenlab.di.uminho.pt
22
Applying the methodology – Data acquisition
 Obtained Java projects of a Journalism support platform
 First year OO course
 Collaborators, Journalists, Readers, Editors
 Write chronicles and reports
 Give likes and comments
 Etc.
 Average of
 36 classes
 104 methods
 2000 lines of code
Optimizing Energy Consumption of Java Programs
greenlab.di.uminho.pt
23
Applying the methodology – Data acquisition
 Obtained 7 test cases to simulate usage
 Size varied vetween 2000-10000 for each test case/each entity
 Chosen popsize – 25,000 (smallest)
 Applied methodology on 5 projects
 Detected usage of any JCF implementation
 Detected which methods were used for each implementation
 Chose the most efficient implementation for each project
 Measured the changes before and after
Optimizing Energy Consumption of Java Programs
greenlab.di.uminho.pt
24
Applying the methodology – Example
Optimizing Energy Consumption of Java Programs
greenlab.di.uminho.pt
25
Applying the methodology – Results
 Between 4.37% - 11.05%
 Average of 6.2%
FW + Conclusion
greenlab.di.uminho.pt
26
 Presented detailed study of the energy consumption of Sets, Lists, and Maps
 Quantification of the energy spent by each method (RQ1 Answer)
 Introduced a very simple methodology to optimize Java programs (RQ2 Answer)
 Consider other object types (int, objects, etc.)
 Implement an automatic refactoring plugin
 Found @ our page: http://greenlab.di.uminho.pt/
greenlab.di.uminho.pt
27 Portuguese National Science Foundation (FCT)
 Starts July 2016
 Grants available for young researchers
 MSc
 PhD
 Postdoc
 Universities:
 University of Minho (Braga)
 University of Beira Interior (Covilhã)
 University of Porto (Porto)
 New University of Lisbon (Lisbon)
The Influence of the Java Collection
Framework on Overall Energy
Consumption
Rui Pereira*, Marco Couto*, Jácome Cunha§,
João Paulo Fernandes‡, and João Saraiva*
greenlab.di.uminho.pt
* HASLab/INESC Tec, Universidade do Minho
§ NOVA LINCS, Universidade Nova de Lisboa
‡ RELEASE, Universidade da Beira Interior
{ruipereira, mcouto, jas}@di.uminho.pt, jacome@fct.unl.pt, jpf@di.ubi.pt

The Influence of the Java Collection Framework on Overall Energy Consumption

  • 1.
    The Influence ofthe Java Collection Framework on Overall Energy Consumption Rui Pereira*, Marco Couto*, Jácome Cunha§, João Paulo Fernandes‡, and João Saraiva* greenlab.di.uminho.pt * HASLab/INESC Tec, Universidade do Minho § NOVA LINCS, Universidade Nova de Lisboa ‡ RELEASE, Universidade da Beira Interior {ruipereira, mcouto, jas}@di.uminho.pt, jacome@fct.unl.pt, jpf@di.ubi.pt
  • 2.
  • 3.
    Global energy systemis unsustainable greenlab.di.uminho.pt 3
  • 4.
    Green Computing  Caughtthe attention of many companies allowing them to save: greenlab.di.uminho.pt 4 “close to 50% of the energy costs of an organization can be attributed to the IT departments” - [PICMET, 2009] “up to 90% of energy used by ICT hardware can be attributed to software” - [The Greenhouse Gas Protocol Report, 2013]
  • 5.
    Green Software  Reducingenergy consumption through software analysis and optimization  Problem:  How to analyze  How to interpret  How to improve greenlab.di.uminho.pt 5
  • 6.
    Green Software  Problems(extend to programmers):  How to analyze  How to interpret  How to improve greenlab.di.uminho.pt 6 Mining questions about software energy consumption - [MSR’14] Integrated energy-directed test suite optimization - [ISTA’14]
  • 7.
    Can we saveenergy by refactoring Java programs to use different data structure implementations? greenlab.di.uminho.pt 7
  • 8.
    Research Questions greenlab.di.uminho.pt 8  (RQ1)Can we define an energy consumption quantification of Java data structures and their methods?  (RQ2) Can we use such quantification to decrease the energy consumption of software systems?
  • 9.
    Towards a Rankingof Java data structures greenlab.di.uminho.pt 9 Design  Simple scenario of:  Storing  Retrieving  Deleting  String values
  • 10.
    greenlab.di.uminho.pt 10  Java CollectionsFramework (JCF) library ConcurrentSkipListSet ArrayList ConcurrentHashMap CopyOnWriteArraySet AttributeList ConcurrentSkipListMap HashSet CopyOnWriteArrayList HashMap LinkedHashSet LinkedList Hashtable TreeSet RoleList IdentityHashMap RoleUnresolvedList LinkedHashMap Stack Properties Vector SimpleBindings TreeMap UIDefaults WeakHashMap Sets Lists Maps Towards a Ranking of Java data structures Design – Data Structures
  • 11.
    greenlab.di.uminho.pt 11 add add clear addAlladdAll containsKey clear add(index) containsValue contains addAll(index) entrySet containsAll clear get iterateAll contains iterateAll iterator containsAll keySet remove get put removeAll indexOf putAll retainAll iterator remove toArray lastIndexOf values listIterator listIterator(index) remove removeAll Continues… Sets Lists Maps Towards a Ranking of Java data structures Design - Methods
  • 12.
    greenlab.di.uminho.pt 12  Defined populationsizes (popsize) of  25,000  250,000  1,000,000  When a second data structure is needed (i.e. addAll)  SecondaryCol = 10% of popsize  Half existing & half new (shuffled) Towards a Ranking of Java data structures Design - Benchmark
  • 13.
    greenlab.di.uminho.pt 13  Linux 3.13.0-74-genericOS  8GB Ram  Intel(R) Core(TM) i3-3240 CPU @ 3.40GHz  Java Interpreter/Compiler versions 1.8.0_66  RAPL/jRAPL Towards a Ranking of Java data structures Execution - Specifications
  • 14.
    greenlab.di.uminho.pt 14  Warm-up  Instantiated Populated w/ popsize  Performed simple actions on the data structure  Each test x20  Extracted time/Joules consumed  Removed lowest/highest 20%  336 different test (Collection.method) configurations  6720 executions for each popsize  20,000+ different executions Towards a Ranking of Java data structures Execution – For every test
  • 15.
    greenlab.di.uminho.pt 15 Towards a Rankingof Java data structures Results (25k pop)
  • 16.
  • 17.
  • 18.
  • 19.
    Is faster, Greener?! greenlab.di.uminho.pt 19 Isslower, Greener?! Faster Slower
  • 20.
    Research Questions greenlab.di.uminho.pt 20  (RQ1)Can we define an energy consumption quantification of Java data structures and their methods?  (RQ2) Can we use such quantification to decrease the energy consumption of software systems?
  • 21.
    Optimizing Energy Consumptionof Java Programs greenlab.di.uminho.pt 21 Methodology 1. Compute which implementations/methods are used in the programs 2. Look up the appropriate energy tables for the used implementations/methods 3. Choose the most energy efficient alternative
  • 22.
    Optimizing Energy Consumptionof Java Programs greenlab.di.uminho.pt 22 Applying the methodology – Data acquisition  Obtained Java projects of a Journalism support platform  First year OO course  Collaborators, Journalists, Readers, Editors  Write chronicles and reports  Give likes and comments  Etc.  Average of  36 classes  104 methods  2000 lines of code
  • 23.
    Optimizing Energy Consumptionof Java Programs greenlab.di.uminho.pt 23 Applying the methodology – Data acquisition  Obtained 7 test cases to simulate usage  Size varied vetween 2000-10000 for each test case/each entity  Chosen popsize – 25,000 (smallest)  Applied methodology on 5 projects  Detected usage of any JCF implementation  Detected which methods were used for each implementation  Chose the most efficient implementation for each project  Measured the changes before and after
  • 24.
    Optimizing Energy Consumptionof Java Programs greenlab.di.uminho.pt 24 Applying the methodology – Example
  • 25.
    Optimizing Energy Consumptionof Java Programs greenlab.di.uminho.pt 25 Applying the methodology – Results  Between 4.37% - 11.05%  Average of 6.2%
  • 26.
    FW + Conclusion greenlab.di.uminho.pt 26 Presented detailed study of the energy consumption of Sets, Lists, and Maps  Quantification of the energy spent by each method (RQ1 Answer)  Introduced a very simple methodology to optimize Java programs (RQ2 Answer)  Consider other object types (int, objects, etc.)  Implement an automatic refactoring plugin  Found @ our page: http://greenlab.di.uminho.pt/
  • 27.
    greenlab.di.uminho.pt 27 Portuguese NationalScience Foundation (FCT)  Starts July 2016  Grants available for young researchers  MSc  PhD  Postdoc  Universities:  University of Minho (Braga)  University of Beira Interior (Covilhã)  University of Porto (Porto)  New University of Lisbon (Lisbon)
  • 28.
    The Influence ofthe Java Collection Framework on Overall Energy Consumption Rui Pereira*, Marco Couto*, Jácome Cunha§, João Paulo Fernandes‡, and João Saraiva* greenlab.di.uminho.pt * HASLab/INESC Tec, Universidade do Minho § NOVA LINCS, Universidade Nova de Lisboa ‡ RELEASE, Universidade da Beira Interior {ruipereira, mcouto, jas}@di.uminho.pt, jacome@fct.unl.pt, jpf@di.ubi.pt

Editor's Notes

  • #7 Aware of the energy consumption problem, many times seeking help in resolving this, misconceptions within the programming community as to what causes highenergy consumption, how to solve them a heavy lack of support and knowledge for energy-aware development Even in software testing Image from [http://thevunderkind.com/new-to-coding-dont-know-how-to-pick-your-first-language-let-udacitys-infographic-help-you/]
  • #11 The most classical way is to separate Implement the interfaces Separation makes sense as each interface is used for distinct properties Elimiated: Job State Reasons (SET) IdentityHashMap (MAP)
  • #13 Provides analysis with multiple orders of magnituted. Learn how it scales also
  • #16 CopyOnWriteArraySet was discarded. Did not finish in reasonable amount of time.
  • #17 LinkedHashSet includes most of the efficient methods But we can also note it has the two most inefficient methods (addAll and containsAll)
  • #18 RoleUnresolved and AttributeList are the best. Interesting they both extend ArrayList which has less efficient methods, and quite different consumption values. LinkedList is by far the worse
  • #19 HashTable, LinkedHashMap, Properties contain the most efficient methods, with no red. Once again concurrent fails. Properties is generally used to store project configuration data/settings, yet produced very good results for this simple string value scenario