Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Writing Greener Java Applications

Holly Cummins
November 02, 2022

Writing Greener Java Applications

The code we write has a climate impact. But how big is that impact? How do we measure it? How do we reduce it? Is the cloud helping? What’s going on with Virginia? Are we still allowed to do CI/CD? Will native compilation save us? Is Java even a good choice anymore? This talk discusses some of the trade-offs for a modern software developer, and provides a roadmap to figuring out the right thing.

Disclosure: Holly works on Quarkus. Along the way, she will talk about Quarkus sustainability measurements we’ve been doing … but it’s ok, because she promises that the Quarkus carbon data is exciting and interesting.

Holly Cummins

November 02, 2022
Tweet

More Decks by Holly Cummins

Other Decks in Programming

Transcript

  1. Holly Cummins


    Senior Principal Software Engineer, Quarkus


    @holly_cummins
    Writing Greener
    Java Applications
    Red Hat


    View Slide

  2. @holly_cummins #RedHat
    Sources:


    https://www.greenit.fr/wp-content/uploads/2019/11/GREENIT_EENM_etude_EN_accessible.pdf


    https://ourworldindata.org/ghg-emissions-by-sector
    the digital world creates
    more carbon emissions
    than aviation

    View Slide

  3. @holly_cummins #RedHat
    Lighter area represents high and low estimates, where available.


    Sources:


    https://www.iea.org/fuels-and-technologies/data-centres-networks


    https://ourworldindata.org/grapher/electricity-demand?tab=table&country=USA~GBR~FRA~DEU~IND~BRA
    data centres use as
    much electricity as a
    medium country

    View Slide

  4. @holly_cummins #RedHat
    aaaaaaaargh

    View Slide

  5. @holly_cummins #RedHat
    aaaaaaaargh?

    View Slide

  6. @holly_cummins #RedHat
    be a solutionist

    View Slide

  7. @holly_cummins #RedHat
    what should we do?

    View Slide

  8. @holly_cummins #RedHat
    • right thing to do


    • business benefits


    • lower costs


    • competitive advantage


    • recruitment advantage
    should we reduce our
    greenhouse gases?

    View Slide

  9. @holly_cummins #RedHat

    View Slide

  10. Usefulness (value)
    Measurement for optimization
    User behaviour
    Software
    Hosting
    Data
    storage
    Demand
    shaping
    Hardware
    efficiency
    Energy
    efficiency
    Application
    efficiency
    Utilization
    Demand
    shifting to
    reduce carbon
    intensity
    Infrastructure
    efficiency


    (PUE)
    Electricity


    source
    principles of green software engineering
    Network

    View Slide

  11. step 1: electricity source

    View Slide

  12. @holly_cummins #RedHat
    data center location matters
    (these are made-up energy mixes)

    View Slide

  13. @holly_cummins #RedHat
    we need to talk
    about virginia

    View Slide

  14. @holly_cummins #RedHat
    look at the sustainability information
    before choosing a hosting region

    View Slide

  15. @holly_cummins #RedHat
    look at the sustainability information
    before choosing a hosting region
    choose a cloud provider who make this easy

    View Slide

  16. @holly_cummins #RedHat
    step 2: the four vowels

    View Slide

  17. @holly_cummins #RedHat
    step 2: the four vowels

    View Slide

  18. @holly_cummins #RedHat
    step 2: the four vowels
    elasticity

    View Slide

  19. @holly_cummins #RedHat
    step 2: the four vowels
    elasticity
    utilisation

    View Slide

  20. @holly_cummins #RedHat
    step 2: the four vowels
    elasticity
    utilisation

    View Slide

  21. @holly_cummins #RedHat
    step 2: the four vowels
    elasticity
    utilisation
    efficiency

    View Slide

  22. @holly_cummins #RedHat
    step 2: the four vowels
    elasticity
    utilisation
    efficiency
    utility

    View Slide

  23. @holly_cummins
    #RedHat
    elasticity
    we used to leave
    our applications
    running overnight
    when we
    scripted turning
    them off, we
    reduced our cloud
    bill by 30%
    @darkandnerdy, Chicago DevOpsDays

    View Slide

  24. #RedHat
    @holly_cummins
    2017 survey


    25%


    of 16,000 servers
    doing no useful work

    View Slide

  25. #RedHat
    @holly_cummins
    2017 survey


    25%


    of 16,000 servers
    doing no useful work
    “perhaps someone
    forgot to turn them off”

    View Slide

  26. @holly_cummins
    #RedHat
    ultimate elasticity


    View Slide

  27. @holly_cummins
    #RedHat
    ultimate elasticity


    View Slide

  28. @holly_cummins
    #RedHat
    turning it off and on again must
    ultimate elasticity


    View Slide

  29. @holly_cummins
    #RedHat
    turning it off and on again must
    • be fast
    ultimate elasticity


    View Slide

  30. @holly_cummins
    #RedHat
    turning it off and on again must
    • be fast
    • actually work
    ultimate elasticity


    View Slide

  31. @holly_cummins
    #RedHat
    turning it off and on again must
    • be fast
    • actually work
    • idempotency
    ultimate elasticity


    View Slide

  32. @holly_cummins
    #RedHat
    turning it off and on again must
    • be fast
    • actually work
    • idempotency
    • resiliency
    ultimate elasticity


    View Slide

  33. @holly_cummins
    #RedHat

    View Slide

  34. @holly_cummins
    #RedHat
    LightSwitchOps

    View Slide

  35. @holly_cummins
    #RedHat
    LightSwitchOps

    View Slide

  36. @holly_cummins
    #RedHat
    efficiency

    View Slide

  37. @holly_cummins
    #RedHat
    what programming languages
    use the least energy?

    View Slide

  38. @holly_cummins
    #RedHat
    what programming languages
    use the most energy?

    View Slide

  39. View Slide

  40. energy efficiency
    of programming
    languages

    View Slide

  41. @holly_cummins
    #RedHat

    View Slide

  42. @holly_cummins
    #RedHat

    View Slide

  43. View Slide

  44. @holly_cummins
    #RedHat
    “Our results show that some JVM platforms can
    exhibit up to 100% more energy consumption.”
    https://hal.inria.fr/hal-03275286/document

    View Slide

  45. @holly_cummins
    #RedHat
    if JVM parameters can make that much difference …


    … what impact does the framework have?

    View Slide

  46. @holly_cummins #RedHat

    View Slide

  47. @holly_cummins #RedHat

    View Slide

  48. @holly_cummins #RedHat
    does being small and fast reduce carbon footprint?

    View Slide

  49. digression:


    measuring carbon is hard

    View Slide

  50. @holly_cummins #RedHat
    step 1: measure power usage

    View Slide

  51. @holly_cummins #RedHat
    step 1: measure power usage
    wall power measurement

    View Slide

  52. @holly_cummins #RedHat
    step 1: measure power usage
    wall power measurement
    more complete

    View Slide

  53. @holly_cummins #RedHat
    step 1: measure power usage
    wall power measurement
    more complete
    needs access to the wall

    View Slide

  54. @holly_cummins #RedHat
    step 1: measure power usage
    wall power measurement
    more complete
    needs access to the wall
    and equipment

    View Slide

  55. @holly_cummins #RedHat
    step 1: measure power usage
    wall power measurement
    more complete
    needs access to the wall
    and equipment
    and notebooks

    View Slide

  56. @holly_cummins #RedHat
    step 1: measure power usage
    wall power measurement
    more complete
    needs access to the wall
    and equipment
    and notebooks
    RAPL

    View Slide

  57. @holly_cummins #RedHat
    step 1: measure power usage
    wall power measurement
    more complete
    needs access to the wall
    and equipment
    and notebooks
    RAPL
    programmatically accessible

    View Slide

  58. @holly_cummins #RedHat
    step 1: measure power usage
    wall power measurement
    more complete
    needs access to the wall
    and equipment
    and notebooks
    RAPL
    programmatically accessible
    misses some components

    View Slide

  59. @holly_cummins #RedHat
    step 1: measure power usage
    wall power measurement
    more complete
    needs access to the wall
    and equipment
    and notebooks
    data costs carbon
    RAPL
    programmatically accessible
    misses some components

    View Slide

  60. @holly_cummins #RedHat

    View Slide

  61. @holly_cummins #RedHat

    View Slide

  62. @holly_cummins #RedHat

    View Slide

  63. @holly_cummins #RedHat
    load

    View Slide

  64. @holly_cummins #RedHat
    Source: Teads EC2 instances carbon dataset

    View Slide

  65. @holly_cummins #RedHat
    coal wind
    step 2: convert power usage to carbon solar

    View Slide

  66. @holly_cummins #RedHat
    published energy mixes
    (these are made-up energy mixes)

    View Slide

  67. @holly_cummins #RedHat
    published energy mixes … but methodologies are not open
    (these are made-up energy mixes)

    View Slide

  68. @holly_cummins #RedHat
    published energy mixes … but methodologies are not open
    … or consistent
    (these are made-up energy mixes)

    View Slide

  69. @holly_cummins #RedHat
    step 3: embedded carbon
    (manufacturing has costs)

    View Slide

  70. @holly_cummins #RedHat
    simpler models

    View Slide

  71. @holly_cummins #RedHat
    vrrrrrooooooooom model*
    * a made-up name

    View Slide

  72. @holly_cummins
    #RedHat

    View Slide

  73. @holly_cummins
    #RedHat
    these two columns
    are almost the same

    View Slide

  74. @holly_cummins #RedHat
    energy consumption (sort of, mostly) is proportional to execution time

    View Slide

  75. @holly_cummins #RedHat
    economic model*

    View Slide

  76. @holly_cummins #RedHat
    economic model*
    * "economic input-output life cycle assessment"

    View Slide

  77. @holly_cummins #RedHat
    reducing your cloud spend
    (probably) reducing your carbon footprint*
    hardware spend
    electricity bill
    * if you keep other factors the same

    View Slide

  78. @holly_cummins #RedHat
    all models are wrong, some are useful

    View Slide

  79. so … quarkus?

    View Slide

  80. @holly_cummins #RedHat
    density
    Source: Clement Escoffier
    cost impact of framework choice
    Setup:


    • 800 requests/second, over 20 days


    • SLA > 99%


    • AWS instances


    Assumptions:


    • Costs are for us-east-1 data centre

    View Slide

  81. @holly_cummins #RedHat
    Setup:


    • 800 requests/second, over 20 days


    • SLA > 99%


    Assumptions:


    • 50% load


    • us-east-1 data centre


    • Teads dataset
    Source: Clement Escoffier x Teads
    cloud carbon impact of framework choice

    View Slide

  82. • quarkus cuts carbon by ~2x*


    • native has a slightly smaller carbon
    footprint
    * OOM heuristic
    density test: conclusions

    View Slide

  83. @holly_cummins #RedHat
    capacity
    Source: John O’Hara
    Setup:


    • REST + CRUD


    • large heap


    • RAPL energy measurement


    Assumptions:


    • US energy mix
    CRUD climate impact at low load (single instance)

    View Slide

  84. @holly_cummins #RedHat
    Setup:


    • REST + CRUD


    • large heap


    • RAPL energy measurement


    • multiple instances to support high load

    Assumptions:


    • US energy mix
    Source: John O’Hara
    CRUD climate impact at high load (multiple instances)

    View Slide

  85. • quarkus cuts carbon by ~2-3x*


    • native consumes more carbon
    than JVM


    capacity test: conclusions
    * OOM heuristic

    View Slide

  86. @holly_cummins #RedHat
    so does quarkus reduce
    carbon emissions?

    View Slide

  87. @holly_cummins #RedHat
    so does quarkus reduce
    carbon emissions?

    View Slide

  88. @holly_cummins #RedHat
    so does quarkus reduce
    carbon emissions?
    quarkus ‘automatically’ saves

    View Slide

  89. @holly_cummins #RedHat
    so does quarkus reduce
    carbon emissions?
    quarkus ‘automatically’ saves
    • time

    View Slide

  90. @holly_cummins #RedHat
    so does quarkus reduce
    carbon emissions?
    quarkus ‘automatically’ saves
    • time
    • money

    View Slide

  91. @holly_cummins #RedHat
    so does quarkus reduce
    carbon emissions?
    quarkus ‘automatically’ saves
    • time
    • money
    • carbon (~2x)

    View Slide

  92. @holly_cummins #RedHat
    so does quarkus reduce
    carbon emissions?
    quarkus ‘automatically’ saves
    • time
    • money
    • carbon (~2x)

    View Slide

  93. @holly_cummins #RedHat
    caveat
    • benchmarks vary


    • applications vary


    • if you have some edge case where
    performance is worse with quarkus,
    carbon footprint is also likely to be
    worse

    View Slide

  94. @holly_cummins #RedHat
    but what about native?
    reminder


    View Slide

  95. @holly_cummins #RedHat
    but what about native?
    reminder


    View Slide

  96. @holly_cummins #RedHat
    but what about native?
    reminder


    View Slide

  97. @holly_cummins #RedHat
    but what about native?
    use case for native
    reminder


    View Slide

  98. @holly_cummins #RedHat
    but what about native?
    use case for native
    • low workload (throughput isn’t the
    bottleneck)
    reminder


    View Slide

  99. @holly_cummins #RedHat
    but what about native?
    use case for native
    • low workload (throughput isn’t the
    bottleneck)
    • resource-constrained or old hardware
    (especially memory)
    reminder


    View Slide

  100. @holly_cummins #RedHat
    but what about native?
    use case for native
    • low workload (throughput isn’t the
    bottleneck)
    • resource-constrained or old hardware
    (especially memory)
    • high re-deploy rate (applications never
    get warmed up before being spun down)
    reminder


    View Slide

  101. @holly_cummins #RedHat
    but what about native?
    use case for native
    • low workload (throughput isn’t the
    bottleneck)
    • resource-constrained or old hardware
    (especially memory)
    • high re-deploy rate (applications never
    get warmed up before being spun down)
    • serverless (of course)
    reminder


    View Slide

  102. @holly_cummins #RedHat
    but what about native?
    use case for native
    • low workload (throughput isn’t the
    bottleneck)
    • resource-constrained or old hardware
    (especially memory)
    • high re-deploy rate (applications never
    get warmed up before being spun down)
    • serverless (of course)
    use case for JVM
    reminder


    View Slide

  103. @holly_cummins #RedHat
    but what about native?
    use case for native
    • low workload (throughput isn’t the
    bottleneck)
    • resource-constrained or old hardware
    (especially memory)
    • high re-deploy rate (applications never
    get warmed up before being spun down)
    • serverless (of course)
    use case for JVM
    • high workload (you need lots of
    throughput)
    reminder


    View Slide

  104. @holly_cummins #RedHat
    but what about native?
    use case for native
    • low workload (throughput isn’t the
    bottleneck)
    • resource-constrained or old hardware
    (especially memory)
    • high re-deploy rate (applications never
    get warmed up before being spun down)
    • serverless (of course)
    use case for JVM
    • high workload (you need lots of
    throughput)
    • long-lived processes (the rapid start of
    native doesn’t save you much over the
    lifetime)
    reminder


    View Slide

  105. @holly_cummins #RedHat
    but what about native?
    use case for native
    • low workload (throughput isn’t the
    bottleneck)
    • resource-constrained or old hardware
    (especially memory)
    • high re-deploy rate (applications never
    get warmed up before being spun down)
    • serverless (of course)
    use case for JVM
    • high workload (you need lots of
    throughput)
    • long-lived processes (the rapid start of
    native doesn’t save you much over the
    lifetime)
    • stable workload or very little elasticity in
    underlying orchestration
    reminder


    View Slide

  106. @holly_cummins #RedHat
    use case for native


    • low workload (so throughput isn’t the
    bottleneck)


    • resource-constrained or old hardware
    (especially memory)


    • high re-deploy rate (applications never
    get warmed up before being spun down)


    • serverless (of course)

    use case for JVM


    • high workload (you need lots of
    throughput)


    • long-lived processes (the rapid start of
    native doesn’t save you much over the
    lifetime)


    • stable workload or very little elasticity in
    underlying orchestration
    but what about native?
    to optimise carbon


    View Slide

  107. @holly_cummins #RedHat
    yes, those are the same
    optimising


    • cost


    • application performance


    will also be optimising carbon

    View Slide

  108. @holly_cummins #RedHat
    native vs JVM is not an either-or
    • consider hybrid
    deployment models


    • a strength of Quarkus is
    application code is the
    same for native and JVM

    View Slide

  109. @holly_cummins #RedHat
    native CLIs?
    • native is not just for serverless


    • native Java makes great CLIs


    • is a CLI usually the most carbon-
    efficient way to do something?

    View Slide

  110. @holly_cummins #RedHat
    elasticity
    native quarkus starts
    faster than a light bulb

    View Slide

  111. @holly_cummins #RedHat
    but.


    an app starting fast isn’t elasticity …


    …unless you also stop the app

    View Slide

  112. @holly_cummins #RedHat
    how does quarkus help reduce carbon?
    energy usage
    elasticity
    machine
    selection
    (provisioning)

    View Slide

  113. @holly_cummins #RedHat
    how does quarkus help reduce carbon?
    energy usage
    ‘free’


    direct


    easy to measure
    elasticity
    machine
    selection
    (provisioning)

    View Slide

  114. @holly_cummins #RedHat
    how does quarkus help reduce carbon?
    energy usage
    ‘free’


    direct


    easy to measure
    lower memory usage


    higher throughput for same resources
    elasticity
    machine
    selection
    (provisioning)

    View Slide

  115. @holly_cummins #RedHat
    how does quarkus help reduce carbon?
    energy usage
    ‘free’


    direct


    easy to measure
    lower memory usage


    higher throughput for same resources
    ‘enabled behaviours’


    harder to measure real world impact


    depends on people taking advantage
    elasticity
    machine
    selection
    (provisioning)

    View Slide

  116. @holly_cummins #RedHat
    how does quarkus help reduce carbon?
    energy usage
    ‘free’


    direct


    easy to measure
    lower memory usage


    higher throughput for same resources
    ‘enabled behaviours’


    harder to measure real world impact


    depends on people taking advantage
    elasticity
    machine
    selection
    (provisioning)

    View Slide

  117. @holly_cummins #RedHat
    how does quarkus help reduce carbon?
    energy usage
    ‘free’


    direct


    easy to measure
    lower memory usage


    higher throughput for same resources
    ‘enabled behaviours’


    harder to measure real world impact


    depends on people taking advantage
    elasticity
    machine
    selection
    (provisioning)
    running the same workload on a smaller
    machine


    saves energy


    saves embodied carbon

    View Slide

  118. @holly_cummins #RedHat
    how does quarkus help reduce carbon?
    energy usage
    ‘free’


    direct


    easy to measure
    lower memory usage


    higher throughput for same resources
    ‘enabled behaviours’


    harder to measure real world impact


    depends on people taking advantage
    elasticity
    machine
    selection
    (provisioning)
    scaling workloads down (ideally to 0)


    serverless a good example (but not the only one)
    running the same workload on a smaller
    machine


    saves energy


    saves embodied carbon

    View Slide

  119. @holly_cummins #RedHat
    elasticity
    utilisation
    efficiency
    utility

    View Slide

  120. @holly_cummins #RedHat
    we need a new mental model
    car:


    high max speed means high fuel
    usage per mile travelled

    View Slide

  121. @holly_cummins #RedHat
    software:


    high max transactions means
    low carbon per transaction
    we need a new mental model
    car:


    high max speed means high fuel
    usage per mile travelled

    View Slide

  122. @holly_cummins #RedHat
    “no-regrets” solutions

    View Slide

  123. @holly_cummins
    #RedHat

    View Slide

  124. @holly_cummins
    #RedHat
    co-benefits

    View Slide

  125. @holly_cummins
    #RedHat
    co-benefits
    the double win

    View Slide

  126. @holly_cummins
    #RedHat
    co-benefits
    the double win
    win-win

    View Slide

  127. @holly_cummins
    #RedHat
    co-benefits
    the double win
    win-win
    win-squared

    View Slide

  128. @holly_cummins
    #RedHat
    co-benefits
    the double win
    win-win
    win-squared
    1 + 1 = 3

    View Slide

  129. @holly_cummins
    #RedHat
    co-benefits
    the double win
    win-win
    win-squared
    1 + 1 = 3
    twofer

    View Slide

  130. @holly_cummins
    #RedHat
    co-benefits
    the double win
    win-win
    win-squared
    1 + 1 = 3
    twofer
    überwinden

    View Slide

  131. @holly_cummins
    #RedHat
    co-benefits
    the double win
    win-win
    win-squared
    1 + 1 = 3
    twofer
    überwinden
    the extra win

    View Slide

  132. @holly_cummins
    #RedHat
    co-benefits
    the double win
    win-win
    win-squared
    1 + 1 = 3
    twofer
    überwinden
    the extra win

    View Slide

  133. @holly_cummins #RedHat
    climate solutions can
    make everything better

    View Slide

  134. @holly_cummins #RedHat
    remember the zombie servers?
    https://www.business2community.com/cloud-computing/overprovisioning-always-on-resources-lead-to-26-6-billion-in-public-cloud-waste-expected-in-2021-02381033

    View Slide

  135. @holly_cummins #RedHat
    remember the zombie servers?
    $26.6 billion
    https://www.business2community.com/cloud-computing/overprovisioning-always-on-resources-lead-to-26-6-billion-in-public-cloud-waste-expected-in-2021-02381033

    View Slide

  136. @holly_cummins #RedHat
    remember the zombie servers?
    $26.6 billion
    wasted
    https://www.business2community.com/cloud-computing/overprovisioning-always-on-resources-lead-to-26-6-billion-in-public-cloud-waste-expected-in-2021-02381033

    View Slide

  137. @holly_cummins #RedHat
    remember the zombie servers?
    $26.6 billion
    wasted
    in 2021
    https://www.business2community.com/cloud-computing/overprovisioning-always-on-resources-lead-to-26-6-billion-in-public-cloud-waste-expected-in-2021-02381033

    View Slide

  138. @holly_cummins #RedHat
    the double-win
    turning things off saves a lot of money

    View Slide

  139. @holly_cummins #RedHat
    the double-win
    turning things off saves a lot of money

    View Slide

  140. @holly_cummins #RedHat
    the double-win
    renewable electricity is 9x cheaper

    View Slide

  141. @holly_cummins #RedHat
    the double-win
    renewable electricity is 9x cheaper
    hosting in Finland:

    View Slide

  142. @holly_cummins #RedHat
    the double-win
    renewable electricity is 9x cheaper
    hosting in Finland:
    43% less carbon than the same workload in London

    View Slide

  143. @holly_cummins #RedHat
    the double-win
    renewable electricity is 9x cheaper
    hosting in Finland:
    43% less carbon than the same workload in London
    and it’s 15% cheaper

    View Slide

  144. @holly_cummins #RedHat
    the double-win

    View Slide

  145. @holly_cummins #RedHat
    the double-win

    View Slide

  146. @holly_cummins #RedHat
    “this is not sacrifice. it’s advancement.”

    View Slide

  147. @holly_cummins #RedHat
    we all have a part to play
    • choose your hosting wisely


    • use your buying power to encourage
    businesses to do make greener choices


    • turn things off when you’re not using them


    • choose an energy-efficient framework


    • all of this is a win anyway

    View Slide

  148. thank you


    @holly_cummins
    slides

    View Slide