$30 off During Our Annual Pro Sale. View Details »

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

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
  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
  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
  4. @holly_cummins #RedHat aaaaaaaargh

  5. @holly_cummins #RedHat aaaaaaaargh?

  6. @holly_cummins #RedHat be a solutionist

  7. @holly_cummins #RedHat what should we do?

  8. @holly_cummins #RedHat • right thing to do • business benefits

    • lower costs • competitive advantage • recruitment advantage should we reduce our greenhouse gases?
  9. @holly_cummins #RedHat

  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
  11. step 1: electricity source

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

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

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

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

    hosting region choose a cloud provider who make this easy
  16. @holly_cummins #RedHat step 2: the four vowels

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

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

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

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

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

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

    utility
  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
  24. #RedHat @holly_cummins 2017 survey 25% of 16,000 servers doing no

    useful work
  25. #RedHat @holly_cummins 2017 survey 25% of 16,000 servers doing no

    useful work “perhaps someone forgot to turn them off”
  26. @holly_cummins #RedHat ultimate elasticity

  27. @holly_cummins #RedHat ultimate elasticity

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

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

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

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

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

    be fast • actually work • idempotency • resiliency ultimate elasticity
  33. @holly_cummins #RedHat

  34. @holly_cummins #RedHat LightSwitchOps

  35. @holly_cummins #RedHat LightSwitchOps

  36. @holly_cummins #RedHat efficiency

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

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

  39. None
  40. energy efficiency of programming languages

  41. @holly_cummins #RedHat

  42. @holly_cummins #RedHat

  43. None
  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
  45. @holly_cummins #RedHat if JVM parameters can make that much difference

    … … what impact does the framework have?
  46. @holly_cummins #RedHat

  47. @holly_cummins #RedHat

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

  49. digression: measuring carbon is hard

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

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

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

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

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

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

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

    more complete needs access to the wall and equipment and notebooks RAPL
  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
  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
  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
  60. @holly_cummins #RedHat

  61. @holly_cummins #RedHat

  62. @holly_cummins #RedHat

  63. @holly_cummins #RedHat load

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

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

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

  67. @holly_cummins #RedHat published energy mixes … but methodologies are not

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

    open … or consistent (these are made-up energy mixes)
  69. @holly_cummins #RedHat step 3: embedded carbon (manufacturing has costs)

  70. @holly_cummins #RedHat simpler models

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

  72. @holly_cummins #RedHat

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

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

    execution time
  75. @holly_cummins #RedHat economic model*

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

  77. @holly_cummins #RedHat reducing your cloud spend (probably) reducing your carbon

    footprint* hardware spend electricity bill * if you keep other factors the same
  78. @holly_cummins #RedHat all models are wrong, some are useful

  79. so … quarkus?

  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
  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
  82. • quarkus cuts carbon by ~2x* • native has a

    slightly smaller carbon footprint * OOM heuristic density test: conclusions
  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)
  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)
  85. • quarkus cuts carbon by ~2-3x* • native consumes more

    carbon than JVM capacity test: conclusions * OOM heuristic
  86. @holly_cummins #RedHat so does quarkus reduce carbon emissions?

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

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

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

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

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

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

    saves • time • money • carbon (~2x)
  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
  94. @holly_cummins #RedHat but what about native? reminder

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

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

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

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

    • low workload (throughput isn’t the bottleneck) reminder
  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
  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
  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
  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
  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
  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
  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
  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
  107. @holly_cummins #RedHat yes, those are the same optimising • cost

    • application performance will also be optimising carbon
  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
  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?
  110. @holly_cummins #RedHat elasticity native quarkus starts faster than a light

    bulb
  111. @holly_cummins #RedHat but. an app starting fast isn’t elasticity …

    …unless you also stop the app
  112. @holly_cummins #RedHat how does quarkus help reduce carbon? energy usage

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

    ‘free’ direct easy to measure elasticity machine selection (provisioning)
  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)
  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)
  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)
  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
  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
  119. @holly_cummins #RedHat elasticity utilisation efficiency utility

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

    max speed means high fuel usage per mile travelled
  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
  122. @holly_cummins #RedHat “no-regrets” solutions

  123. @holly_cummins #RedHat

  124. @holly_cummins #RedHat co-benefits

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

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

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

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

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

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

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

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

    1 = 3 twofer überwinden the extra win
  133. @holly_cummins #RedHat climate solutions can make everything better

  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

  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

  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

  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
  138. @holly_cummins #RedHat the double-win turning things off saves a lot

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

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

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

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

    in Finland: 43% less carbon than the same workload in London
  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
  144. @holly_cummins #RedHat the double-win

  145. @holly_cummins #RedHat the double-win

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

  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
  148. thank you @holly_cummins slides