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: I work on Quarkus. Along the way, I will talk about Quarkus sustainability measurements we’ve been doing … but it’s ok, because the Quarkus carbon data is exciting and interesting, I promise.

Holly Cummins

May 09, 2023
Tweet

More Decks by Holly Cummins

Other Decks in Programming

Transcript

  1. @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
  2. @holly_cummins #RedHat • right thing to do • business benefits

    • lower costs should we reduce our greenhouse gases?
  3. @holly_cummins #RedHat • right thing to do • business benefits

    • lower costs • higher ESG score should we reduce our greenhouse gases?
  4. @holly_cummins #RedHat • right thing to do • business benefits

    • lower costs • higher ESG score • competitive advantage should we reduce our greenhouse gases?
  5. @holly_cummins #RedHat • right thing to do • business benefits

    • lower costs • higher ESG score • competitive advantage • recruitment advantage should we reduce our greenhouse gases?
  6. @holly_cummins #RedHat algorithms carbon awareness green software foundation: principles hardware

    efficiency electricity efficiency where when elasticity utilisation
  7. @holly_cummins #RedHat algorithms stack carbon awareness green software foundation: principles

    hardware efficiency electricity efficiency where when elasticity utilisation
  8. @holly_cummins #RedHat algorithms stack carbon awareness hardware efficiency electricity efficiency

    where when elasticity utilisation green software foundation: principles
  9. @holly_cummins #RedHat look at the sustainability information before choosing a

    hosting region choose a cloud provider who make this easy
  10. @holly_cummins #RedHat time of day matters • (most) renewables are

    intermittent • if grid load is high, shortfalls are filled by fossil fuels
  11. @holly_cummins #RedHat elasticity we used to leave our applications running

    all the time when we scripted turning them off at night, we reduced our cloud bill by 30% @darkandnerdy, Chicago DevOpsDays
  12. #RedHat @holly_cummins 2017 survey 25% of 16,000 servers doing no

    useful work “perhaps someone forgot to turn them off”
  13. #RedHat @[email protected] 2014 survey 29% of 4,000 active less than

    5% of the time https://www.anthesisgroup.com/wp-content/uploads/2019/11/Comatose-Servers-Redux-2017.pdf
  14. @holly_cummins #RedHat turning it off and on again must •

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

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

    be fast • actually work • idempotency • resiliency ultimate elasticity
  17. @holly_cummins #RedHat algorithms stack carbon awareness hardware efficiency electricity efficiency

    where when elasticity utilisation green software foundation: principles
  18. @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
  19. @holly_cummins #RedHat if JVM parameters can make that much difference

    … … what impact does the framework have?
  20. @holly_cummins #RedHat step 1: measure power usage wall power measurement

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

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

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

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

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

    more complete needs access to the wall and equipment and actual paper data costs carbon RAPL programmatically accessible misses some components
  26. @holly_cummins #RedHat published energy mixes … but methodologies are not

    open … or consistent (these are made-up energy mixes)
  27. @holly_cummins #RedHat reducing your cloud spend (probably) reducing your carbon

    footprint* hardware spend electricity bill * if you keep other factors the same
  28. @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
  29. @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
  30. • quarkus cuts carbon by ~2x* • native has a

    slightly smaller carbon footprint * OOM heuristic density test: conclusions
  31. @holly_cummins #RedHat capacity Source: John O’Hara Setup: • REST +

    CRUD • large heap • RAPL energy measurement Assumptions: • US energy mix climate impact at low load (single instance)
  32. @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 climate impact at high load (multiple instances)
  33. • quarkus cuts carbon by ~2-3x* • native consumes more

    carbon than JVM capacity test: conclusions * OOM heuristic
  34. @holly_cummins #RedHat but what about native? use case for native

    • low workload (throughput isn’t the bottleneck) reminder
  35. @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
  36. @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
  37. @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
  38. @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
  39. @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
  40. @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
  41. @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
  42. @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
  43. @holly_cummins #RedHat yes, those are the same optimising • cost

    • application performance will also be optimising carbon
  44. @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
  45. @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?
  46. @holly_cummins #RedHat how does quarkus help reduce carbon? energy usage

    ‘free’ direct easy to measure elasticity machine selection (provisioning)
  47. @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)
  48. @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)
  49. @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)
  50. @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
  51. @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
  52. @holly_cummins #RedHat we need a new mental model car: high

    max speed means high fuel usage per mile travelled
  53. @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
  54. @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
  55. @holly_cummins #RedHat the double-win renewable electricity is 9x cheaper hosting

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

    in Montreal: 88% less carbon than the same workload in London and it’s 15% cheaper
  57. @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