Greener coding - Making a 'gold' reference configuration with the Wagtail demo site #8843
Replies: 11 comments 14 replies
-
I may not be the best person to help you out with this (or have the time), but I wanted to give my support to this really cool idea! |
Beta Was this translation helpful? Give feedback.
-
Sounds pretty cool to me! I don’t have the time to help with instrumentation right now (our next release is due soon) but am generally very interested in Wagtail’s climate impact, and in particular in documentation and recommendations we could make to implementers. To start with, maybe it’s the right time for a #sustainability channel on our Slack like WordPress? There’s been discussions about the impact of Wagtail in the past, but mostly behind closed doors. Back to the premise of your proposal @mrchrisadams, I have two questions:
|
Beta Was this translation helpful? Give feedback.
-
This is really interesting - happy to help where I can! I've done plenty of setting up of bakery demo instances, although less so when it comes to actual production setups. On the subject of wagtail-bakery for generating static files, the underlying django-bakery package is currently lagging behind on Django 4 support, and it's a little unclear how much work it's going to take to get that project back up to speed with regular CI testing. As a result, I recently came up with a replacement, wagtail-freezer - currently very minimal, with just enough functionality to get it working on my personal site. Happy to hear any feedback on how it can be made more widely useful! |
Beta Was this translation helpful? Give feedback.
-
Speaking as someone who has run numerous Wagtail and Django sites in production (both at Torchbox and elsewhere), this sounds like a really interesting avenue of research. If you're optimising purely for carbon efficiency, there definitely a lot of dials to turn, but I'm not sure how many of them are necessarily Wagtail or even Django specific? One could argue if that's what you're chasing, Python might not be the best choice. With your LAMP stack, what recommendations were you able to give? Do you imagine any of them being adaptable to a Django-based application? Measurements is 1 thing, but actions are presumably the main goal here. That said, definitely happy to help out where I can! Suspect there might be some interesting links between this and the performance team |
Beta Was this translation helpful? Give feedback.
-
Hey all, Arne here from Green Coding Berlin. We are the developers behind the Green Metrics Tool that @mrchrisadams mentioned earlier. If we could contribute some work on this topic, we would be very helpful to. So I thought I join the discussion here. In the topic there are two repositories mentioned and it feels to me like they might be convoluted.
So far correct? On the topic of comparing static site builders with the energy cost of requests to a dynamic CMS we have for instance made a small article about to get an idea of the order of magnitude they differ: https://www.green-coding.org/case-studies/wordpress-vs-hugo-cloudflare/ The other topic, what Chris mentioned I guess, is to get an idea of the order of magnitude the general energy consumption a Django project lies in it would be helpful to have a standardized setup & interaction with such a project. My question: Is there a standard setup of Unit Tests / E2E Tests / Selenium interactions with the [Wagtail BakeryDemo](Wagtail BakeryDemo) app that we could use to run such a measurement? |
Beta Was this translation helpful? Give feedback.
-
Hi all, took me a while to get back to this but here we are! Here is the proposed reference configuration as well as tentative automated Puppeteer scripts to benchmark it: https://github.com/thibaudcolas/bakerydemo-gold-benchmark This is based upon our vanilla bakerydemo, with additional Django and Docker configuration improvements to be more representative of a real-world production site – and a few compromises on top so it can still be run locally. I’ve documented those improvements and key differences with a real site in the README for future reference. The README also contains instructions on how to benchmark the site,
I’d love any and all feedback on this, and particularly from you @mrchrisadams and @ArneTR whether this seems like it’ll work with Green Metrics. One particular point I could use feedback on is the obvious ways in which this will differ from a real-world site and how (or whether) to account for them. With this setup, the site is:
And for the user journeys – the main shortcoming I believe is how fast an automated script would go through the steps compared to a user. I’ve introduced a few delays so the test cases run in 10-20s rather than 1-2s, but that’s still a good order of magnitude faster than real-world user journeys. Here are sample times people spend on different page types across sites we manage as an illustration:
|
Beta Was this translation helpful? Give feedback.
-
Uhh, very nice! I will get on these measurements asap ... hopefully before christmas, but if not then def. in the days between NYE. Regarding the GreenFrame CLI: Nice that you are checking out that tool. We were very happy that they finally open sourced it. Do you have the results somewhere for qualitative comparison? Regarding your questions:
Since no current agreed upon way for a "standard test scenario" for web-frameworks exists we just have to assume one. I believe this test here is very early and reasonable assumptions are the best for now. I will send remarks however on the setup as it is regarding our internal experience on how we design energy test setups. |
Beta Was this translation helpful? Give feedback.
-
Just a quick update as I did not stick to my initial time planning ... holidays were a bit more relaxed than expected :) @ribalba is currently working on the task and we expect to have something ready by mid / end next week. The scenarios are quite straightforward. The only thing we have to do here is to annotate them so they display better in graphs and one can easily see when which step is executed. A question I have out of curiosity and for comparison regarding particular the Greenframe measurements:
|
Beta Was this translation helpful? Give feedback.
-
thanks for this discussion; |
Beta Was this translation helpful? Give feedback.
-
Hey @thibaudcolas , we have forked the repository to make it clear what changes we made to make it run with the GMT: https://github.com/green-coding-berlin/bakerydemo-gold-benchmark I hope the Diff shows that only minor touches were necessary:
Really looking forward to your feedback especially if the
The static tests we have excluded in this first run, as they need a different setup in our tool, that we are working on. I expect to have them ready by end next week. An note on the test setup and result quality
Please give it a look and ask questions. I think from here we can now go next steps and am interested in what questions you have:
Thank you for your great work! It was very easy to build on your gold benchmark. I was really blown away by the throrough documentation and all the prepared files!! |
Beta Was this translation helpful? Give feedback.
-
Hey @thibaudcolas , sorry for being silent for so long. We have been working internally not only on making the static measurements work easier, but also on revamping our Green Metrics Tool so that it can natively compare softwares and also incorporate stuff like phases (think of container build, container boot etc.). We have modified the repo you have created in the following ways:
To make it easily viewable what we have changed I have opened two pull requests:
Also, the I hope most interesting part: Here would be the comparison between these two cases Very interested in your feedback! The idea for the pull requests in particular would be to track the changes of Wagtail over time and see how the energy compares for this reference implementation. Our tool can track changes over time through a "Repeated Runs" or "Commits" comparison as we call it. Effectively you will the the changes over time aggregated. See an example here: Repeated Runs comparison |
Beta Was this translation helpful? Give feedback.
-
Hi there.
I hope this isn't too left-field for the discussion here. I'm a fan of wagtail, I've used it in production on a few projects, and personally it's my favourite CMS. After doing a few talks about django and climate, I wanted to see if there was interest in the community in demonstrating some of the ideas using Wagtail as as real world reference project.
I've recently been working with the nice folks at Green Coding Berlin, who have set up a test rig for running code, for a few given users journeys then tracking the energy usage for different deployment configurations of the software you might use.
We did it recently to make some comparisons between running a user journey for a Wordpress site that was hosted by a more common dynamically hosted LAMP stack, then comparing the same to using a 'baked' version of the static site.
The system works by taking a few processes like a browser, an app server, and providing a degree of isolation (shown here using docker, but only for convenience - you can use other more robust forms of isolation too), running them as a system under test, then carrying out the same user journey for different 'systems'.
The diagram, extremely simplified looks like this:
The actual running rig right now looks a bit more like this
Anyway, you can see an example of the charted data for the difference processes in this busy diagram below - the blue is the resource usage for a browser visiting a hosted site, the yellow is a Maria DB server, and the green is the Apache and PHP server:
There's more data if you fancy wading through it for this test run, but I need to stress, this is all in development, and I can't make any guarantees about the data being online forever.
By comparison, you can check the resource usage there for a common lamp stack style setup, versus a 'baked' version where once content has been created, you only need the static server.
You have basically the same user journeys, and you can see similar spikes in resource usage client side, but server side it's pretty much flat. If you look at the entire system data for the second run, you'll see that the total energy use for the whole system, including the browser is about a third of the energy.
It shouldn't come as a surprise that serving static files is less energy intensive, but I hadn't come across numbers on a per-run basis like this before, and I think you can use this a basis for some interesting ideas in django world.
Adapting this to Django and Wagtail
For the demo above, we used real content from the non profit I help run, The Green Web Foundation, but I think that the Wagtail Bakery Demo is a pretty good reference application, that you could run in a number of different deployment configurations to better understand the resource usage trade-offs associated with different stacks used.
I'm thinking you might be able to use it to answer questions like:
Is there a similar saving from using wagtail with the other bakery app, the wagtail bakery django app as part of a deployment process?
Is it possible to run the entire common wagtail editing user journeys using an entirely scale-to-zero stack?
_ (ie. some provider of Cloud Run-style services for app servers, using something like neon.tech for OSS scale-to-zero Postgres, and object storage for static files)?
Are the savings worth the extra hassle compared to running it on a VPS?
I'm not sure you can answer that with charts, but you can at least get some idea of the difference in resource footprint for the different deployment configurations.
Related - other ways to get metrics for high level comparisons
I totally appreciate that the project I've linked to above is only testing stuff you can containerise and run in the rig pictured, but there are other ways of getting numbers for other parts of the system too, for making some initial comparisons.
Below is an example for the environmental footprint from running code in a number of configurations from a "functions as a service" based way to comparing it to common setups for serving the same code, like running the same work in a VPS, or VPS with warm standby:
https://www.linkedin.com/pulse/quantifying-greenness-faas-lukasz-mastalerz/
There are also similar examples where other OSS tooling like cloud carbon footprint have been used to model out the likely environmental footprint of consuming other 3rd party services from larger cloud providers, like this post from Chris Ward.
This post demonstrates using cloud carbon footprint to model the likely footprint for a project handlig requests for 1000 concurrent users using a serverless system, gradually adding more to the project til they add an always-on cloud SQL service that ends up being the source of 90% of the projected energy use (mainly because it's one part that doesn't scale to zero when not actively used).
https://chronosphere.io/learn/increasing-cloud-native-sustainability-with-observability/
The code for the green coding tool
The green coding metrics tool is called imaginatively enough, "Green Metrics Tool", and is AGPL licensed. you can see it below:
https://github.com/green-coding-berlin/green-metrics-tool
There's a blog here:
https://www.green-coding.org/blog/
And various examples of metrics from other testing runs:
https://metrics.green-coding.org/
My ask - help making a "GOLD" Wagtail
I've been using the mnemonic GOLD ( green, open, lean, distributed) as a way to talk about the qualities of 'greener' development in a few talks in the django community. I've outlined a below with videos
I like Wagtail, but I'm not as experienced with it as I'd like and it would be useful to get some pointers on how to get a system under test, like the examples above, but using a recent version of wagtail.
Why I think this would be interesting for wagtail users
If this can be set up I think it's then possible to quantify the resource savings with different deployment setups of wagtail, and this would likely be the first significant OSS community project I know where these kind of considerations are well documented with a open and defensible process.
I think this would also make it possible to quantify the impact of optimising certain hot spots in the code inside wagtail for representative user journeys over time too
I'd be very much up for contributing documentation and recommendations to the wagtail project based on what we might learn if there was interest.
So, to recap... if:
Would you please leave a comment below?
If nothing else it might make a fun wagtail space project in future (I'm sorry I missed the last one in June…)
Beta Was this translation helpful? Give feedback.
All reactions