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 #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 • higher ESG score • competitive advantage • recruitment advantage should we reduce our greenhouse gases?
  3. 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
  4. @holly_cummins #RedHat look at the sustainability information before choosing a

    hosting region choose a cloud provider who make this easy
  5. @holly_cummins #RedHat time of day matters • renewables are not

    “steady supply” • if grid load is high, shortfalls are filled by fossil fuels
  6. @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
  7. #RedHat @holly_cummins 2017 survey 25% of 16,000 servers doing no

    useful work “perhaps someone forgot to turn them off”
  8. @holly_cummins #RedHat turning it off and on again must •

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

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

    be fast • actually work • idempotency • resiliency ultimate elasticity
  11. @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
  12. @holly_cummins #RedHat if JVM parameters can make that much difference

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

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

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

    more complete needs access to the wall and equipment and notebooks RAPL
  16. @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
  17. @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
  18. @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
  19. @holly_cummins #RedHat published energy mixes … but methodologies are not

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

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

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

    carbon than JVM capacity test: conclusions * OOM heuristic
  27. @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
  28. @holly_cummins #RedHat but what about native? use case for native

    • low workload (throughput isn’t the bottleneck) reminder
  29. @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
  30. @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
  31. @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
  32. @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
  33. @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
  34. @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
  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) • 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
  36. @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
  37. @holly_cummins #RedHat yes, those are the same optimising • cost

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

    ‘free’ direct easy to measure elasticity machine selection (provisioning)
  41. @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)
  42. @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)
  43. @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)
  44. @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
  45. @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
  46. @holly_cummins #RedHat we need a new mental model car: high

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

    in Finland: 43% less carbon than the same workload in London
  50. @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
  51. @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