Greening Digital �With Django
(abridged)
www.thegreenwebfoundation.org
Chris
Adams
2024.06.27
Django User Group Berlin
1
GREEN WEB FOUNDATION
Hello, I’m Chris!
My background:
First started working with Django in 2008. My background is mainly in climate and open data startups and companies since then.��Loco2 - Low CO2 Travel in Europe by train
A.M.E.E (Avoid Mass Extinction Engine) - CO2 calculation as an API
Green Software Foundation - policy working group co-chair
Branch Magazine - contributor, co-founding editor
climateAction.tech - community organiser since 2018
Environment Variables podcast - host since 2022
Djangocon EU - various talks and workshops on this subject since 2017
Green Web Foundation - exec director, my full time job today
2
GREEN WEB FOUNDATION
GREEN WEB FOUNDATION
What we’ll cover
3
GREEN WEB FOUNDATION
GREEN WEB FOUNDATION
Accessing this deck
4
This deck is online with a bajillion links, and presenter notes.
The QR code will visible on the last slide too.
https://bit.ly/djangocon-eu-2024-greening-digital
GREEN WEB FOUNDATION
GREEN WEB FOUNDATION
The Green Web Foundation is working towards a fossil-free internet by 2030.
5
The internet should be a global public good —healthy for the planet and for the people who use it.
GREEN WEB FOUNDATION
Build open source tools, APIs, and libraries
6
GREEN WEB FOUNDATION
GREEN WEB FOUNDATION
Create prototypes.
Contribute to open source projects.
Publish open data.
7
GREEN WEB FOUNDATION
GREEN WEB FOUNDATION
Talks.
Workshops.
Training.
Consulting.
8
GREEN WEB FOUNDATION
GREEN WEB FOUNDATION
How digital causes emissions, and why measure it
GREEN WEB FOUNDATION
GREEN WEB FOUNDATION
How do digital services cause emissions?
GREEN WEB FOUNDATION
10
Source: https://developers.thegreenwebfoundation.org/co2js/overview/
Datacentre usage
End user device usage
Network transfer
Production and disposal
Powering and cooling servers
Powering core networks, mobile networks,
on-premise wifi and fixed routers
Powering end user devices - laptops, workstations, smartphones and tablets
Energy usage from making all of the above - processing raw silicon and other raw materials into integrated circuits, batteries, metal casings, etc
GREEN WEB FOUNDATION
Estimates vary, but between 2% and 4% of global carbon emissions is safe to use.
GREEN WEB FOUNDATION
11
How big is tech’s carbon footprint?
Source: https://www.thegreenwebfoundation.org/publications/report-fog-of-enactment/
GREEN WEB FOUNDATION
12
Credit: Photo by Skyler Smith on Unsplash
GREEN WEB FOUNDATION
13
Credit: Photo by Andy Li on Unsplash
GREEN WEB FOUNDATION
The internet is the biggest machine in the world, and today, it mostly runs on fossil fuels.
GREEN WEB FOUNDATION
14
Source: https://www.thegreenwebfoundation.org/publications/report-fog-of-enactment/
GREEN WEB FOUNDATION
How does this affect me though?
(apart from the whole climate anxiety thing, obvs)
GREEN WEB FOUNDATION
New changes in the law are making firms care more about two things:
1. Climate Disclosure: what are my emissions?
2. Climate Response: what is my plan to reduce them?
GREEN WEB FOUNDATION
Driving Climate Disclosure
17
“Show us you track emissions, and share this info with society”
Corporate Sustainability Reporting Directive (CSRD)
Climate Corporate Data Accountability Act (CCDAA)
GREEN WEB FOUNDATION
GREEN WEB FOUNDATION
Driving Climate Disclosure
18
liberté�egalité�CSRDé
GREEN WEB FOUNDATION
GREEN WEB FOUNDATION
Scope 3
Scope 1
Scope 2
Scope 3
Upstream
Directly reported
Downstream
GHG Protocol and Scoped Emissions Reporting
GREEN WEB FOUNDATION
How I remember the Greenhouse Gas Protocol
Greenhouse Gas Protocol:
Scope 1,
Scope 2,
Scope 3
20
Emissions from burning fossil fuels to make hot coffee
Scope 1
Emissions from electricity generated on your behalf, to make coffee
Scope 2
Emissions from activity in your supply chain, so you can have coffee
Scope 3
Scoped emissions communicated through the medium of hot beverages
GREEN WEB FOUNDATION
GREEN WEB FOUNDATION
Scope 3
Scope 1
Scope 2
Scope 3
Upstream
Directly reported
Downstream
GHG Protocol and Scoped Emissions Reporting - if you sell to affected firms
You are here
And maybe here
GREEN WEB FOUNDATION
Driving Climate Response
22
“Show us you have a plan informed by the science”
Corporate Supply Chain Due Diligence Directive (CSDDD)
GREEN WEB FOUNDATION
GREEN WEB FOUNDATION
Driving Climate Response
23
“Show us you have a plan informed by the science”
GREEN WEB FOUNDATION
GREEN WEB FOUNDATION
Emerging Standards: Software Carbon Intensity
Think of “carbon emitted per activity”.
CO2e per page request
CO2e per CI run
CO2e per LLM query
CO2e per ad impression
Created by the Green Software Foundation - with a freely available spec. Developed in the open on GitHub.
24
https://sci.greensoftware.foundation
GREEN WEB FOUNDATION
GREEN WEB FOUNDATION
Emerging Standards: Software Carbon Intensity
25
Now a recognised ISO standard, as of March 2024
https://www.iso.org/standard/86612.html
GREEN WEB FOUNDATION
GREEN WEB FOUNDATION
Key takeaways.
1. Climate Disclosure: what are my emissions?
2. Climate Response: what is my plan to reduce them?�3. Digital has an impact too: we will�need to be able to answer questions �about our plans to reduce it when asked
GREEN WEB FOUNDATION
How people estimate carbon emissions for digital
GREEN WEB FOUNDATION
GREEN WEB FOUNDATION
All models are wrong, some models are useful.
GEORGE BOX
Empirical Model-Building and Response Surfaces, 1987
28
“
GREEN WEB FOUNDATION
Usage based
29
Billing based
Estimate emissions based on observed usage of one or more parts of a system.
Estimate emissions based on observed spend. Turn billing data into emissions data.
GREEN WEB FOUNDATION
GREEN WEB FOUNDATION
Usage based tooling
30
Component view
System view
Global view
Firefox profiler:
Javascript, browser reports own energy / carbon use. �
Code Carbon:
Python, often used for AI, can wrap existing python code for server side measurements.
Scaphandre:
Rust, gives server-side per process figures for every process running.
Green Metrics Tool:
Python, simulates common usage scenarios
Greenframe
Proprietary, javascript. Simulates common usage scenarios
KEPLER
Kubernetes focussed, uses production telemetry data, growing corporate support
Website Carbon
Javascript, proprietary
Ecograder
Javascript, open source
Sitespeed.io
Javascript, used by Wikipedia, has own grafana dashboards
Webpage Test Carbon Control
php + js, available as hosted service
Common to start experimenting with these first.
(All use sustainable web model under the hood))
GREEN WEB FOUNDATION
GREEN WEB FOUNDATION
Billing based tooling
31
Native
Third party
Microsoft Emissions Impact Dashboard
Scopes 1, 2 and 3
AWS Customer Carbon Footprint Tool
Scopes 1, 2 (no scope 3- can make up to 99% of emissions in some cases)
Google Cloud Carbon Footprint
Scopes 1, 2 and 3
OVH
Scopes 1, 2 and 3, also water usage 👍
Cloud Carbon Footprint
Scopes 1,2 3 - first “significant” open source project
OpenCost
Recently merged PR now adds carbon costs to dashboards.
Green Pixie (proprietary)
Originally based on CCF, available as hosted service. Now offers richer data than just carbon.
(And more, each day)
Native have better access to data about underlying infra.�
3rd party options have more compatible across providers, and are often easier to trust (!)
GREEN WEB FOUNDATION
GREEN WEB FOUNDATION
What these tools look like
GREEN WEB FOUNDATION
GREEN WEB FOUNDATION
Starting out:
My suggestions for fellow Django users
33
Component view
System view
Global view
Firefox profiler
Javascript, reports measured browser energy
Code Carbon
Python, server side, often used for AI
Scaphandre
Rust, gives server-side per process figures
Green Metrics Tool
Python, simulates common usage scenarios
Greenframe
Proprietary, javascript simulates common usage scenarios
KEPLER
Kubernetes, uses production telemetry data for “real time” figures
Website Carbon
Javascript, proprietary
Ecograder
Javascript, open (?)
Sitespeed.io
Javascript
Webpage Test Carbon Control
php + js, available as hosted service
(All use sustainable web design model under the hood))
GREEN WEB FOUNDATION
GREEN WEB FOUNDATION
Website Carbon by Wholegrain Digital
Website Carbon is a usage based, global view tool.
Easy to use and explain to people new to the field.
34
GREEN WEB FOUNDATION
GREEN WEB FOUNDATION
WebPageTest by Catchpoint
Web Page Test is a usage based, global view tool.
Open source, offers more detail than Website Carbon.
35
GREEN WEB FOUNDATION
GREEN WEB FOUNDATION
Firefox Profiler by Mozilla Firefox
Firefox Profiler is a usage based, component view tool.
Open source - see our PR that added this :)��Might already be installed on your laptop (!)
36
GREEN WEB FOUNDATION
GREEN WEB FOUNDATION
Code Carbon by MILA and others
CodeCarbon is a usage based, component view tool for measuring carbon emissions for python code
Most common library used in AI papers for tracking carbon emissions of training.��Also pythonic: provides context managers and decorators
💚
from codecarbon import EmissionsTracker
�tracker = EmissionsTracker()
tracker.start()
�try:
# Compute intensive code goes here
_ = 1 + 1
finally:
tracker.stop()
37
GREEN WEB FOUNDATION
GREEN WEB FOUNDATION
Green Metrics Tool by Green Coding Solutions
GMT is a usage based, system view tool,
It creates a system comprised of instrumented docker containers, executes common use cases, and shows resource impacts.
See also: Extensive real-world example with Django Wagtail (and workshop at end of this talk)
38
GREEN WEB FOUNDATION
GREEN WEB FOUNDATION
Why Django is well placed to be the greenest framework out there
GREEN WEB FOUNDATION
GREEN WEB FOUNDATION
Why is Django well placed to lead in greening digital?
40
GREEN WEB FOUNDATION
GREEN WEB FOUNDATION
Thanks!
Follow this link for the deck, and an afternoon’s worth workshop of activities
www.linkedin.com/in/mrchrisadams
mastodon.social/@mrchrisadams�
climateAction.tech - a friendly community of climate-minded tech workers
podcast.greensoftware.foundation - I interview experts in this field to share what they know�branch.climateAction.tech - an online magazine all about this stuff
GREEN WEB FOUNDATION
GREEN WEB FOUNDATION
Extra bonus bits
GREEN WEB FOUNDATION
GREEN WEB FOUNDATION
Green Metrics Tool Full stack measurements
GREEN WEB FOUNDATION
GREEN WEB FOUNDATION
Green Metrics Tool (GMT) - what is it?
GMT is a usage based, system view tool, that creates a system under test, then simulates common interactions
44
Component view
System view
Global view
Usage based
GREEN WEB FOUNDATION
GREEN WEB FOUNDATION
How GMT works at very high level
Use docker to set up a system, and record metrics from “the outside”
45
GREEN WEB FOUNDATION
GREEN WEB FOUNDATION
What can you do with GMT?
Try different usage scenarios for your service - static vs dynamic, different page designs, etc.
46
https://www.green-coding.io/case-studies/wordpress-vs-hugo-cloudflare/
GREEN WEB FOUNDATION
GREEN WEB FOUNDATION
Applying this to django - what you need
If you have a dockerised app, you’re halfway there to trying it out.
If you have any integration tests that drive a browser, you have a head start on usage scenarios too
47
Django app
Postgres
Browser
docker-compose.yaml
Redis
usage_scenario.yaml
+
scripts to drive the browser
GREEN WEB FOUNDATION
GREEN WEB FOUNDATION
Learning from a real example - Wagtail and the bakery
Last year on the Wagtail GSoC project: used GMT to test common scenarios on the bakery demo site
48
GREEN WEB FOUNDATION
GREEN WEB FOUNDATION
Learning from a real example - entire lifecycle
Seeing the software carbon intensity for each usage scenario
49
GREEN WEB FOUNDATION
GREEN WEB FOUNDATION
Learning from a real example - putting the SCI in CI
Tracking Software Carbon Intensity in Continuous Integration
50
GREEN WEB FOUNDATION
GREEN WEB FOUNDATION
Learning from a real example
Figuring out what to do next.
�This is roadmap is entirely open source, and actively worked on again this Google Summer of Code.
51
GREEN WEB FOUNDATION
GREEN WEB FOUNDATION
Thanks!
Follow this link for the deck, and an afternoon’s worth workshop of activities
bit.ly/djangocon-eu-2024-greening-digital
www.linkedin.com/in/mrchrisadams
mastodon.social/@mrchrisadams�
climateAction.tech - a friendly community of climate-minded tech workers
podcast.greensoftware.foundation - I interview experts in this field to share what they know�branch.climateAction.tech - an online magazine all about this stuff
GREEN WEB FOUNDATION
GREEN WEB FOUNDATION