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

Writing Greener Java Applications

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

January 19, 2023
Tweet

More Decks by Holly Cummins

Other Decks in Programming

Transcript

  1. Holly Cummins


    Senior Principal Software Engineer, Quarkus


    @[email protected]
    Writing Greener
    Java Applications
    Red Hat


    View full-size 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 full-size 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 full-size slide

  4. @holly_cummins #RedHat
    aaaaaaaargh

    View full-size slide

  5. @holly_cummins #RedHat
    aaaaaaaargh?

    View full-size slide

  6. @holly_cummins #RedHat
    be a solutionist

    View full-size slide

  7. @holly_cummins #RedHat
    what should we do?

    View full-size slide

  8. @holly_cummins #RedHat
    • right thing to do


    • business benefits


    • lower costs


    • higher ESG score


    • competitive advantage


    • recruitment advantage
    should we reduce our
    greenhouse gases?

    View full-size slide

  9. @holly_cummins #RedHat

    View full-size 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 full-size slide

  11. step 1: electricity source

    View full-size slide

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

    View full-size slide

  13. @holly_cummins #RedHat

    View full-size slide

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

    View full-size slide

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

    View full-size slide

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

    View full-size slide

  17. @holly_cummins #RedHat
    time of day matters
    • renewables are not “steady supply”


    • if grid load is high, shortfalls are
    filled by fossil fuels

    View full-size slide

  18. @holly_cummins #RedHat
    “carbon-aware”

    View full-size slide

  19. @holly_cummins #RedHat
    “carbon-aware”

    View full-size slide

  20. @holly_cummins #RedHat
    “carbon-aware”
    a data problem


    an orchestration problem

    View full-size slide

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

    View full-size slide

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

    View full-size slide

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

    View full-size slide

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

    View full-size slide

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

    View full-size slide

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

    View full-size slide

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

    View full-size slide

  28. @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 full-size slide

  29. @holly_cummins #RedHat

    View full-size slide

  30. #RedHat
    @holly_cummins
    2017 survey


    25%


    of 16,000 servers
    doing no useful work

    View full-size slide

  31. #RedHat
    @holly_cummins
    2017 survey


    25%


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

    View full-size slide

  32. @holly_cummins
    #RedHat
    ultimate elasticity


    View full-size slide

  33. @holly_cummins
    #RedHat
    ultimate elasticity


    View full-size slide

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


    View full-size slide

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


    View full-size slide

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


    View full-size slide

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


    View full-size slide

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


    View full-size slide

  39. @holly_cummins
    #RedHat

    View full-size slide

  40. @holly_cummins
    #RedHat
    LightSwitchOps

    View full-size slide

  41. @holly_cummins
    #RedHat
    LightSwitchOps

    View full-size slide

  42. @holly_cummins
    #RedHat
    efficiency

    View full-size slide

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

    View full-size slide

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

    View full-size slide

  45. energy efficiency
    of programming
    languages

    View full-size slide

  46. @holly_cummins
    #RedHat

    View full-size slide

  47. @holly_cummins
    #RedHat

    View full-size slide

  48. @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 full-size slide

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


    … what impact does the framework have?

    View full-size slide

  50. @holly_cummins #RedHat

    View full-size slide

  51. @holly_cummins #RedHat

    View full-size slide

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

    View full-size slide

  53. digression:


    measuring carbon is hard

    View full-size slide

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

    View full-size slide

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

    View full-size slide

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

    View full-size slide

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

    View full-size slide

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

    View full-size slide

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

    View full-size slide

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

    View full-size slide

  61. @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 full-size slide

  62. @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 full-size slide

  63. @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 full-size slide

  64. @holly_cummins #RedHat

    View full-size slide

  65. @holly_cummins #RedHat

    View full-size slide

  66. @holly_cummins #RedHat

    View full-size slide

  67. @holly_cummins #RedHat
    load

    View full-size slide

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

    View full-size slide

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

    View full-size slide

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

    View full-size slide

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

    View full-size slide

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

    View full-size slide

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

    View full-size slide

  74. @holly_cummins #RedHat
    simpler models

    View full-size slide

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

    View full-size slide

  76. @holly_cummins
    #RedHat

    View full-size slide

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

    View full-size slide

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

    View full-size slide

  79. @holly_cummins #RedHat
    economic model*

    View full-size slide

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

    View full-size slide

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

    View full-size slide

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

    View full-size slide

  83. so … quarkus?

    View full-size slide

  84. @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 full-size slide

  85. @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 full-size slide

  86. • quarkus cuts carbon by ~2x*


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

    View full-size slide

  87. @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 full-size slide

  88. @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 full-size slide

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


    • native consumes more carbon
    than JVM


    capacity test: conclusions
    * OOM heuristic

    View full-size slide

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

    View full-size slide

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

    View full-size slide

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

    View full-size slide

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

    View full-size slide

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

    View full-size slide

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

    View full-size slide

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

    View full-size slide

  97. @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 full-size slide

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


    View full-size slide

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


    View full-size slide

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


    View full-size 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)
    reminder


    View full-size 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)
    reminder


    View full-size 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)
    reminder


    View full-size 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
    reminder


    View full-size 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)
    reminder


    View full-size slide

  106. @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 full-size slide

  107. @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 full-size slide

  108. @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 full-size slide

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


    • cost


    • application performance


    will also be optimising carbon

    View full-size slide

  110. @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 full-size slide

  111. @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 full-size slide

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

    View full-size slide

  113. @holly_cummins #RedHat
    but.


    an app starting fast isn’t elasticity …


    …unless you also stop the app

    View full-size slide

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

    View full-size slide

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


    direct


    easy to measure
    elasticity
    machine
    selection
    (provisioning)

    View full-size 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
    elasticity
    machine
    selection
    (provisioning)

    View full-size 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)

    View full-size 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)

    View full-size slide

  119. @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 full-size slide

  120. @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 full-size slide

  121. @holly_cummins #RedHat
    elasticity
    utilisation
    efficiency
    utility

    View full-size slide

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


    high max speed means high fuel
    usage per mile travelled

    View full-size slide

  123. @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 full-size slide

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

    View full-size slide

  125. @holly_cummins
    #RedHat

    View full-size slide

  126. @holly_cummins
    #RedHat
    co-benefits

    View full-size slide

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

    View full-size slide

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

    View full-size slide

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

    View full-size slide

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

    View full-size slide

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

    View full-size slide

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

    View full-size slide

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

    View full-size slide

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

    View full-size slide

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

    View full-size slide

  136. @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 full-size slide

  137. @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 full-size slide

  138. @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 full-size slide

  139. @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 full-size slide

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

    View full-size slide

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

    View full-size slide

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

    View full-size slide

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

    View full-size slide

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

    View full-size slide

  145. @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 full-size slide

  146. @holly_cummins #RedHat
    the double-win

    View full-size slide

  147. @holly_cummins #RedHat
    the double-win

    View full-size slide

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

    View full-size slide

  149. @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 full-size slide