<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Mirko Stocker on Medium]]></title>
        <description><![CDATA[Stories by Mirko Stocker on Medium]]></description>
        <link>https://medium.com/@mstocker?source=rss-ff9700c896a8------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/2*W4yAgr6a8uqwiBWmc_1bEQ.jpeg</url>
            <title>Stories by Mirko Stocker on Medium</title>
            <link>https://medium.com/@mstocker?source=rss-ff9700c896a8------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sat, 21 Nov 2026 09:22:58 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@mstocker/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Are Cloud-Native Applications the Answer to Software Sustainability?]]></title>
            <link>https://medium.com/growing-green-software/are-cloud-native-applications-the-answer-to-software-sustainability-42e16b33bc76?source=rss-ff9700c896a8------2</link>
            <guid isPermaLink="false">https://medium.com/p/42e16b33bc76</guid>
            <category><![CDATA[cloud-native-application]]></category>
            <category><![CDATA[sustainability]]></category>
            <category><![CDATA[software]]></category>
            <category><![CDATA[cloud-computing]]></category>
            <category><![CDATA[green-software]]></category>
            <dc:creator><![CDATA[Mirko Stocker]]></dc:creator>
            <pubDate>Mon, 26 May 2025 18:30:37 GMT</pubDate>
            <atom:updated>2025-05-26T18:30:37.441Z</atom:updated>
            <content:encoded><![CDATA[<p>According to <a href="https://en.wikipedia.org/wiki/Betteridge%27s_law_of_headlines">Betteridge’s law</a>, the answer to “any headline that ends in a question mark can be answered by the word <em>no</em>” in technology journalism. Let’s find out whether a green software developer also gives this answer to the question in the title of this post.</p><p>A previous post on <a href="https://medium.com/growing-green-software/carbon-emissions-in-ict-99a0d421bbb6">Carbon Emissions in ICT</a> looked at what cloud providers do to reduce their carbon footprint.</p><p><a href="https://medium.com/growing-green-software/carbon-emissions-in-ict-99a0d421bbb6">Carbon Emissions in ICT</a></p><p>We saw that many providers invest in renewable energy sources and improvement of their data center efficiency. Does this mean that can we simply move all our applications to the cloud and tick the sustainability checkbox? We can reveal this much: in true Betteridge style, the answer is ‘no’.</p><p>In this post, we will look at Cloud-Native Applications (CNA) and how they can help us to leverage the cloud’s inherent efficiency that arises through resource sharing and economies of scale. We will start with an overview of CNA and how a cloud deployment differs from a traditional one, especially w.r.t scalability in different cloud service models. Another interesting question we will discuss is whether pricing is a good proxy for sustainability. Risks and opportunities are covered as well.</p><h3>What is a Cloud-Native Application anyway?</h3><p>There is no single definition, unfortunately. <a href="https://www.infoworld.com/article/3281046/what-is-cloud-native-the-modern-way-to-develop-software.html">InfoWorld</a> describes it as an “approach to building and running applications that exploits the advantages of the cloud computing delivery model”. Many other definitions exist; when my colleague <a href="https://ozimmer.ch/">Olaf</a> and I asked this question ourselves a few years back, we analyzed <a href="https://ozimmer.ch/index/2021/05/21/CloudNativeDefinitionAnalysis.html">twelve CNA definitions</a>, only to come up with our own definition. We ended up with seven <em>traits</em> or characteristics of CNAs:</p><ol><li><em>Fit for Purpose:</em> Design each component to meet specific application requirements without unnecessary functionality.</li><li><em>Rightsized and Modular:</em> Structure applications into independently deployable, appropriately sized modules.</li><li><em>Sovereign and Tolerant:</em> Keep components in control of their dependencies and able to handle failures without cascading effects.</li><li><em>Resilient and Protected:</em> Design components to recover from disruptions and protect against threats.</li><li><em>Controllable and Adaptable:</em> Make components controllable from the outside and adaptable, with observability and runtime configuration.</li><li><em>Workload-Aware and Resource-Efficient:</em> Align resource usage with workload patterns and minimize unused capacity.</li><li><em>Agile and Tool-Supported:</em> Follow best practices and tools that support continuous integration and delivery.</li></ol><p><a href="https://ozimmer.ch/index/2021/08/20/CloudNativeDefinitionSynthesis.html">What is a Cloud-Native Application Anyway? From Analysis to Synthesis</a></p><p>For details and examples, please refer to the <a href="https://ozimmer.ch/index/2021/08/20/CloudNativeDefinitionSynthesis.html">blog post</a> above. Green software wasn’t on our mind when we did this analysis, but looking back now, there are several traits that have an effect on the greenness of our software: <em>Resource-Efficient</em> stands out, which we described as “CNAs should be frugal […] This includes being aware of cloud rental fees (e.g., CPU, local I/O, network usage) and then making sound decisions that balance cost and benefit w.r.t. functional and non-functional requirements.” To be resource-efficient, having applications that are <em>Fit for Purpose</em> and <em>Rightsized and Modular</em> are important prerequisites as well. Table 1 summarizes the positive and negative effects that Cloud-Native Applications traits can have on sustainability. Do you agree?</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*VxvdBwTb6zZIGqNIxyW4gw.png" /><figcaption><em>Table 1: Positive and negative effects that Cloud-Native Applications traits may have on sustainability.</em></figcaption></figure><h3>Rightsizing</h3><p>To deploy and run an application on a server, you either buy or rent one that provides enough resources (e.g., CPU, RAM, Disk) to run the application and to handle the expected workload. For many applications, though, the workload isn’t static; it might change with the time of day, seasons or special occasions (think Black Friday sales or Christmas shopping). The five <a href="https://www.cloudcomputingpatterns.org/cloud_computing_fundamentals/#application_workloads">Application Workload Patterns</a> Static Workload, Periodic Workload, Once-in-a-lifetime Workload, Unpredictable Workload, and Continuously Changing Workload capture different cloud workload scenarios nicely.</p><p>However, buying or renting a server often leads to under-utilization since you have to get a server that is able to handle peak loads (and often with some considerable safety margins to handle future growth). This over-provisioning leads to an under-utilization of resources on average: the allocated resources remain constant, but the application may not fully utilize them during periods of low demand — much to the dismay of my kids, it’s not Christmas every day! Now, you might say, the CPU uses less power when it’s idle, so what’s the big deal? You’re right if you’re only looking at runtime energy, but do you really want to buy hardware that will sit mostly idle until it’s replaced in 4–5 years? What about all the embodied emissions that went into the hardware? Another effect could be that, regardless of whether it is inefficient or not, you simply use all available resources because they are there.¹</p><p>So does the cloud solve this dichotomy of over-provisioning and under-utilization? Well, it depends. If you simply replace your local server with an equivalent virtual machine in the cloud (a so-called “lift and shift” migration), the problem isn’t solved magically. As the <a href="https://sysdig.com/blog/2023-cloud-native-security-usage-report/">Sysdig 2023 Cloud-Native Security and Usage Report</a> shows, shifting to the cloud isn’t enough. They found that “69% of requested CPU resources are unused” and that “for large deployments, optimizing an environment can save an average of $10 million on cloud consumption bills. On average, organizations of all sizes could be overspending by 40%.” Couldn’t the cloud providers take care of this, for example, by running virtual machines more efficiently? There are optimization techniques like <a href="https://en.wikipedia.org/wiki/Memory_ballooning">memory ballooning</a> that lets virtual machines “effectively give back unused pages of virtual memory” to the hypervisor. But as far as I know, they’re not easy to implement, and they don’t apply if your application is simply holding on to too much memory.</p><p>The promise of CNA is that we can automatically scale the application and thus adjust the underlying cloud resources based on demand. Additional resources can be allocated during periods of high demand to handle increased workload and scale back during periods of low demand, avoiding under-utilization. Sounds good? Let’s take a closer look.</p><h3>Scaling</h3><p>When we talk about scaling, there are two fundamental ways or directions to scale an application: <em>vertical scaling</em> and <em>horizontal scaling</em>. Vertical scaling means replacing the underlying machines with bigger (or smaller) boxes to scale up and down. The growing box in yellow on the left shows vertical scaling in the following figure:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Ps78ANvuq-O9cLUJn7CDiQ.png" /><figcaption><em>Figure 1: Scaling up versus scaling out.</em></figcaption></figure><p>Horizontal scaling is different: instead of replacing a machine with a larger or smaller one, additional instances are added. This scaling out approach has several benefits: while scaling up is at some point limited by the resources a single machine can offer, horizontal scalability is only limited by the total amount of resources available in the cloud (or by your credit card 😉). Figure 2 shows how a changing workload can be handled by scaling out.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*r0iUWDVVaQykYqYMFnca9A.png" /><figcaption>Figure 2: Multiple instances can handle changing workloads as needed. As the workload grows, more instances are added.</figcaption></figure><p>Multiple machines running in parallel also improve fault tolerance and reliability (<em>Resilient and Protected</em> is another CNA trait) of the overall system because these instances can run in different locations. A further benefit of distributed locations is that networks are less burdened if applications run close to users, saving energy and emissions on the networking side (see the work my colleagues are doing on <a href="https://www.ost.ch/en/research-and-consulting-services/computer-science/ins-institute-for-networks-and-security/research-projects/sustainable-networking">Sustainable Networking</a>).</p><p>Cloud providers want to pack as many of these “green” boxes shown in Figure 2 onto as few physical servers as possible, better utilizing existing hardware and lowering costs (for them). Of course, this doesn’t work just with public clouds: increasing utilization through virtualization on the hardware or operating system level (also known as “containers”) is also possible with private clouds and traditional server infrastructure.</p><p>Scalability is not just an application software issue; the underlying IT infrastructure including middleware, operating system and hardware (for computing, storage and networking) must be able to support more flexible applications. Parts of this infrastructure might be virtualized. Let’s take a closer look at what cloud providers have to offer.</p><h3>Cloud Service Models</h3><p>Cloud providers have large catalogs of offerings, from virtual machines, databases, middleware, to machine learning models that can be used as a service. When we focus on running applications (sometimes also called “compute”), there are several well-known service models. Infrastructure-as-a-Service (IaaS) offerings let you rent physical or virtual machines that run an operating system that is administered by the customer. In the Platform-as-a-Service (PaaS) model, the provider takes on this task and provides a predefined execution environment for applications, often supplemented by tailored databases and middleware offerings. Serverless computing goes even further and gets rid of (at least from the customer’s perspective) servers altogether. Applications are started and scaled on-demand without managing servers, so there are no idle instances hogging resources when the application is not in use.</p><p>Most cloud providers offer IaaS, PaaS and serverless. For example, Amazon Web Services has <a href="https://aws.amazon.com/ec2/?nc2=h_ql_prod_cp_ec2">EC2</a> (IaaS), <a href="https://aws.amazon.com/elasticbeanstalk/">Elastic Beanstalk</a> (PaaS), and <a href="https://aws.amazon.com/lambda/">Lambda</a> (serverless). Microsoft Azure has <a href="https://azure.microsoft.com/en-us/products/virtual-machines/windows/">Virtual Machines</a> (IaaS), <a href="https://azure.microsoft.com/en-us/products/app-service/">App Service</a> (PaaS), and <a href="https://azure.microsoft.com/en-us/products/functions/">Azure Functions</a> (serverless). Other providers are more focused, for example, <a href="https://www.heroku.com/platform/">Heroku</a> is a pure PaaS-Provider.</p><p>How can this make our software greener? Depending on the service, the “green boxes” we saw earlier tend to be larger or smaller. Scalability can be achieved with large IaaS offerings, but applications deployed on PaaS are quicker to react to changes in the workload, with serverless applications able to exactly match the workload. See Figure 3 for a visualization.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*-Uxx33UG-s4IBP_jr70KGg.png" /><figcaption><em>Figure 3: Cloud offerings differ in instance size and scalability. The figure shows a workload (grey line) that changes over time and service instances (virtual machines or deployment units, depending on the service) as green boxes. The parts of the green boxes that are over the line are effectively overprovisioned capacity. Looking at the different service models, IaaS instances tend to be larger and less flexible, while PaaS offers finer scaling but still works in fixed resource units. With serverless computing, we can reduce overprovisioned capacity to a minimum (assuming that cloud providers tightly pack all these functions onto as few servers as possible).</em></figcaption></figure><p>Different strategies can be applied to move an application to IaaS or PaaS, see <a href="https://medium.com/aws-enterprise-collection/6-strategies-for-migrating-applications-to-the-cloud-eb4e85c412b4">6 Strategies for Migrating Applications to the Cloud</a>. A transition to serverless might require more refactoring and re-architecting, depending on the current state of the application.</p><p>By the way, our <a href="https://interface-refactoring.github.io/">Interface Refactoring Catalog</a> offers a collection of API refactorings and related architectural refactorings, for example, to <a href="https://interface-refactoring.github.io/refactorings/segregatecommandsfromqueries">Segregate Commands from Queries</a>. We are currently working on refactorings to split application backends and frontends. Refactorings from the catalog can be applied when preparing to migrate to the cloud or after a migration, when attempting to find a suited balance/tradeoff regarding cost, efficiency and other desired qualities (such as performance and scalability).</p><h3>Pricing</h3><p>Efficiency is not only greener, it can also be cheaper. Another aspect of the different cloud service models that we haven’t touched on yet is pricing. Cloud costs scale with usage: compute hours, storage, data transfer. The cloud’s pay-per-use pricing model rewards efficient software and aligns well with sustainability goals, which is good news. Also, cost is something that all providers provide detailed reporting on. While costs might initially serve as a rough proxy for the much harder-to-estimate carbon emissions, this does not mean that cheaper is always better for the environment.</p><p>Despite the airy name, “clouds” are backed by earthly data centers, which might be in a region powered by abundant coal or gas. This means running your applications could lead to more carbon emissions despite lower cloud pricing. And unfortunately, most data centers aren’t green. According to the <a href="https://www.eesi.org/articles/view/data-center-energy-needs-are-upending-power-grids-and-threatening-the-climate">Environmental and Energy Study Institute</a> “about 56% of the electricity used to power data centers nationwide [in the US] comes from fossil fuels” and the <a href="https://www.iea.org/reports/energy-and-ai/energy-supply-for-ai">International Energy Agency</a> “new demand from data centres is a significant near-term driver of growth for natural gas-fired and coal-fired generation.”</p><p>So is cost a good proxy for sustainability (environmental, not economic)? Not necessarily. I’m sure there must be studies that look into this, but I couldn’t find any. If you want to do one, let’s join up!</p><h3>Risks</h3><p>Over the past few months, I’ve also seen an increasing amount of articles criticizing the major cloud providers (for example by <a href="https://www.theguardian.com/technology/2024/sep/15/data-center-gas-emissions-tech">the Guardian: Data center emissions probably 662% higher than big tech claims. Can it keep up the ruse?</a>, or <a href="https://www.techradar.com/pro/generative-ai-triples-the-carbon-dioxide-emissions-from-data-centers">Techradar: Generative AI is reportedly tripling carbon dioxide emissions from data centers</a>) and reports that providers are <a href="https://hbr.org/2024/08/companies-are-scaling-back-sustainability-pledges-heres-what-they-should-do-instead">missing and retreating from their sustainability pledges</a>. It’s worth noting that this doesn’t contradict the core of our analysis here. The huge growth in data centers is primarily being driven by investments in AI and not because we’re all re-engineering our applications to CNA and shifting these to the cloud.</p><p>Cloud-native principles allow us to better utilize computing resources, reducing waste and therefore making running our software greener. But that’s only part of the story. I see a risk that the infinite scalability of the cloud will make it even harder to detect inefficiently architected or written software. My dear colleague Olaf updated the Philippe Kruchten quote “The life of a software architect is a long and rapid succession of suboptimal design decisions taken partly in the dark.”² for our context:</p><blockquote>The life of a cloud application architect is a long, rapid, and frequently changing succession of suboptimal design decisions about concepts, technologies, and service offerings taken partly in the dark.</blockquote><p>Tradeoffs must be found between cost, energy efficiency, and other <a href="https://ozimmer.ch/practices/2020/09/24/ASRTestECSADecisions.html">architecturally significant requirements</a> in the architect’s business-as-usual.</p><p>It’s not just the <a href="https://markaicode.com/azure-cost-increase-2025/#real-horror-stories-companies-caught-by-surprise">headline-grabbing</a> <a href="https://www.reddit.com/r/AZURE/comments/1d2uoyc/comment/l635mx6/">horror-stories</a> or <a href="https://x.com/fredkschott/status/1631449132358598656?s=12&amp;t=O-BIPqQeV-xOttdxXTe5AA">$300 queries</a>, but also a risk of losing sight of efficiency due to the cloud’s huge range of available services and configurations, with complex interactions (for example, regarding <a href="https://www.duckbillgroup.com/understanding-data-transfer-in-aws/">data transfer pricing</a>). With nearly unlimited scaling and options, teams can easily overprovision or accidentally misuse services. Who hasn’t spun up some virtual machines and forgotten about them? So while the scalability of the cloud is definitely a strength, it can just as well hide inefficiencies.</p><h3>Opportunities</h3><p>The actual sustainability of a (cloud) deployment depends a lot on how the software is designed and where it runs. A well-designed application in a traditional data center may have a smaller footprint than a poorly optimized one in a green cloud.</p><p>We have seen that electricity cost is just one of several factors that influence cloud pricing, and while cost savings might go hand in hand with going green, they don’t have to. Cloud providers could also do more. For example, how about dynamic pricing of cloud resources depending on the carbon intensity of electricity, similar to how <a href="https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/using-spot-instances.html">AWS Spot Instances</a> react to demand?</p><p><a href="https://hackernoon.com/our-code-is-harming-the-planet-we-need-carbon-aware-design-patterns">Carbon-aware</a> and <a href="https://www.thegreenwebfoundation.org/news/introducing-our-grid-aware-websites-project/">grid-aware websites</a> are further interesting directions of research. They aim to dynamically adjust applications to the carbon intensity of the electricity in the grid. Cloud-native applications that scale down not just with user demand but also carbon intensity — with the consequence that a website might load slower or even shut down partially — could help us make our software greener.</p><h3>Conclusion</h3><p>Coming back to our initial question, are Cloud-Native Applications (CNAs) the answer to software sustainability? The answer is somewhere between the Betteridge-no and a cloud marketing-yes, it depends. CNA by themselves are not the answer, but they give us flexibility and options. What we should definitely do is both measure and optimize our applications and infrastructure to uncover wasted resources. And a nice side effect is that thanks to the pay-per-use pricing that many cloud resources offer, this might also lower your cloud bill.</p><p>This is also where the term FinOps (cloud) financial operations — comes in. Many of the same practices that reduce cloud bills, such as rightsizing, auto-scaling, turning off idle resources, also reduce energy use and emissions.</p><p>A future article will look into different tools to measure — or rather estimate — cloud carbon emissions.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/618/1*V5Za_XV_Iw-9ZoIF7_jesQ.png" /><figcaption><em>Figure 4: Cloud native applications can have both positive and negative impacts. Cloud service models enable scalability that can improve energy efficiency and reduce the environmental footprint of applications.</em></figcaption></figure><p><strong>Acknowledgements.</strong> A big thank you to <a href="https://ozimmer.ch/">Olaf Zimmermann</a> for his feedback and input on this post, as always it was very helpful!</p><h3>Further Reading</h3><p>Here are some additional resources and tools to help you learn more:</p><p>French cloud provider Scaleway has an <a href="https://www.scaleway.com/en/environmental-footprint-calculator/">Environmental Footprint Calculator</a> that gives you carbon and water metrics for their offerings. They also prominently display the eco-friendliness of their different data centers when creating a new compute instance.</p><p>A study on <a href="https://research.vu.nl/en/publications/software-driven-strategies-to-reduce-the-energy-footprint-of-data">Software-Driven Strategies to Reduce the Energy Footprint of Data Centers: A Systematic Literature Review</a> by Sophie Vos and colleagues identified “five main strategies to reduce the energy footprint, namely: VM consolidation, Resource management, Monitoring, Network optimization, and Container consolidation.”</p><p><a href="https://cloudcustodian.io/">Cloud Custodian</a> “allows users to define policies to enable a well managed cloud infrastructure, that’s both secure and cost optimized.” For example, you can define off-hours to shut down instances according to a schedule or automatically mark unused storage volumes for deletion.</p><p>In <a href="https://www.linkedin.com/pulse/what-does-green-data-centre-look-like-guy-massey-xfp4e/">What Does a Green Data Centre Look Like?</a>, Guy Massey gives a good overview of the core components of a green data center: Energy Efficiency &amp; Performance Optimization, Renewable Energy Integration, Sustainable Water &amp; Cooling Management, and Circular Economy &amp; Sustainable IT Hardware.</p><p>If you’re wondering why the current generative AI hype is problematic, I highly recommend <a href="https://wimvanderbauwhede.codeberg.page/articles/the-real-problem-with-AI/">this article</a> by Wim Vanderbauwhede. The Green Web Foundation also has a great <a href="https://www.thegreenwebfoundation.org/publications/report-ai-environmental-impact/">Thinking about using AI?</a> report.</p><h4>Footnotes</h4><ol><li>Is there a name for this effect? It seems similar to Parkinson’s Law that “work expands so as to fill the time available for its completion” but for resources instead of time.</li><li>From <a href="https://dokumen.pub/the-process-of-software-architecting-0321357485-9780321357489.html">The Process of Software Architecting</a> by Peter Eeeles and Peter Cripps. Also see <a href="https://www.youtube.com/watch?v=sSW3GpzY57E">“Controlling Your Architecture with Philippe Kruchten”</a> in the Azure DevOps Podcast.</li></ol><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=42e16b33bc76" width="1" height="1" alt=""><hr><p><a href="https://medium.com/growing-green-software/are-cloud-native-applications-the-answer-to-software-sustainability-42e16b33bc76">Are Cloud-Native Applications the Answer to Software Sustainability?</a> was originally published in <a href="https://medium.com/growing-green-software">Growing Green Software</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Comparing Java Virtual Machine Energy Efficiency]]></title>
            <link>https://medium.com/growing-green-software/comparing-java-virtual-machine-energy-efficiency-e2e8658539b8?source=rss-ff9700c896a8------2</link>
            <guid isPermaLink="false">https://medium.com/p/e2e8658539b8</guid>
            <category><![CDATA[green-software]]></category>
            <category><![CDATA[spring-boot]]></category>
            <category><![CDATA[energy-consumption]]></category>
            <category><![CDATA[java]]></category>
            <category><![CDATA[jvm]]></category>
            <dc:creator><![CDATA[Mirko Stocker]]></dc:creator>
            <pubDate>Mon, 23 Dec 2024 12:14:12 GMT</pubDate>
            <atom:updated>2024-12-23T12:14:12.569Z</atom:updated>
            <content:encoded><![CDATA[<p>Does the Java Virtual Machine (JVM) version affect energy consumption? As the JVM executes the byte code from the Java compiler, its efficiency could play a role and change between JVM versions, for better or worse. In the <a href="https://medium.com/growing-green-software/evolution-of-energy-usage-in-spring-boot-69c7c372dba3">previous post</a>, we looked at the energy consumption of different Spring Boot versions. We created a JMeter benchmark that simulates interactions with the Spring Boot Petclinic API and measured the energy consumption using JoularJX. We found that they vary between different Spring Boot versions. In this post, we will continue our investigation and compare the energy consumption of different JVM versions.</p><h3>Java Versions and JVMs</h3><p>What do we actually mean when we talk about Java and JVM versions? When we compile Java source code, the compiler generates byte code of a specific version for the JVM to execute. So, both the generated code and the JVM have a version. To run the code, these versions don’t have to match exactly. For example, you can run byte code compiled with a Java 11 compiler on a Java 17 JVM. The following (simplified, as we will see in a moment) diagram illustrates this:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/698/1*pg2AGTXveXg5vFL2BwCoPA.png" /></figure><p>So the JVM is backwards compatible.¹ If you want to dig deeper into the different kinds of compatibilities (there’s also the concepts of source and serialization compatibility) and guarantees, see the <a href="https://cr.openjdk.org/~darcy/OpenJdkDevGuide/OpenJdkDevelopersGuide.v0.777.html#compatibility">OpenJDK Developers’ Guide</a>.</p><p>There are <a href="https://www.baeldung.com/maven-java-version">different ways to set the Java version</a>. In the Spring Petclinic project we use the java.version property in the pom.xml file, which will then be used by Spring Boot to configure the Maven compiler plugin. So to set the Java version to 17, we can run the following command (on Windows, use mvnw.cmd):</p><pre>$ ./mvnw versions:set-property \<br>  -Dproperty=java.version \<br>  -DnewVersion=17 \<br>  -DgenerateBackupPoms=false</pre><p>To switch between JVMs, we can use the <a href="https://sdkman.io/">SDKMAN!</a> tool. For example, to switch to the Eclipse Temurin 17 JVM, we can run:</p><pre>$ sdk use java 17.0.12-tem</pre><p>Wait a minute, what is Eclipse doing here and what is a “Temurin”? It’s not an exotic fruit, but a distribution of OpenJDK², which is the reference implementation of the Java platform (so the above picture is actually more complex because “the JVM” doesn’t really exist). There actually is a surprisingly large number of <a href="https://en.wikipedia.org/wiki/OpenJDK#OpenJDK_builds">OpenJDK distributions</a>. These distributions mainly differ in the platform they support, the update policy, and additional features they provide. For example, when I first got my M1 MacBook, I had to use the Azul Zulu distribution because it was one of the first to support the Apple Silicon architecture. This is another aspect that we could investigate in the future: how do different Java distributions compare in terms of energy consumption? In this post, we will stick to different Temurin versions.</p><h3>Comparing JVM Versions</h3><p>Since we already have the possibility to run the benchmark with different Spring Boot versions, we can now also run it with different JVM versions. I ran the benchmark with the following JVM versions: 17, 21, and 22. Versions 17 and 21 offer long-term support (LTS), while version 22 was the latest release supported by Spring Boot at the time I wrote this.³ The results are shown in Figure 1.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/987/1*tUsPXz_Y1p7hYauJY7OgEw.png" /></figure><p><em>Figure 1: Evolution of energy consumption of different JVM versions. Measured with our Petclinic benchmark and Spring Boot 3.3.1.</em></p><p>Isn’t that wonderful, newer versions of the JVM use significantly less energy! Figure 1 only shows the results for a single Spring Boot version, but the same trend can be observed for the other versions as well.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/987/1*k2qTIn-GYJyfyKK9ZGl6vA.png" /></figure><p><em>Figure 2: Evolution of energy consumption of different JVM versions and Spring Boot versions 3.0–3.3.</em></p><p>Keen readers of this blog will notice that, compared to the previous blog post, we didn’t include version 2.7 of Spring Boot in the benchmark. The reason is simply that it doesn’t run on Java 22, so we dropped it for this benchmark.</p><p>Somewhat puzzling is the jump in energy consumption between Spring Boot 3.0 and 3.1. If you have any ideas where that comes from, please let me know!</p><h3>Conclusion</h3><p>In this post, we compared the energy consumption of different JVM versions. We found that newer versions of the JVM use less energy, so one learning is that it’s a good idea to keep your JVM up-to-date.</p><p>What’s next? I hope I’m not boring you with all these benchmarks, but I have at least one more planned. Spring Boot comes with different <a href="https://docs.spring.io/spring-boot/how-to/webserver.html">embedded web servers</a> (Tomcat, Jetty, and Undertow), with Tomcat being the default. Does the choice of web server have an impact on the energy consumption? Stay tuned to find out!</p><h3>Resources</h3><p>The benchmarking scripts can be found in a separate <a href="https://github.com/misto/spring-petclinic-energy-benchmarking">GitHub repository</a>. Please refer to the blog post on <a href="https://medium.com/growing-green-software/evolution-of-energy-usage-in-spring-boot-69c7c372dba3">Evolution of Energy Usage in Spring Boot</a> for more details on the benchmark and the setup. Also see this post on <a href="https://medium.com/growing-green-software/measuring-java-energy-consumption-987654efdabb">Measuring Java Energy Consumption</a> that explains the usage of JoularJX.</p><ol><li>That’s actually not entirely true; breaking changes sometimes occur, but in my experience, Java is among the most stable platforms with which I&#39;ve worked in terms of compatibility. For example, deprecated methods can be removed, but this is rare and usually well-documented and announced in advance. For example, here’s a <a href="https://docs.oracle.com/en/java/javase/23/migrate/removed-apis.html">list of removed APIs</a>. In our book <a href="https://api-patterns.org/book/">Patterns for API Design</a>, we have a whole chapter on patterns for remote <a href="https://api-patterns.org/patterns/evolution/">API evolution</a>.</li><li>“Temurin” is just an <a href="https://github.com/adoptium/adoptium.net/issues/2237">anagram of runtime</a>. But according to ChatGPT, it is “derived from the Japanese word ‘Te-muri,’ which means ‘hand smoke’ or ‘hand vapor.’” And Co-Pilot claims that it means “iron” in Mongolian. 🤷‍♂️</li><li>Between running the experiments and writing this blog post, Spring Boot 3.4 has been released and supports Java 23.</li></ol><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=e2e8658539b8" width="1" height="1" alt=""><hr><p><a href="https://medium.com/growing-green-software/comparing-java-virtual-machine-energy-efficiency-e2e8658539b8">Comparing Java Virtual Machine Energy Efficiency</a> was originally published in <a href="https://medium.com/growing-green-software">Growing Green Software</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Evolution of Energy Usage in Spring Boot]]></title>
            <link>https://medium.com/growing-green-software/evolution-of-energy-usage-in-spring-boot-69c7c372dba3?source=rss-ff9700c896a8------2</link>
            <guid isPermaLink="false">https://medium.com/p/69c7c372dba3</guid>
            <category><![CDATA[spring-boot]]></category>
            <category><![CDATA[jmeter]]></category>
            <category><![CDATA[api]]></category>
            <category><![CDATA[energy-measurement]]></category>
            <category><![CDATA[green-software]]></category>
            <dc:creator><![CDATA[Mirko Stocker]]></dc:creator>
            <pubDate>Fri, 08 Nov 2024 13:38:01 GMT</pubDate>
            <atom:updated>2024-11-11T10:54:42.104Z</atom:updated>
            <content:encoded><![CDATA[<p>In the previous post on <a href="https://medium.com/growing-green-software/measuring-java-energy-consumption-987654efdabb">Measuring Java Energy Consumption</a>, we looked at the JoularJX tool to measure the energy consumption of Java programs at the method level. We used the Java Microbenchmark Harness (JMH) to contrast the runtime performance of different Java data structures and their energy consumption. In this post, we will switch from JMH to the <a href="https://jmeter.apache.org/">Apache JMeter</a> performance testing tool and combine it with the energy measurements from JoularJX. Our system under test is also different; instead of Java collections, we will use the <a href="https://spring-petclinic.github.io/">Spring Petclinic</a> application, specifically the <a href="https://github.com/spring-petclinic/spring-petclinic-rest">REST version</a> that provides an HTTP Web API.</p><p>Read on to learn how to set up the benchmark, run it, and compare the energy consumption of different Spring Boot versions and individual API operations.</p><h3>Apache JMeter</h3><p>JMeter is a Java-based tool that can be used to load-test and measure the performance of applications. It supports many different protocols; we will use the <a href="https://jmeter.apache.org/usermanual/component_reference.html#HTTP_Request">HTTP Request feature</a> to interact with the Petclinic Web API. What I like about JMeter is that its GUI makes it easy to create test suites, run them, and inspect the results, which is great during development and debugging. It also has a command-line mode that we will later use for automated testing. To learn more about JMeter, I recommend this <a href="https://www.baeldung.com/jmeter">Intro to Performance Testing using JMeter</a>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*b38K2uWtP7yXAP_WZim8bw.png" /></figure><p><em>Figure 1: The JMeter GUI application with a test plan (the series of steps that JMeter will execute) for the Petclinic API.</em></p><h3>Spring Petclinic Application and JMeter Benchmark Setup</h3><p>Spring Petclinic is a sample application that demonstrates the use of the Spring Framework. It is a CRUD (Create, Read, Update, Delete) application that manages veterinarians, owners, pets, and their interactions, implemented with Spring Boot. The version we are using does not come with a frontend application (there are other versions that do, check out the <a href="https://github.com/spring-petclinic">GitHub organization</a>), but instead provides an HTTP API that we can use to interact with the system. An advantage of the API is that we can easily use it with benchmarking tools that simulate user interactions and measure the performance of the application. Petclinic supports multiple databases and different ways to access database content: <a href="https://docs.oracle.com/javase/8/docs/technotes/guides/jdbc/">JDBC</a>, <a href="https://www.oracle.com/java/technologies/persistence-jsp.html">JPA</a>, and <a href="https://spring.io/projects/spring-data-jpa">Spring Data JPA</a>.</p><p>In our benchmark, we will use GET, POST, PUT, and DELETE requests to interact with the Petclinic API. We will simulate user interactions by creating new owners, adding pets, and updating their information. In total, the benchmark comprises 5500 GET requests and 6000 POST, PUT, and DELETE requests to different operations and resources (Owners, Pets, Visits, etc.) of the API.¹</p><p>The Petclinic application comes with an in-memory database that is populated with a small amount of <a href="https://github.com/spring-petclinic/spring-petclinic-rest/blob/master/src/main/resources/db/hsqldb/data.sql">sample data</a>. To make the benchmark more realistic, we need more data. Luckily for us, Markus Harrer already did this work and shared the script in his blog post <a href="https://www.feststelltaste.de/generate-fake-data-for-spring-petclinic-with-pandas-and-faker/">Generate fake data for Spring PetClinic with Pandas and Faker</a>. I was able to reuse his setup to generate 1000 owners, each with 2 pets, and 100 veterinarians providing care for these pets. This data will be loaded into a fresh database before running the benchmark. We are also going to use a MySQL database instead of the in-memory one. Since the MySQL database runs in a different process, it won’t directly influence the energy consumption of the Petclinic application.</p><p>The entire benchmark consists of the following steps (note that I’ve shortened the file paths and omitted some output for brevity,² I’m running these on macOS, but they should work on other UNIX-based systems as well):</p><p><strong>Prepare the environment.</strong> We must have Java and Docker installed on our system. I’m using <a href="https://sdkman.io/">SDKMAN!</a> tool (UNIX-based platforms only) to manage the different Java versions on my system. We’ll use Java 17 for the benchmark, specifically the Eclipse Temurin distribution of OpenJDK.³</p><pre>$ sdk use java 17.0.12-tem<br>Using java version 17.0.12-tem in this shell.</pre><p><strong>Clone the Spring Petclinic REST repository. </strong>I had to fork the repository to fix <a href="https://github.com/spring-petclinic/spring-petclinic-rest/pull/172">some issues</a>. Once the pull request is merged, you can use the original repository. <em>(Update 11.11.24: The changes have been merged; you should now be able to use the vanilla </em><a href="https://github.com/spring-petclinic/spring-petclinic-rest"><em>https://github.com/spring-petclinic/spring-petclinic-rest</em></a><em>.)</em></p><pre>$ git clone https://github.com/misto/spring-petclinic-rest.git<br>$ cd spring-petclinic-rest</pre><p><strong>Build the application.</strong> This will result in a JAR file in the target folder that we can then run.</p><pre>$ ./mvnw clean package<br>$ ls target/*.jar<br>target/spring-petclinic-rest-3.2.1.jar</pre><p><strong>Prepare the database.</strong> We will start a MySQL database in a Docker container and load the benchmark data into it (the long number is the randomly generated container ID).</p><pre>$ docker run -d --rm \<br>  -e MYSQL_ROOT_PASSWORD=petclinic \<br>  -e MYSQL_DATABASE=petclinic \<br>  -p 3306:3306 mysql:8<br>81004fa973889e64405997043761fd6410a3ee67a6e9b14f7b4e57fc794473ed<br>$ docker exec -i 81004fa973889e64405997043761fd6410a3ee67a6e9b14f7b4e57fc794473ed \<br>  mysql -u root -ppetclinic petclinic &lt; benchmark-ddl-and-data.sql</pre><p><strong>Start the Petclinic application.</strong> Several parameters must be set to run the application: the JoularJX agent, the JoularJX configuration file⁴ and the active Spring profiles. We also disable the SQL initialization since we already prepared the database in the previous step and don’t want it to get overwritten.</p><pre>$ java \<br>  -javaagent:/path/to/joularjx-3.0.0.jar \<br>  -Djoularjx.config=/path/to/config.properties \<br>  -Dspring.sql.init.mode=never \<br>  -Dspring.profiles.active=mysql,jpa \<br>  -jar target/*.jar &gt; /path/to/application.log 2&gt;&amp;1 &amp;<br>[1] 27645</pre><p>Note that we redirect the output of the application (including standard error 2&gt;&amp;1) to a file. The &amp; at the end of the command puts the application into the background. This is important because we will use the same terminal to run the JMeter benchmark, and we want to keep the application running in the background. The 27645 is the process ID of the application, which we can use to stop it once we&#39;re done.</p><p><strong>Run the JMeter benchmark.</strong> The jmeter-petclinic-server.jmx file contains the test plan that we showed earlier in the JMeter GUI. We will run the benchmark in non-GUI mode and save the results to a file. From the log, we can then extract the time it took to run the benchmark.</p><pre>$ jmeter -n \<br>  -t /path/to/jmeter-petclinic-server.jmx \<br>  -l /path/to/results-file.jtl \<br>  -j /path/to/jmeter.log<br>$ tail -n 1 /path/to/jmeter.log<br>2024-10-03 13:50:19,571 INFO o.a.j.r.Summariser: summary =  11500 in 00:05:18 =   36.1/s Avg:   137 Min:     1 Max:  2529 Err:     0 (0.00%)</pre><p><strong>Analyze the results.</strong> The benchmark ran for 5 minutes and 18 seconds and executed 11500 requests. Now we can stop the Petclinic application: We use the process ID we saved earlier to send a SIGTERM signal to the application with kill -s TERM. The -s TERM parameter and SIGTERM signal allow the application to shut down gracefully. If we kill it more forcefully, JoularJX will not be able to reliably write the energy measurements to the file (which I learned the hard way).</p><pre>$ kill -s TERM 27645</pre><p>From the log file of the Petclinic application, we can extract the energy consumption⁵ of the benchmark.</p><pre>$ grep joules /path/to/application.log<br>03/10/2024 01:50:20.998 - [INFO] - Program consumed 1308.75 joules</pre><p>As we saw in the <a href="https://medium.com/growing-green-software/measuring-java-energy-consumption-987654efdabb">previous post</a>, JoularJX also writes per-method energy measurements to a file. Because each API operation corresponds to a unique method in the Petclinic application, we now have the energy consumption of each operation. For example, we can see that the PetRestController.listPets operation consumed 171.7327 joules:</p><pre>$ grep listPets joularjx-result/joularJX-24240-filtered-methods-energy.csv<br>org.springframework.samples.petclinic.rest.controller.PetRestController.listPets,171.7327</pre><p>To run this benchmark multiple times with different configurations, we better automate the process. I wrote a shell script that performs all these steps, including error checking and results extraction. We’re not going to go into all the details of the script here (it has almost 400 lines with various configuration options). You can find it in the <a href="https://github.com/misto/spring-petclinic-energy-benchmarking">GitHub repository</a>.</p><p>Now that we have the basics set up, what can we do with it? We could start tinkering with the Petclinic application, changing the Spring Boot version, the Java version (or even different JVM versions), the database, or the data access layer (which is JPA at present; maybe plain JDBC or <a href="https://www.jooq.org/">jOOQ</a> would be more efficient?).</p><h3>Comparing Spring Boot Versions</h3><p>I like Spring because it is a very active project with <a href="https://mvnrepository.com/artifact/org.springframework.boot/spring-boot-starter-parent">regular releases</a> where compatibility is a high priority. This means that one can usually upgrade to a newer version without much hassle. To change the Spring Boot version of the Petclinic application, we can use the Maven versions plugin. For example, to upgrade to Spring Boot 3.3.2, we can run the following command:</p><pre>$ ./mvnw versions:update-parent \<br>  -DparentVersion=[3.3.2] \<br>  -DgenerateBackupPoms=false</pre><p>Without further changes to the code, we can now run the benchmark with Spring Boot versions 3.0 to 3.3 and compare the results. I also tried to go back to Spring 2, and was able to get the application running with Spring Boot 2.7 with only <a href="https://github.com/misto/spring-petclinic-rest/commit/25ea15fbfbb8a78fc1b818b53b7eaf6ac529ea10">minor code changes</a>. We must also keep the JVM version in mind, as newer Spring Boot versions might require newer Java versions.⁶</p><p>Running the benchmark five times for each version produces the results shown in Figure 2. The box plots show the energy consumption in joules for each version of Spring Boot tested. Box plots are a standardized way of displaying data distribution based on a five-number summary: minimum, first quartile, median, third quartile, and maximum. The box represents the <em>interquartile range (IQR)</em>, the middle 50% of the data. The whiskers at the top and at the bottom of the plot extend to the minimum and maximum values, excluding outliers. Outliers are shown as circles (like the one on the lower left). I like to overlay box plots with a plot of the individual data points to get a better sense of the distribution, or in this case, with just five data points to see what the box plot elements represent (I also added a table showing the data points for each version, but that’s mostly for myself to ensure I got all the measurements I want).</p><p>We can see that the switch from version 2.7 to 3.0 results in a slight decrease in energy consumption, but from version 3.0 to 3.3, the energy consumption increases again.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/980/1*Uvxjcs9Wu6KIJDO2rGWHMg.png" /></figure><p><em>Figure 2: The evolution of energy consumption over different Spring Boot versions.</em></p><p>Now, before you start downgrading your Spring Boot version to save energy, keep in mind that this is just one benchmark with one application. We could look at the code changes between the versions, the dependencies that were updated, and the changes in the Spring Boot framework itself. It could be that the newer versions are more efficient in some areas but less so in others. Maybe newer versions are more feature-rich or secure, which comes at the cost of higher energy consumption. It could also be that the benchmark is not representative, or the energy measurements are inaccurate. Also, the Spring Petclinic application is quite small and doesn’t have any real business logic or application state. We would need to run more benchmarks, analyze the code, and profile the application to understand better what’s going on.</p><p>Remember that we used JMeter to run the benchmark? What if we didn’t just look at the energy consumption but also at the runtime performance of the application? The results are shown in Figure 3. Interestingly, we can see a similar trend for the 3.x versions, whereas Spring Boot 2.7 was quite a bit slower. Also note the outlier in version 3.0.13, which was caused by my system going to sleep while I was getting coffee 😅 I decided to leave it in because it nicely shows when runtime and energy measurements can vary.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/980/1*vMR_QZX3UhamfeKqi335Qw.png" /></figure><p><em>Figure 3: The evolution of JMeter runtime over different Spring Boot versions.</em></p><p>Again, before drawing conclusions, we would have to further analyze this and also run more iterations.</p><h3>API Operation-Level Energy Consumption</h3><p>Up to now, we only considered the total energy consumption of the benchmark. But the strength of JoularJX is that it provides per-method energy measurements. In Spring Boot, each operation of the API corresponds to a method in the code. For example, the listPets retrieval operation is declared in the PetsApi interface and implemented in the PetRestController class:</p><pre>public interface PetsApi {<br>    ...<br>    @RequestMapping(<br>        method = RequestMethod.GET,<br>        value = &quot;/pets&quot;,<br>        produces = { &quot;application/json&quot; }<br>    )<br>    default ResponseEntity&lt;List&lt;PetDto&gt;&gt; listPets() {<br>        ...<br>}<br><br>@RestController<br>@RequestMapping(&quot;api&quot;)<br>public class PetRestController implements PetsApi {<br>    ...<br>    public ResponseEntity&lt;List&lt;PetDto&gt;&gt; listPets() {<br>        List&lt;PetDto&gt; pets = new ArrayList&lt;&gt;(petMapper.toPetsDto(this.clinicService.findAllPets()));<br>        if (pets.isEmpty()) {<br>            return new ResponseEntity&lt;&gt;(HttpStatus.NOT_FOUND);<br>        }<br>        return new ResponseEntity&lt;&gt;(pets, HttpStatus.OK);<br>    }<br>...</pre><p>This method is called when the /api/pets operation receives a GET request. In case you&#39;re wondering why there&#39;s a separation into interface and (singular) implementation class: The interface is generated automatically during compilation by the <a href="https://openapi-generator.tech/">OpenAPI Generator</a> from the Petclinic <a href="https://github.com/spring-petclinic/spring-petclinic-rest/blob/master/src/main/resources/openapi.yml">openapi.yml</a> <a href="https://api-patterns.org/patterns/foundation/APIDescription">API Description</a>.</p><p>As we saw earlier, this method consumed 171.7327 joules. Taking the measurements from our benchmarks, we can now compare the energy consumption of each operation. The results are shown in Figure 4 and includes not just listPets but also listOwners and listVisits.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*yxsisISX1HECxlbKmZNf0g.png" /></figure><p><em>Figure 4: The energy consumption of retrieval operations over different Spring Boot versions.</em></p><p>Surprisingly, these results differ from the trend in the total energy consumption. While the listVisits operation shows a similar trend, the listOwners and listPets operations show a different pattern. Keep in mind that JoularJX doesn&#39;t measure all the framework code that is executed before the listPets method is called, like the marshalling and unmarshalling of the ResponseEntity&lt;List&lt;PetDto&gt;&gt; payload. Maybe something changed there between the versions? Unfortunately, I don&#39;t have the answer to that question. If you do, please let me know in the comments!</p><p>What about the other operations? In Figure 4, we only saw retrieval operations, but there’s also the creation of new owners, pets, and visits, as well as updating their information. The results are shown in Figure 5. At first glance, it seems that the oldest version is the most efficient in many operations, but before you start squinting your eyes and trying to read too much into it these results, compare the scales of the y-axis of the plots. Compared to the retrieval operations, the energy consumption of the other operations is orders of magnitude lower because they operate on a single entity and don’t have to fetch nearly as much data from the database as the list operations.⁷</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*5a0TQAONINx71kvEf5ZI2g.png" /></figure><p><em>Figure 5: The energy consumption of add, delete, and update operations.</em></p><h3>Conclusion</h3><p>There are many more things that we could do with this setup, and I have some ideas for a follow-up post. Let me know if you want to team up to research this further together!</p><p>In this post, we learned that:</p><blockquote><em>JMeter is a performance testing tool that can be used to simulate interactions with a remote API (e.g., an HTTP Web API) and measure its performance.</em></blockquote><p>We also saw that:</p><blockquote><em>Combining JMeter and JoularJX provides insights into performance as well as energy consumption, which have a correlation but are not the same.</em></blockquote><p>Analyzing the energy consumption of a Spring Boot application, we found that:</p><blockquote><em>The energy consumption of a Spring Boot application can vary between different framework versions, and it’s worth investigating the energy consumption trends of individual operations.</em></blockquote><p>In a follow-up post, we will look at the energy consumption of different Java Virtual Machines and how they affect the energy consumption of the Petclinic application. Stay tuned!</p><p><strong>Acknowledgements.</strong> Thanks to <a href="https://ozimmer.ch/">Olaf Zimmermann</a> and <a href="https://stefan.kapferer.ch/about/">Stefan Kapferer</a> for their feedback on this post, as always it was very helpful!</p><h3>Resources</h3><p>The scripts, including the JMeter test plan and JoularJX config can be found in a separate <a href="https://github.com/misto/spring-petclinic-energy-benchmarking">GitHub repository</a>.</p><p>In previous posts, we talked about <a href="https://medium.com/growing-green-software/why-green-software-matters-b2f6789a82d2">Why Green Software Matters</a>, <a href="https://medium.com/growing-green-software/software-efficiency-and-energy-consumption-916b390593ec">Software Efficiency and Energy Consumption</a>, <a href="https://medium.com/growing-green-software/carbon-emissions-in-ict-99a0d421bbb6">Carbon Emissions in ICT</a>, and <a href="https://medium.com/growing-green-software/measuring-java-energy-consumption-987654efdabb">Measuring Java Energy Consumption</a>.</p><h3>Footnotes</h3><ol><li>In case you’re wondering how we came up with exactly these numbers of requests: we developed a simple test plan that issues a series of requests and run it 500 times.</li><li>The extended scripts can be found in the <a href="https://github.com/misto/spring-petclinic-energy-benchmarking">GitHub repository</a>.</li><li>In case you’re wondering how the Java version influences the energy consumption of the application: this will be the topic of the next post 😉</li><li>I had to create a <a href="https://github.com/joular/joularjx/pull/75">pull request</a> to the JoularJX repository to set the path to the configuration file via an environment variable. It was merged quickly, but isn’t part of the latest release yet.</li><li>See this <a href="https://medium.com/growing-green-software/software-efficiency-and-energy-consumption-916b390593ec">previous post</a> for a refresher on energy consumption of software.</li><li>I like to use the <a href="https://endoflife.date/spring-boot">endoflife.date</a> website to see which Java versions are supported by which Spring versions. The site covers dozens of frameworks, programming languages, and applications, not just Java.</li><li>The Spring Petclinic application does not use <a href="https://api-patterns.org/patterns/quality/dataTransferParsimony/Pagination">pagination</a> for the retrieval operations, so all data is fetched at once.</li></ol><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=69c7c372dba3" width="1" height="1" alt=""><hr><p><a href="https://medium.com/growing-green-software/evolution-of-energy-usage-in-spring-boot-69c7c372dba3">Evolution of Energy Usage in Spring Boot</a> was originally published in <a href="https://medium.com/growing-green-software">Growing Green Software</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Pattern-oriented API Refactoring]]></title>
            <link>https://medium.com/olzzio/pattern-oriented-api-refactoring-51cffa5a054d?source=rss-ff9700c896a8------2</link>
            <guid isPermaLink="false">https://medium.com/p/51cffa5a054d</guid>
            <category><![CDATA[software-architecture]]></category>
            <category><![CDATA[microservices]]></category>
            <category><![CDATA[api]]></category>
            <category><![CDATA[refactoring]]></category>
            <category><![CDATA[api-design]]></category>
            <dc:creator><![CDATA[Mirko Stocker]]></dc:creator>
            <pubDate>Mon, 04 Nov 2024 13:44:08 GMT</pubDate>
            <atom:updated>2024-11-04T13:44:08.080Z</atom:updated>
            <content:encoded><![CDATA[<h4>Addressing Design Smells and Stakeholder Concerns</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*O0cig7NHp5Ul-GwBSB2sBw.png" /><figcaption>An overview of all the interface refactorings available in our catalog.</figcaption></figure><p>In our latest paper from this year’s <a href="https://www.europlop.net/conference/">EuroPLoP</a> conference, we continue our work on refactoring application programming interfaces (APIs) in distributed systems. As architectural components like single-page applications and microservices rely on APIs for communication, ensuring interoperability and high quality becomes paramount. Our work builds on <a href="https://medium.com/olzzio/return-to-europlop-api-refactoring-patterns-217787f90930">previous research on API refactoring</a>, presenting a new set of seven refactorings from our <a href="https://interface-refactoring.github.io/">Interface Refactoring Catalog</a>. The refactorings we present target <a href="https://api-patterns.org/">API design patterns</a> and aim to address common design smells while meeting stakeholder concerns. The seven API refactorings are:</p><ul><li><a href="https://interface-refactoring.github.io/refactorings/extractinformationholder">Extract Information Holder</a></li><li><a href="https://interface-refactoring.github.io/refactorings/inlineinformationholder">Inline Information Holder</a></li><li><a href="https://interface-refactoring.github.io/refactorings/extractoperation">Extract Operation</a></li><li><a href="https://interface-refactoring.github.io/refactorings/renameoperation">Rename Operation</a></li><li><a href="https://interface-refactoring.github.io/refactorings/makerequestconditional">Make Request Conditional</a></li><li><a href="https://interface-refactoring.github.io/refactorings/encapsulatecontextrepresentation">Encapsulate Context Representation</a></li><li><a href="https://interface-refactoring.github.io/refactorings/introduceversionidentifier">Introduce Version Identifier</a></li></ul><p>Our approach combines the principles of refactoring with established API design patterns, providing developers with structured methods to improve API design and maintainability. Each refactoring has context, motivation, and step-by-step solutions, illustrated through implementation code snippets, API specification excerpts, and runtime message examples.</p><p>Let’s take a closer look at one refactoring:</p><h3>Refactoring: Make Request Conditional</h3><h4>Context and Motivation</h4><p>An API endpoint provides data that changes rarely, and thus, some clients request and receive the same data frequently. Preparing and retransmitting data already available to the clients is unnecessary and wasteful.</p><blockquote>As an API provider, I want to be able to tell clients that they already have the most recent version of certain data so that I do not have to send this data again.</blockquote><h4>Stakeholder Concerns</h4><ul><li><a href="https://interface-refactoring.github.io/refactorings/by-stakeholder-concerns/#performance">#performance</a>, <a href="https://interface-refactoring.github.io/refactorings/by-stakeholder-concerns/#green-software">#green-software</a> Response, throughput, and processing times concern API clients and providers. Unused data that is prepared, transported, and processed wastes resources, which should be avoided.</li><li><a href="https://interface-refactoring.github.io/refactorings/by-stakeholder-concerns/#data-access-characteristics">#data-access-characteristics</a> API clients might use caching and do not want to retrieve data they already have.</li><li><a href="https://interface-refactoring.github.io/refactorings/by-stakeholder-concerns/#developer-experience">#developer-experience</a>, <a href="https://interface-refactoring.github.io/refactorings/by-stakeholder-concerns/#simplicity">#simplicity</a> Knowing when and how long to cache which data might be challenging for API clients and providers. Permanent or temporary storage is required. These valid concerns have to be balanced with the desire for performance.</li></ul><h4>Initial Position Sketch</h4><p>Figure 1 shows the initial position sketch for this refactoring. The client requests some data from the API. Later, the client wants to ensure that the data is still up to date and sends a second request for the same data.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*5ok-LkP9w64pYQVn.png" /><figcaption>Figure 1: Make Request Conditional: Initial Solution Sketch: In the first message exchange (1–2), the endpoint returns one or more <a href="https://api-patterns.org/patterns/structure/elementStereotypes/DataElement">Data Elements</a>. Later on (3), the client requests the data from the endpoint again. Because nothing has changed, the provider returns the same data (4) as in the previous response.</figcaption></figure><p>This refactoring targets a single API operation and its request and response messages.</p><h4>Design Smells</h4><ul><li><a href="https://interface-refactoring.github.io/refactorings/by-smells-drivers#high-latency-poor-response-time"><em>High latency/poor response time</em></a> Load on the API provider is unnecessarily high because the same data is processed and transferred many times over.</li><li><a href="https://interface-refactoring.github.io/refactorings/by-smells-drivers#spike-load"><em>Spike load</em></a> Regular requests for large amounts of data can cause Periodic Workload or Unpredictable Workload [<a href="https://interface-refactoring.github.io/refactorings/makerequestconditional#ref-Fehling:2014">Fehling et al. 2014</a>] for CPU and memory, for instance, when a relatively large JSON object representing the requested data has to be constructed (on the provider side) and read (on the client side).</li><li><a href="https://interface-refactoring.github.io/refactorings/by-smells-drivers#polling-proliferation"><em>Polling proliferation</em></a> Clients that participate in long-running conversations and API call orchestrations ping the server for the current status of processing (“are you done?”). They do so more often than the provider-side state advances.</li></ul><h4>Instructions</h4><p>Instead of transmitting the same data repeatedly, the request can be conditional. Condition information is exchanged as metadata to allow the communication participants to determine whether the client already has the latest data version.</p><p>See the website for <a href="https://interface-refactoring.github.io/refactorings/makerequestconditional#instructions">detailed step-by-step instructions</a>.</p><h4>Target Solution Sketch (Evolution Outline)</h4><p>Comparing the solution in Figure 2 to the initial position sketch, we see that follow-up requests return a special response message indicating that the data has not changed. The client can then continue to use the data it has already received.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*l45V753LHma9PYzq.png" /><figcaption>Figure 2: Make Request Conditional: Target Solution Sketch: The first exchange (1–2) is the same as in the initial position. In the second request though, the client includes the condition metadata (3) in its request, which in turn allows the provider to respond with a special “not modified” message (4) if the data has not changed.</figcaption></figure><p>See the <a href="https://interface-refactoring.github.io/refactorings/makerequestconditional#examples">Interface Refactoring Catalog website</a> for an example, hints and pitfalls to avoid when applying this refactoring and more related content.</p><h3>The EuroPLoP Conference Experience</h3><p>EuroPLoP’s distinctive format involves two key phases:</p><ul><li><strong>Shepherding</strong>: For approximately three months before the conference, authors work closely with assigned “shepherds” to refine their papers. This process allows for in-depth feedback and iterative improvement.</li><li><strong>Writers’ Workshops</strong>: Forming the core of the conference, these workshops involve authors reading and discussing each other’s papers following a specific protocol. This peer-review process provides valuable insights and constructive criticism.</li></ul><p>The reception of our work on interface refactorings was overwhelmingly positive. Workshop participants appreciated several aspects of our refactorings:</p><ul><li>The approach of starting from stakeholder concerns and API design smells was deemed particularly useful.</li><li>Our detailed guidance, supported by examples, was well-received.</li><li>The carefully chosen names for the refactorings were praised for their readability and clarity.</li><li>The extensive references and footnotes were recognized as a valuable resource for further research.</li></ul><p>We thank both our shepherd and all workshop participants for their feedback!</p><h3>What’s Next?</h3><p>Our catalog has enough candidates and draft refactorings for another issue of the conference. For example, Split Application Backend, Move Operation or Bundle Requests could be next. Drafts are available on the <a href="https://interface-refactoring.github.io/">Interface Refactoring Catalog</a> website.</p><p>Our paper <a href="https://interface-refactoring.github.io/assets/PatternOrientedAPIRefactoringEuroPLoP2024.pdf">Pattern-oriented API Refactoring: Addressing Design Smells and Stakeholder Concerns</a> (PDF) is open access and available under a Creative Commons license.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=51cffa5a054d" width="1" height="1" alt=""><hr><p><a href="https://medium.com/olzzio/pattern-oriented-api-refactoring-51cffa5a054d">Pattern-oriented API Refactoring</a> was originally published in <a href="https://medium.com/olzzio">ZIO’s Blog</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Measuring Java Energy Consumption]]></title>
            <link>https://medium.com/growing-green-software/measuring-java-energy-consumption-987654efdabb?source=rss-ff9700c896a8------2</link>
            <guid isPermaLink="false">https://medium.com/p/987654efdabb</guid>
            <category><![CDATA[java]]></category>
            <category><![CDATA[green-software]]></category>
            <category><![CDATA[energy-measurement]]></category>
            <category><![CDATA[jmh]]></category>
            <dc:creator><![CDATA[Mirko Stocker]]></dc:creator>
            <pubDate>Fri, 20 Sep 2024 11:12:51 GMT</pubDate>
            <atom:updated>2024-09-23T07:08:58.204Z</atom:updated>
            <content:encoded><![CDATA[<p>In a <a href="https://medium.com/growing-green-software/software-efficiency-and-energy-consumption-916b390593ec">previous post</a>, we discussed software efficiency and ways to measure the energy consumption of software. We used the <a href="https://github.com/osmhpi/pinpoint">Pinpoint</a> command line tool to measure the energy consumption when compiling a Java application. This probably wasn’t the most exciting demonstration, but it showed that we can measure the energy consumption of running software. In this post, we will dig deeper and measure the energy consumption of Java programs on an individual method level.</p><p>There are several <a href="https://en.wikipedia.org/wiki/Software_metric">measurable aspects of software</a>, such as execution time, memory usage, network performance, test coverage (how much of our software is covered by automated tests), and energy consumption. These are all runtime measurements that can only be collected by observing the running software. There are also several static measurements of software that we can get without running it, such as adherence to programming language style guides, potential bugs, architectural conformance, or source code complexity.¹</p><p>With the current state of the art, we cannot measure software&#39;s energy consumption without also running it. There are just too many variables that influence the energy consumption of software, such as the hardware it runs on, the operating system, and so on. If we make enough assumptions, it might be possible to estimate energy consumption statically, but that’s something to explore in the future.² So, let’s get back to runtime measurements, specifically measuring the energy consumption of Java software.</p><p>Why Java? I’ve spent the last twenty years programming in Java and related languages (Scala, JRuby) and am most familiar with its ecosystem. It’s also <a href="https://www.jetbrains.com/lp/devecosystem-2023/languages/">widely used</a> in industry. As an added challenge, measuring it is not as straightforward as measuring C or C++ software. Java runs on a virtual machine, the Java Virtual Machine (JVM), which abstracts the hardware and operating system from the software. Virtual machines typically use Just-In-Time (JIT) compilation,³ which might compile the Java byte code to machine code during runtime and optimize it for the specific hardware as it runs. There also is a Garbage Collector (GC) that reclaims memory by clearing unused objects. The GC can cause unpredictable pauses, affecting the consistency of performance measurements.</p><h3>Java Microbenchmark Harness</h3><p>When it comes to measuring the performance of Java applications, one of the most widely used tools is the <a href="https://github.com/openjdk/jmh">Java Microbenchmark Harness</a> (JMH). JMH is a versatile benchmarking framework that allows developers to write and execute micro-benchmarks to evaluate the performance of specific methods. JMH provides a standardized and reliable way to conduct performance tests, ensuring accurate results. It also takes care of “warming up” the virtual machine, meaning that it runs the code a few times before measuring it to give the virtual machine a chance to optimize the code. While garbage collection pauses can still affect the results, JMH comes with a GC Profiler to help you understand what is happening under the hood, for example, to detect memory leaks.</p><p>As an example, let’s compare two different list data structures: ArrayList and LinkedList and measure the time it takes to add different amounts of random numbers to a list. A JMH benchmark to measure the performance of these operations might look like this:</p><pre>@BenchmarkMode(Mode.AverageTime)<br>@Measurement(iterations = 5)<br>@Warmup(iterations = 5)<br>@OutputTimeUnit(TimeUnit.MILLISECONDS)<br>@Fork(value = 1)<br>@State(Scope.Benchmark)<br>public class CollectionAdd {<br><br>    @Param({ &quot;100000&quot;, &quot;200000&quot;, &quot;500000&quot;, &quot;1000000&quot; })<br>    private int collectionSize;<br>    private int[] valuesToAdd;<br><br>    @Setup<br>    public void iterationSetup() {<br>        valuesToAdd = new int[collectionSize];<br>        Random rand = new Random(9032);<br>        for (int i = 0; i &lt; collectionSize; i++) {<br>            valuesToAdd[i] = rand.nextInt(collectionSize);<br>        }<br>    }<br><br>    @Benchmark<br>    public List&lt;Integer&gt; addToJavaArrayList() {<br>        var result = new ArrayList&lt;Integer&gt;();<br>        for (int i = 0; i &lt; valuesToAdd.length; i++) {<br>            result.add(valuesToAdd[i]);<br>        }<br>        return result;<br>    }<br><br>    @Benchmark<br>    public List&lt;Integer&gt; addToJavaLinkedList() {<br>        var result = new LinkedList&lt;Integer&gt;();<br>        for (int i = 0; i &lt; valuesToAdd.length; i++) {<br>            result.add(valuesToAdd[i]);<br>        }<br>        return result;<br>    }<br><br>    public static void main(String[] args) throws RunnerException {<br>        Options opt = new OptionsBuilder()<br>                .include(CollectionAdd.class.getSimpleName())<br>                .build();<br>        new Runner(opt).run();<br>    }<br>}</pre><p>The full code is available on <a href="https://github.com/misto/java-collection-impls-benchmark">GitHub</a>. As we can see, JMH uses annotations to parametrize the measurement:</p><ul><li>@BenchmarkMode(Mode.AverageTime) specifies that the benchmark should measure the average time of the operation. An operation is a method that has the @Benchmark annotation, such as addToJavaArrayList or addToJavaLinkedList.</li><li>The @Measurement annotation specifies that the benchmark should run five times (see the Cnt column in the output below).</li><li>@Warmup specifies the number of warm-up iterations. These are thrown away and not counted in the results; they are just there to give the virtual machine a chance to optimize the code, as we discussed earlier.</li><li>@OutputTimeUnit(TimeUnit.MILLISECONDS) specifies that the output should be in milliseconds (see the Units in the output below).</li><li>@Fork(value = 1) specifies that the benchmark should run just once, in a single fork.</li><li>@State(Scope.Benchmark) marks the class that holds the state of the benchmark. In this case, the class has two member variables: an int collectionSize that specifies the collection size and an array valuesToAdd that holds the random numbers to add to the list.</li><li>We only want to generate the random numbers once, so we use the @Setup annotation to initialize the data for the benchmark. Note that we specify four different sizes for the list: 100&#39;000, 200&#39;000, 500&#39;000, and 1&#39;000&#39;000 elements. The benchmark will run for each of these sizes, with JMH injecting the values into the collectionSize variable.</li></ul><p>Note that the code adds primitive int values to collections of Integer objects, which forces Java to wrap these ints into objects (this technique is called <a href="https://docs.oracle.com/javase/tutorial/java/data/autoboxing.html">autoboxing</a>). While this adds a constant overhead to all the calls, it should keep the big picture the same.</p><p>We have two methods that are benchmarked, addToJavaArrayList and addToJavaLinkedList. When we run this program, a table with the results will be printed to the console:</p><pre>java -jar target/java-collection-impls-benchmark.jar<br># JMH version: 1.37<br>...<br>Benchmark                               (collectionSize)  Mode  Cnt   Score   Error  Units<br>CollectionAdd.addToJavaArrayList                  100000  avgt    5   0.298 ± 0.004  ms/op<br>CollectionAdd.addToJavaArrayList                  200000  avgt    5   0.606 ± 0.004  ms/op<br>CollectionAdd.addToJavaArrayList                  500000  avgt    5   4.360 ± 0.151  ms/op<br>CollectionAdd.addToJavaArrayList                 1000000  avgt    5  15.290 ± 1.407  ms/op<br>CollectionAdd.addToJavaLinkedList                 100000  avgt    5   0.342 ± 0.009  ms/op<br>CollectionAdd.addToJavaLinkedList                 200000  avgt    5   0.689 ± 0.015  ms/op<br>CollectionAdd.addToJavaLinkedList                 500000  avgt    5   1.712 ± 0.068  ms/op<br>CollectionAdd.addToJavaLinkedList                1000000  avgt    5   3.533 ± 0.282  ms/op</pre><p>Comparing the “collectionSize” and the “Score”, we see that the LinkedList growth is linear in the number of elements. This is because adding an element to the end of a LinkedList always takes the same time, no matter how large it is. The picture is not as clear with the ArrayList, which internally has a fixed-size array that has to be copied into a larger array when it runs out of space (see <a href="https://www.baeldung.com/java-arraylist-linkedlist">this article</a> for details between the two implementations).</p><p>Let us throw in some additional collections to make the comparison more interesting. Besides collections included with the Java standard library, third-party libraries such as the <a href="https://www.eclipse.org/collections/">Eclipse Collections</a> (previously known as the Goldman Sachs Collections due to their roots) exist. For example, the FastList (an optimized array-based list) and the IntArrayList (a specialized list that does not box/wrap int values) are optimized for performance. Adding these to the benchmark results in the following output (note that the source code snippet above does not include the additional benchmarks, but the full example in the GitHub repo does):</p><pre>Benchmark                               (collectionSize)  Mode  Cnt   Score   Error  Units<br>CollectionAdd.addToEclipseFastList                100000  avgt    5   0.303 ± 0.011  ms/op<br>CollectionAdd.addToEclipseFastList                200000  avgt    5   0.620 ± 0.004  ms/op<br>CollectionAdd.addToEclipseFastList                500000  avgt    5   4.451 ± 0.215  ms/op<br>CollectionAdd.addToEclipseFastList               1000000  avgt    5  11.562 ± 0.283  ms/op<br>CollectionAdd.addToEclipseIntArrayList            100000  avgt    5   0.157 ± 0.005  ms/op<br>CollectionAdd.addToEclipseIntArrayList            200000  avgt    5   0.324 ± 0.006  ms/op<br>CollectionAdd.addToEclipseIntArrayList            500000  avgt    5   0.794 ± 0.038  ms/op<br>CollectionAdd.addToEclipseIntArrayList           1000000  avgt    5   1.516 ± 0.056  ms/op<br>CollectionAdd.addToJavaArrayList                  100000  avgt    5   0.298 ± 0.004  ms/op<br>CollectionAdd.addToJavaArrayList                  200000  avgt    5   0.606 ± 0.004  ms/op<br>CollectionAdd.addToJavaArrayList                  500000  avgt    5   4.360 ± 0.151  ms/op<br>CollectionAdd.addToJavaArrayList                 1000000  avgt    5  15.290 ± 1.407  ms/op<br>CollectionAdd.addToJavaLinkedList                 100000  avgt    5   0.342 ± 0.009  ms/op<br>CollectionAdd.addToJavaLinkedList                 200000  avgt    5   0.689 ± 0.015  ms/op<br>CollectionAdd.addToJavaLinkedList                 500000  avgt    5   1.712 ± 0.068  ms/op<br>CollectionAdd.addToJavaLinkedList                1000000  avgt    5   3.533 ± 0.282  ms/op</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Zk9dHMVYtGbld1QLGUPdDg.png" /><figcaption><em>Figure 1: The time it takes to add items to different collections grows linearly or polynomially with the size of the collection.</em></figcaption></figure><p>We can see that they are indeed faster, so if performance is a concern and you have such large collections, you might consider using a FastList or IntArrayList instead of the standard JDK collections. You might ask, why would I ever use ArrayList if it&#39;s apparently slower than the others? Keep in mind that we only benchmarked adding elements to the end of the list. We did not measure the time it takes to access elements by index, remove elements, or iterate over the lists. Depending on your use case, ArrayList might still be the best choice and is a safe default. If you&#39;re curious, check out the <a href="https://github.com/misto/java-collection-impls-benchmark">source code on GitHub</a> and run your own benchmarks. You could try even larger collections or smaller ones. Use other data structures than lists, etc.</p><p>Ok, enough with comparing performance. What about energy consumption?</p><h3>JoularJX</h3><p>While JMH is great for measuring the performance of Java applications, it does not provide a way to measure energy consumption. For this, we can use <a href="https://joular.github.io/joularjx/overview.html">JoularJX</a>. JoularJX is a Java agent that hooks into the JVM to measure the energy consumption of applications. Depending on the platform, <em>RAPL (Running Average Power Limit)</em> or other hardware counters are used to measure the energy consumption of the whole JVM. JoularJX can even break the consumption down to individual methods! This level of detail gives us interesting possibilities.</p><p>We will pick up our collection benchmarking later, but first, let’s start with a simple example. We will measure the energy consumption of calculating prime numbers. Not just a single prime number, that would run too quickly, we need something that runs for a while to get meaningful results. We will count the number of prime numbers between 2 and 100&#39;000&#39;000⁴:</p><pre>package ch.ost.ifs.cal;<br><br>import java.util.stream.LongStream;<br><br>public class PrimeNumberCounter {<br> <br>    public static void main(String[] args) {<br>        var from = 2;<br>        var to = 100_000_000;<br>        var numberOfPrimes = countPrimesInRange(from, to);<br>        System.out.println(&quot;There are &quot; + numberOfPrimes + &quot; primes between &quot; + from + &quot; and &quot; + to); <br>    }<br><br>    private static long countPrimesInRange(int from, int to) {<br>        var result = LongStream.range(from, to)<br>                               .filter(number -&gt; isPrime(number))<br>                               .count();<br>        return result;<br>    }<br><br>    private static boolean isPrime(long number) {<br>        // the `factor * factor` is an optimization to reduce the number of checks<br>        for (long factor = 2; factor * factor &lt;= number; factor++) {<br>            if (number % factor == 0) { <br>                return false; <br>            }<br>        }<br>        return true;<br>    }<br>}</pre><p>The countPrimesInRange method calculates the number of prime numbers between from and to using an infinite stream of long numbers. The isPrime method tests whether a number is divisible by any number without a remainder (if you&#39;re unfamiliar with Java, that&#39;s what the % operator does). If it is possible to divide it, then the number is not prime, and the method returns false. If no divisor is found, the number is prime, and the method returns true. We can run this code with the JoularJX agent to measure the energy consumption:</p><pre>java -javaagent:/opt/joularjx/joularjx-2.9.0.jar -classpath target/classes ch.ost.ifs.cal.PrimeNumberCounter<br>10/07/2024 09:51:04.244 - [INFO] - +---------------------------------+<br>10/07/2024 09:51:04.245 - [INFO] - | JoularJX Agent Version 2.9.0    |<br>10/07/2024 09:51:04.245 - [INFO] - +---------------------------------+<br>10/07/2024 09:51:04.254 - [INFO] - Results will be stored in joularjx-result/20510-1720597864252/<br>10/07/2024 09:51:04.262 - [INFO] - Initializing for platform: &#39;mac os x&#39; running on architecture: &#39;aarch64&#39;<br>10/07/2024 09:51:04.263 - [INFO] - Please wait while initializing JoularJX...<br>10/07/2024 09:51:06.765 - [INFO] - Initialization finished<br>10/07/2024 09:51:06.766 - [INFO] - Started monitoring application with ID 20510<br>There are 5761455 primes between 2 and 100000000<br>10/07/2024 09:51:49.329 - [INFO] - Thread CPU time negative, taking previous time + 0 : 40230480000 for thread: 1<br>10/07/2024 09:51:49.332 - [INFO] - JoularJX finished monitoring application with ID 20510<br>10/07/2024 09:51:49.332 - [INFO] - Program consumed 95.15 joules<br>10/07/2024 09:51:49.335 - [INFO] - Energy consumption of methods and filtered methods written to files</pre><p>The second to last line shows that the “program consumed 95.15 joules”. JoularJX also writes the energy consumption of individual methods to files so that we can analyze them:</p><pre>jdk.internal.org.objectweb.asm.Type.getArgumentTypes,0.0000<br>ch.ost.ifs.cal.PrimeNumberCounter.isPrime,91.4710<br>java.util.stream.LongPipeline$9$1.accept,0.0026<br>java.lang.ref.Reference.waitForReferencePendingList,0.0006<br>sun.invoke.util.BytecodeDescriptor.unparse,0.0000<br>java.util.stream.Streams$RangeLongSpliterator.forEachRemaining,1.4731<br>java.lang.invoke.MethodHandleNatives.resolve,0.0000<br>java.lang.ProcessHandleImpl.waitForProcessExit0,0.0004</pre><p>The isPrime method consumed most of the energy (91.471 joules), which is unsurprising as it is the most computationally intensive part of the program. Our other methods, like countPrimesInRange, consumed so little power that they were not even listed.</p><h3>Combining JMH and JoularJX</h3><p>Now that we’ve seen how to measure the energy consumption of a single Java method, let’s combine JMH and JoularJX to measure our collection benchmark. There are some caveats: as we learned earlier, JMH warms up the JVM before measuring performance, so the energy consumption of the warm-up phase will be included in the JoularJX results. That’s why we turn off the warm-up, accepting that the performance measurements will be less accurate.</p><p>More importantly, we also need to change the measurement mode. Instead of having JMH call the methods multiple times and averaging the results, we will use Mode.SingleShotTime (indicated by the ss values in the &quot;Mode&quot; column of the table below), which measures the total time of a method. So now, we can combine the total time of a benchmark method with its energy consumption. For the same reason, we also have to run the benchmark individually for each collection size, so we run it once for 100&#39;000 elements, combine it with the JoularJX measurements, then run it again for 200&#39;000 elements, and so on.</p><p>The following snipped highlights the changes to the benchmark (notation: diff):</p><pre>--- @BenchmarkMode(Mode.AverageTime)<br>+++ @BenchmarkMode(Mode.SingleShotTime)<br>--- @Measurement(iterations = 5)<br>--- @Warmup(iterations = 5)<br>+++ @Measurement(iterations = 10, batchSize = 1000)</pre><p>So, we do ten iterations, and in each iteration, we run the same benchmark method 1000 times. Combining JMH and JoularJX, we get the following results for a collectionSize of 1&#39;000&#39;000 elements:</p><pre>Benchmark                              (collectionSize) Mode Cnt    Score      Error   Units    Joules   <br>CollectionAdd.addToEclipseFastList       1000000         ss   10 10652.147  ±  312.464 ms/op 1479.9486<br>CollectionAdd.addToEclipseIntArrayList   1000000         ss   10  1600.708  ±   61.199 ms/op   52.6131<br>CollectionAdd.addToJavaArrayList         1000000         ss   10 13244.062  ±  261.798 ms/op 1879.2856<br>CollectionAdd.addToJavaLinkedList        1000000         ss   10  4098.937  ± 1140.329 ms/op  175.6389</pre><p>Note the last column that shows the Joules as measured by JoularJX. Running the benchmark for the other collection sizes, we get the following results (only the ArrayList and LinkedList are shown below; see the <a href="https://github.com/misto/java-collection-impls-benchmark">repository</a> for the full results):</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*8nnFg2WFx3gBVv6hjFF2fg.png" /><figcaption><em>Figure 2: Comparing the score and the energy consumption of the </em><em>ArrayList benchmark.</em></figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Y78f6q0LVXTYZY3J3qfJJQ.png" /><figcaption><em>Figure 3: Comparing the score and the energy consumption of the </em><em>LinkedList benchmark.</em></figcaption></figure><p>As we can see, the scores and energy consumption evolve similarly with collection size. This relationship is not surprising since the energy consumption of a method is directly related to the time it takes to execute, especially for code like this that is not idle waiting for something to happen. But seeing them correlate is nice and gives me confidence in the tools and measurements.</p><h3>Conclusion</h3><p>This post looked at the energy consumption of Java software. We used the Java Microbenchmark Harness to measure the performance of Java software and JoularJX to measure energy consumption. We combined the two tools to measure the energy consumption of different Java collections.</p><p>We learned that:</p><blockquote><em>JMH is a versatile benchmarking framework that allows developers to write and execute microbenchmarks to evaluate the performance of specific methods.</em></blockquote><p>We also learned that:</p><blockquote><em>JoularJX is a Java agent that hooks into the Java virtual machine to measure the energy consumption of applications.</em></blockquote><p>Combining these two tools, we saw that:</p><blockquote><em>The energy consumption of a method is directly related to the time it takes to execute.</em></blockquote><p>Note that we will not be doing any statistical analysis of the data, as this is just a demonstration. If we were to do that, we would need more iterations and benchmarks to get meaningful results and set up the experiments properly.</p><p>Where can we go from here? We could study the energy consumption of different algorithms or compare different implementations of the same algorithm. But for such tasks, it’s probably easier to stick to measuring performance and using that as a proxy for energy efficiency. Suppose we are more concerned with understanding the energy consumption of different parts or components of our software than with direct comparisons. For example, one could determine the energy consumption of individual API operations. In that case, JoularJX is an excellent tool and starting point.</p><p>In a future post, we will try to measure the energy consumption of a Spring Boot application. Stay tuned!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/633/1*SY9qTXJrMHaj_gytbHO_rg.png" /><figcaption><em>Figure 4: Overview of topics that we covered in this post.</em></figcaption></figure><p><strong>Acknowledgements. </strong>I thank <a href="https://medium.com/@docsoc">Olaf</a> and <a href="https://medium.com/@Styp">Martin</a> for their valuable feedback.</p><h3>Further Reading</h3><p>Asher Toqeer has a nice blog post on <a href="https://thebackendguy.com/posts/performance-analysis-using-jmh/">performance analysis using JMH</a> that explains the different options and how to get started with JMH. The <a href="https://github.com/Valloric/jmh-playground">JMH Playground</a> repository contains a playground for JMH that you can use to get started.</p><p>Check out the <a href="https://github.com/ionutbalosin/jvm-performance-benchmarks?tab=readme-ov-file">JVM Performance Benchmarks</a> repository if you’re looking for more benchmarks.</p><ol><li>If you studied computer science, you might remember the <a href="https://en.wikipedia.org/wiki/Big_O_notation">Big O and Big Theta</a> notations, which describe the complexity of algorithms. These notations give us a way to reason how the running time of software will change depending on the amount of data and to classify algorithms. All without running it.</li><li>The <a href="https://projects.ics.forth.gr/carv/greenvm/index.html">GreenVM</a> project published a technical report on “<a href="https://projects.ics.forth.gr/carv/greenvm/publications.html">An Instruction Level Energy Characterization of ARM Processors</a>” that came up with energy metrics for the different CPU instructions.</li><li>Alternative to Just-In-Time (JIT) compilation, there is also Ahead-Of-Time (AOT) compilation, such as <a href="https://www.graalvm.org/">GraalVM</a>, but that’s not (yet) the default for Java.</li><li>The code is adapted from my first-semester course on object-oriented programming at the <a href="https://www.ost.ch/de/studium/informatik/bachelor-informatik">Eastern Switzerland University of Applied Sciences</a>.</li></ol><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=987654efdabb" width="1" height="1" alt=""><hr><p><a href="https://medium.com/growing-green-software/measuring-java-energy-consumption-987654efdabb">Measuring Java Energy Consumption</a> was originally published in <a href="https://medium.com/growing-green-software">Growing Green Software</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Carbon Emissions in ICT]]></title>
            <link>https://medium.com/growing-green-software/carbon-emissions-in-ict-99a0d421bbb6?source=rss-ff9700c896a8------2</link>
            <guid isPermaLink="false">https://medium.com/p/99a0d421bbb6</guid>
            <category><![CDATA[cloud-computing]]></category>
            <category><![CDATA[green-software]]></category>
            <category><![CDATA[carbon-emissions]]></category>
            <category><![CDATA[data-center]]></category>
            <category><![CDATA[sustainable-software]]></category>
            <dc:creator><![CDATA[Mirko Stocker]]></dc:creator>
            <pubDate>Tue, 06 Aug 2024 08:53:27 GMT</pubDate>
            <atom:updated>2024-08-06T08:53:27.399Z</atom:updated>
            <content:encoded><![CDATA[<p>In this article, we will look into carbon emissions. We know that there are too many of them and that they are terrible for our planet. But what exactly are carbon emissions? How do they relate to software? Is it just a matter of how dirty the energy is that powers the systems that run our software?</p><p>In a <a href="https://medium.com/growing-green-software/software-efficiency-and-energy-consumption-916b390593ec">previous post</a>, we learned the carbon emissions of the Information Communication Technology (ICT) sector are estimated to be as high as 3.9% of global emissions.¹ But when I look around in my office, I’m probably the biggest carbon emitter. The average person exhales approximately <a href="https://www.sciencefocus.com/planet-earth/how-much-does-human-breathing-contribute-to-climate-change">1 kg or 500 liters of CO₂ daily</a>. So why is ICT such a big problem?</p><h3>Types of Emissions</h3><p>First, let’s look at the different lifecycle steps of a product and the emissions caused by each of them. Emissions can be categorized into two groups: <em>embodied</em> and <em>operational</em>. For a piece of hardware, the embodied emissions, also called upfront emissions, are caused by the production of the hardware, including mining raw materials, manufacturing, and transportation. It’s not just up-front emissions, but the end-of-life emissions caused by hardware disposal are also embodied. The running of the hardware and infrastructure causes operational or in-use emissions. But what is the proportional distribution of these two types of emissions? According to <a href="https://doi.org/10.1016/j.patter.2021.100340">Charlotte Freitag and colleagues</a>, embodied emissions account for about a quarter of ICT emissions. The remaining ones are operational emissions. However, the share of embodied emissions for consumer devices is much higher, at around 50%, because these devices are only used for parts of the day and use less electricity but are replaced often, especially smartphones.</p><p>This categorization of embodied and operational emissions can also be applied to software. All the emissions that occur during the construction of the software, including the developer hardware, operating the staging servers, CI/CD pipelines, coffee makers, commuting to the office, etc. together comprise the embodied or upfront emissions. The operational emissions would then be the emissions caused by running the software on end-user devices and the emissions caused by running the servers and networks that deliver the software to end users.</p><p>To add up all these emissions, we simplify them and use carbon dioxide (CO₂) equivalent emissions or, even less specifically, just talk about “CO₂ emissions” but mean all greenhouse gas (GHG) emissions. The most critical GHGs besides carbon dioxide are methane (CH₄), nitrous oxide (N₂O), and various fluorinated gases, as defined by the <a href="https://ec.europa.eu/eurostat/statistics-explained/index.php?title=Glossary:Greenhouse_gas_(GHG)">Kyoto Protocol</a>. From a software engineering perspective, this simplification is acceptable since a) carbon dioxide is the most important by volume and b) it occurs when fossil fuels are burned, for example, to produce electricity. But carbon emissions are not the only problem — we should be aware of other environmental impacts of software, such as water consumption, which we will return to later in this post.</p><h3>Energy Sources</h3><p>ICT runs on electricity, so unsurprisingly, the operational emissions are caused by the emissions that occur during electricity production for these devices (electricity and heating are by far the largest source of emissions overall; see <a href="https://ourworldindata.org/emissions-by-sector#energy-electricity-heat-and-transport-73-2">Emissions by sector: where do greenhouse gases come from?</a>). The electricity mix varies from country to country, but in most countries, electricity is still produced by burning fossil fuels. According to <a href="https://ourworldindata.org/renewable-energy">Our World in Data</a>, the share of renewable energy in the global electricity mix is about one-third. For a closer look and real-time share of renewables by country, see the beautiful <a href="https://app.electricitymaps.com/map">Electricity Maps</a>. They even have an <a href="https://static.electricitymaps.com/api/docs/index.html">API</a> that exposes the carbon intensity of electricity in a given region. The carbon intensity of electricity is the amount of carbon dioxide emitted per unit of electricity produced and is measured in grams of CO₂ per kilowatt-hour (gCO₂/kWh). Coal is the most carbon-intensive energy source, followed by oil and natural gas (for details, see the UK government’s <a href="https://www.forestresearch.gov.uk/tools-and-resources/fthr/biomass-energy-resources/reference-biomass/facts-figures/carbon-emissions-of-different-fuels/">Forest Research</a> organization).</p><p>Considering that about a third of ICT emissions can be attributed to end-user devices (estimates range <a href="https://www.sciencedirect.com/science/article/pii/S2666389921001884?via%3Dihub#fig3">between 32%-57%</a> for end-user devices, 22%-25% for networks, and 18%-41% for data centers), another approximate third to networks (where we software engineers have the least direct control), and the remaining third to data centers, there are multiple ways to reduce the carbon emissions of our software. One way is to reduce the hardware’s energy consumption, whether end-user devices or servers, by optimizing our software. Minimizing data transmission is another. And we can choose a cloud provider that uses renewable energy.</p><h3>Is 100% Renewable Energy Enough?</h3><p>Let’s start with the last one: choosing a cloud provider that uses renewable energy. Chances are, your cloud provider already uses renewable energy to a large extent. For example, <a href="https://azure.microsoft.com/en-us/explore/global-infrastructure/sustainability/">Azure plans to use 100% renewable energy by 2025</a>. But even once that is reached, this does not mean that each data center actually uses renewable energy all around the clock. Typically, the provider simply buys the same amount of renewable energy that the data center uses over time, for example, over the period of a year, in what is called a <a href="https://en.wikipedia.org/wiki/Power_purchase_agreement">Power Purchase Agreement (PPA)</a>. The fundamental problem is that the energy consumption of a data center does not always coincide with the energy generation from renewable sources. Sometimes, a data center needs more energy than is currently available from renewable sources, bringing us back to the grid’s energy mix. Having said that, it is still better to buy renewable energy, especially if such PPAs are used to finance the construction of new renewable energy plants (this is called <a href="https://perspectives.se.com/renewable-energy/what-you-need-to-know-about-additionality">additionality</a> because it adds to the overall generation and doesn’t just divert the renewable energy away from other uses). Others use Renewable Energy Certificates (RECs) to offset their carbon emissions, but as the <a href="https://newclimate.org/resources/publications/navigating-the-nuances-of-corporate-renewable-electricity-procurement">New Climate Institute</a> highlights, RECs are “very unlikely to contribute to additional renewable capacity. [..] For instance, companies may procure RECs generated in Norway to claim they are using renewable electricity in Bulgaria. This action sends no signal to Norwegian power suppliers, who already are producing most of their electricity from renewables, nor to Bulgarian power suppliers.” Another cloud provider, <a href="https://www.aboutamazon.com/news/sustainability/amazon-renewable-energy-portfolio-november-2023-update">Amazon’s AWS</a>, has a growing renewable energy portfolio. The ultimate goal should be to use only renewable energy, like <a href="https://cloud.google.com/blog/topics/inside-google-cloud/announcing-round-the-clock-clean-energy-for-cloud">Google Cloud plans to do by 2030</a> with its “24/7 Carbon-Free Energy” goal. Does that mean we can tick off the cloud in our quest to grow greener software? Of course not; running inefficient software and wasting energy is still not a good idea, even if it comes from renewable sources — that energy could have gone to other/better uses. Also, code and data must go to and return from the cloud.</p><h3>Power Usage Effectiveness</h3><p>If current trends continue, all cloud providers and other hosting providers will sooner or later run on renewable energy. Maybe not all the time, but at least on average. So, besides looking at the share of renewable energy, a different comparison metric is the Power Usage Effectiveness (PUE) of a data center. To quote <a href="https://en.wikipedia.org/wiki/Power_usage_effectiveness">Wikipedia</a>:</p><blockquote><em>Power usage effectiveness (PUE) is a ratio that describes how efficiently a computer data center uses energy; specifically, how much energy is used by the computing equipment (in contrast to cooling and other overhead that supports the equipment).</em></blockquote><p>Ideally, the PUE is 1, meaning that all the energy is used by the computing equipment. In reality, this is not achievable. The <a href="https://emea.socomec.com/en/measuring-pue-power-usage-effectiveness">average PUE of data centers</a> was estimated at just 1.6. <a href="https://www.google.com/about/datacenters/efficiency/">Google Cloud reports PUE numbers</a>, showing that they achieved an overall PUE of 1.1. If you invert the PUE, you get the Data Center Infrastructure Efficiency (DCIE) metric. In Google’s case, the DCIE is 90.9%. This means that the computing equipment uses 90.9% of the energy, and the remaining 9.1% is used for cooling, lighting, etc. When comparing data centers, keep in mind that since cooling is an essential factor, the location of the data center is highly influential. For example, <a href="https://www.google.com/about/datacenters/inside/locations/hamina/">Google’s data center in Hamina, Finland</a> (PUE: 1.09) uses seawater from the Bay of Finland for cooling, whereas their <a href="https://www.google.com/about/datacenters/locations/singapore/">Singapore data center</a> (PUE: 1.20) has a higher PUE because its cooling system is probably more energy-intensive (they use recycled water for cooling).</p><h3>Water Usage</h3><p>Besides electricity, another essential resource for data centers is water. Water is directly used for cooling but also indirectly for generating electricity (this relationship between water and energy is called the <a href="https://en.m.wikipedia.org/wiki/Water-energy_nexus#">Water-energy nexus</a>). In turn, supplying the water to the data center and treating the wastewater uses energy itself. Large data centers use millions of liters daily (<a href="https://blog.google/outreach-initiatives/sustainability/our-commitment-to-climate-conscious-data-center-cooling/">“the average Google data center consumed approximately 450,000 gallons of water per day”</a>, about 1700 m³).</p><p>Consequently, a Water Usage Effectiveness (WUE) metric has been proposed under <a href="https://www.iso.org/standard/77692.html">ISO/IEC 30134–9:2022</a>, which is the ratio of the total water consumption of a data center to its energy consumption. While many data centers are located in regions with abundant water supply, there are others in areas with water scarcity. A study by <a href="https://iopscience.iop.org/article/10.1088/1748-9326/abfba1#erlabfba1s4">Md Abu Bakar Siddik</a> showed that “one-fifth of [US] data center servers direct water footprint comes from moderately to highly water stressed watersheds, while nearly half of servers are fully or partially powered by power plants located within water stressed regions.” So just comparing WUEs might not be as helpful as PUEs.</p><h3>Carbon Footprint</h3><p>Going back to carbon, we could now attempt to do some “carbon accounting” and calculate the carbon footprint of software.² The carbon footprint is the total amount of carbon dioxide and other GHGs emitted over the entire lifecycle of a product or service. I say “could attempt” because this is far from easy. There are many factors to consider, and the data is often unavailable or incomplete. Cloud providers have recently started to provide dashboards and metrics for cloud resources (see <a href="https://aws.amazon.com/blogs/aws/new-customer-carbon-footprint-tool/">AWS Customer Carbon Footprint Tool</a>, <a href="https://www.microsoft.com/en-us/sustainability/emissions-impact-dashboard">Azure Emissions Impact Dashboard</a>, and <a href="https://cloud.google.com/carbon-footprint?hl=de">Google Cloud Carbon Footprint</a>). This looks fantastic, but when digging deeper, one realizes that they’re not all (yet) as helpful and complete as one might hope, as we’ll see shortly.</p><p>The <a href="https://ghgprotocol.org/">Greenhouse Gas Protocol</a> is a widely used standard to calculate the carbon footprint of anything. It distinguishes between three scopes of emissions:</p><ul><li>Scope 1: Direct emissions from sources owned or controlled by an organization. A typical software company may have a limited number of sources, such as company cars or heating. Unless you run your own data center on diesel generators, then you have a significant scope 1 emissions problem…</li><li>Scope 2: Indirect emissions from the generation of purchased energy (e.g., electricity for the office and computers).</li><li>Scope 3: All indirect emissions (not included in scope 2), including both upstream (e.g., hardware manufacturing) and downstream emissions (e.g., electricity use of your customers when they use your product).</li></ul><p>The standard originates in manufacturing and other industries, so it doesn’t fit perfectly for software. I found the article <a href="https://www.wonderingchimp.com/deep-dive-into-scope-3-emissions">Deep Dive into Scope 3 emissions</a> by Marjan Bugarinović very helpful to better understand what comprises Scope 3 emissions. The proposed <a href="http://www.techcarbonstandard.org/">Technology Carbon Standard</a> better maps to the typical emissions of a software/technology company. It includes the following categories:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*EGaiy95izA0OH-lcV5jE-w.jpeg" /><figcaption><em>Figure 1: The Technology Carbon Standard by </em><a href="https://www.scottlogic.com/"><em>Scott Logic</em></a></figcaption></figure><p>Going back to the cloud providers’ tools, Amazon only considers <a href="https://docs.aws.amazon.com/awsaccountbilling/latest/aboutv2/ccft-estimation.html">Scope 1 and 2 emissions</a>, whereas <a href="https://learn.microsoft.com/en-us/industry/sustainability/api-calculation-method">Azure</a> and <a href="https://cloud.google.com/carbon-footprint/docs/methodology">Google Cloud</a> also include Scope 3. Even with this data, we are still missing the whole networking part and the end-user devices. So, we’re still far from a complete picture. We will try to fill in some of these gaps in future posts.</p><h3>Conclusion</h3><p>The environmental impact of data centers and software development is a complex issue that requires careful consideration. We learned that</p><blockquote><em>Metrics such as Power or Water Usage Effectiveness and Data Center Infrastructure Efficiency provide useful insights into the energy and water efficiency of data centers.</em></blockquote><p>However, they don’t tell the whole story, especially when it comes to carbon emissions. We also saw that:</p><blockquote><em>The GHG Protocol’s scopes of emissions offer a more comprehensive view, but even then, the data is often incomplete or unavailable.</em></blockquote><p>We learned that:</p><blockquote><em>Cloud providers have started to offer tools for tracking carbon footprints, but these tools are still in their early stages.</em></blockquote><p>As responsible green software developers and researchers, we must continue to push for more transparency and accountability in this area. But we need to do more than just wait and hope that others will fix it for us. Maybe we can start by incorporating carbon footprints into our decision-making or contributing to open-source tools? In future posts, we will explore where we can integrate these aspects into the software development process. We will also try out some tools for measuring and tracking the carbon footprint of software.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/976/1*wpWQq64dmKpPTCfIbZBoiw.png" /><figcaption><em>Figure 2: Overview of topics that we covered in this post.</em></figcaption></figure><p><strong>Acknowledgements. </strong>I would like to thank my colleagues <a href="https://medium.com/@docsoc">Olaf</a> and <a href="https://stefan-kapferer.medium.com/">Stefan</a> for providing feedback on an earlier version of this article.</p><h3>Further Reading</h3><p>Energy CX, an energy brokerage, has a nice <a href="https://www.energycx.com/blog/recs-and-ppas-how-green-energy-is-purchased">visualization of how RECs and PPAs work</a>.</p><p>David Mytton has a blog post on <a href="https://davidmytton.blog/how-much-water-do-data-centers-use/">How much water do data centers use?</a>.</p><p>Adrian Cockcroft analyzed the <a href="https://thenewstack.io/sustainability-how-did-amazon-azure-google-perform-in-2023/">2023 environmental reports of Amazon, Azure, and Google</a>.</p><ol><li>I tried to find recent studies that provide predictions, but I couldn’t find any. If you know of any, please let me know. For example, an often-cited one by <a href="https://www.mdpi.com/2078-1547/6/1/117">Andrae and Edler</a> from 2015 predicts that “CT electricity usage could contribute up to 23% of the globally released greenhouse gas emissions in 2030” (note the “CT”, so it’s just about the communication technology, not the whole ICT). In 2018, <a href="https://www.sciencedirect.com/science/article/pii/S095965261733233X#sec7">Belkhir and Elmeligi</a> concluded that “assuming a continued annual relative growth ranging from 5.6 to 6.9%, ICT’s relative contribution would exceed 14% of the 2016-level worldwide [Greenhouse Gas Emissions] by 2040”.</li><li>Not just of software, if you’re a researcher, have you thought about <a href="https://journals.plos.org/plosone/article?id=10.1371/journal.pone.0066508">The Carbon Footprint of Conference Papers</a>?</li></ol><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=99a0d421bbb6" width="1" height="1" alt=""><hr><p><a href="https://medium.com/growing-green-software/carbon-emissions-in-ict-99a0d421bbb6">Carbon Emissions in ICT</a> was originally published in <a href="https://medium.com/growing-green-software">Growing Green Software</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Software Efficiency and Energy Consumption]]></title>
            <link>https://medium.com/growing-green-software/software-efficiency-and-energy-consumption-916b390593ec?source=rss-ff9700c896a8------2</link>
            <guid isPermaLink="false">https://medium.com/p/916b390593ec</guid>
            <category><![CDATA[green-software]]></category>
            <category><![CDATA[software-efficiency]]></category>
            <category><![CDATA[energy-efficiency]]></category>
            <category><![CDATA[green-it]]></category>
            <category><![CDATA[energy-consumption]]></category>
            <dc:creator><![CDATA[Mirko Stocker]]></dc:creator>
            <pubDate>Sat, 08 Jun 2024 17:54:45 GMT</pubDate>
            <atom:updated>2024-06-08T17:54:45.542Z</atom:updated>
            <content:encoded><![CDATA[<p>Efficiency, in general, has long been a key concern in software development. In the early days of computing, when memory and processing power were scarce, programmers were forced to write efficient code that got the most out of the hardware. With today&#39;s abundant cheap memory, storage, and processing power and a shortage of skilled developers, hardware efficiency is often a secondary concern. Developer efficiency, which leads to increased business value, is a higher priority when choosing programming languages or frameworks. Massive computing power is only a few clicks away, thanks to the cloud. However, the move to the cloud has the potential to make software efficiency more important again. Cloud costs are directly related to resource usage and can even be reported to the users or developers on the level of individual applications or managed services used within applications.</p><p>In the realm of green software development, understanding software efficiency and energy consumption is crucial because there is a strong correlation between the two. And just like healthy plants thrive in the right conditions, efficient code runs smoothly and minimizes resource footprint. The more efficient a software system is, the less energy it consumes and the better for the environment it is. But how much energy does software consume? I was relieved to find a study that shows that I&#39;m not the only one having a hard time answering that: A group around Candy Pang from the University of Alberta studied the knowledge of programmers about energy consumption and found that they &quot;had limited knowledge of energy efficiency, lacked knowledge of the best practices to reduce software energy consumption, and were often unsure about how software consumes energy.&quot; Their research was peer-reviewed and published in the IEEE Software magazine. Unfortunately, the final article is behind a paywall, but the authors published <a href="https://www.researchgate.net/publication/308789636_What_do_programmers_know_about_the_energy_consumption_of_software">a pre-print version</a> that can be freely accessed.</p><p>This post delves into the fundamentals of energy measurement, providing software engineers with a basic understanding of energy units, energy consumption, and some energy measurement tools.</p><h3>Software Efficiency</h3><p>The <a href="https://dictionary.cambridge.org/dictionary/english/efficiency">Cambridge Dictionary</a> offers several definitions of efficiency. In the context of computers, the following is probably the most tangible:</p><blockquote>the relationship between the amount of energy put into a machine or process and the amount of useful work it produces.</blockquote><p>For example, the amount of light produced by a light bulb is the useful work, and the energy consumed is the energy that the light bulb draws from the power socket. Energy labels with an easy-to-compare scale are shown on appliances such as refrigerators, washing machines, or light bulbs (at least until LED became the standard, which is way more efficient and longer-lasting than incandescent lighting).</p><p>When applied to software, efficiency is the amount of useful work a software system produces per unit of energy consumed. For example, the amount of data a web server sends to a client is the useful work, and the energy consumed is the energy the server draws. In this case, the energy consumption is not directly visible to the user but is still there. One can, of course, argue that &quot;data transferred&quot; does not necessarily equal &quot;useful work.&quot; After all, the data might never be used. Still, as there is no standard definition of &quot;useful work&quot; in software, this will have to suffice for now.¹ Measuring software efficiency can nevertheless be helpful, for example, to compare different approaches, architectures, or products.</p><p>Another way to look at software efficiency is from a software quality perspective. The <a href="https://iso25000.com/index.php/en/iso-25000-standards/iso-25010">ISO/IEC 25010 Product Quality Model</a> lists performance efficiency as one of nine characteristics as &quot;the degree to which a product performs its functions within specified time and throughput parameters and is efficient in the use of resources.&quot; It has three sub-characteristics: Time Behavior (how well the product meets response time and throughput requirements), Resource Utilization (how well the product meets resource usage requirements), and Capacity (how well the product meets the maximum limits of a system parameter). The <a href="https://quality.arc42.org/qualities/efficiency">arc42 Quality Model</a> lists dozens of examples of related quality requirements.</p><h3>Energy Consumption</h3><p>Let&#39;s take a look at the other ingredient for efficiency: energy consumption, the amount of energy a system consumes over time. Energy can be <a href="https://www.aps.org/policy/reports/popa-reports/energy/units.cfm">expressed in different units</a>, such as Joules or Kilowatt-hours (or calories, but that might be more interesting for the software developers than for the software itself 😉).</p><blockquote><em>1 kilowatt-hour = 1 kWh = 3600 kilojoules = 3.6 MJ</em></blockquote><p>One way to measure energy consumption is by using a <em>Wattage and current meter</em>, which measures the power consumption of an electrical device in Watts. The power consumption is then multiplied by the time the device is used to calculate the energy consumption in Watt-hours or Kilowatt-hours. Here&#39;s an example of measuring the power consumption of the laptop I&#39;m using to write this post:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1008/1*r9LYRRhleJrmiLdQth865g.jpeg" /><figcaption><em>Figure 1: A Watt-meter measuring the power consumption of my laptop.</em></figcaption></figure><p>As we can see, when I took the picture, the laptop drew about 12 Watts from the power socket. There isn&#39;t much going on my system. Spotify is playing in the background, and I&#39;m writing this post in Visual Studio Code. If I were to use it for one hour just like this, it would consume 12 Watt-hours (or 0.012 Kilowatt-hours). Refreshing a page in the browser causes the consumption to spike to about 20 watts and then drop back to 12 (the power meter refreshes roughly once a second). Using a CPU stress testing tool, I can get the consumption up to 50-60 watts. When plugging in my external screen, usage jumps another 30 watts, which seems about right compared with the <a href="https://www.energystar.gov/productfinder/product/certified-displays/details/2347518">energystar label of the screen</a> (yet another known use of an energy label).²</p><p>Such meters can give us a first impression, albeit crude, of energy consumption. But what about devices, let&#39;s say a mobile phone, that runs on battery? There are ways to measure energy consumption under such circumstances; for example, see the tutorial <a href="https://tqrg.github.io/physalia/monsoon_tutorial">How to measure energy consumption with Monsoon</a> by Luís Cruz and Rui Abreu. But it&#39;s not as easy anymore as plugging in a Watt-meter. But even with a Watt-meter, I&#39;d still need to isolate the usage of my software that I want to measure from everything else that is going on in the system, and we also must correlate the measurements with the running time of the software. This is where <em>energy profiling tools</em> come into play.</p><h3>Energy Profiling</h3><p>Rather than treating the system as a black box, energy profiling tools measure the energy consumption from within. They are usually integrated into or use APIs of the operating system and can report energy consumption by process. Unfortunately, many of these tools work only on specific CPUs and/or operating systems. Also, not all components of a system are measured. For example, disks or peripheral devices are not. RAPL (Running Average Power Limit) is such an API for Intel-based systems to measure the energy consumption of CPUs, GPUs, and memory, which different tools can use. One commonly used tool is the <a href="https://github.com/intel/pcm">Intel® Performance Counter Monitor</a> open-source tool, which unsurprisingly doesn&#39;t work on my Apple Silicon CPU. While there seem to be tools under development that ought to support Apple Silicon (for example, <a href="https://github.com/osmhpi/pinpoint">PinPoint</a> and <a href="https://github.com/dehydratedpotato/socpowerbud">socpowerbud</a>), I haven&#39;t found one that works on my machine — pointers are welcome.</p><p>You might wonder, what about the overhead of profiling? Generally speaking, there are several ways to do profiling. One approach is to instrument the binary or the code to include additional instructions that record measurements. For example, let&#39;s say you want to find out how often each function in your program is called. A profiler could add &quot;counting&quot; instructions at the beginning of each function. Unsurprisingly, this would add quite a lot of overhead. A less invasive approach is performance counters, special-purpose CPU registers that provide information about the system. This is what RAPL uses, so the added overhead should be minimal. Of course, others have asked this question as well. Kashif Nizam Khan and a group of researchers from Finland, Switzerland, and China described several experiments in their publication <a href="https://www.researchgate.net/publication/322308215_RAPL_in_Action_Experiences_in_Using_RAPL_for_Power_Measurements">RAPL in Action: Experiences in Using RAPL for Power Measurements</a>. They conclude that “the performance overhead of RAPL measurements is considerably low and negligible.” The paper also provides a great introduction to how RAPL works.</p><h3>Example</h3><p>Since I haven&#39;t found a profiler that works on Apple Silicon, let&#39;s switch to a different system with more traditional hardware and operating system (Intel i7 Thinkpad running <a href="https://archlinux.org/">Arch Linux</a>). The PinPoint command-line tool mentioned above, which uses RAPL under the hood, also runs on Linux and allows us to measure the energy consumption of a process. Let&#39;s measure the compilation and packaging of a Java web application:³</p><pre>sudo  ~/pinpoint/build/pinpoint -r 4 -i 250 -- mvn --offline clean verify<br>[INFO] Scanning for projects...<br>...<br>[INFO] ------------------------------------------------------------------<br>[INFO] BUILD SUCCESS<br>[INFO] ------------------------------------------------------------------<br>[INFO] Total time:  5.377 s<br>[INFO] Finished at: 2024-01-04T16:39:28+01:00<br>[INFO] ------------------------------------------------------------------<br>Energy counter stats for &#39;mvn -o clean verify&#39;:<br>[interval: 250ms, before: 0ms, after: 0ms, delay: 0ms, runs: 4]<br><br>         14.13 J rapl:ram       ( +- 0.83% )<br>        145.50 J rapl:cores     ( +- 1.64% )<br>          2.17 J rapl:psys      ( +- 1.84% )<br>          0.92 J rapl:gpu       ( +- 5.64% )<br>        158.42 J rapl:pkg       ( +- 1.52% )<br><br>        6.26829439 seconds time elapsed ( +- 2.66% )</pre><p>As we can see, the process took 6.27 seconds and consumed about 175 Joules (J) of energy in total. Note that the &quot;rapl:pkg&quot; represents the whole CPU package and already includes the &quot;rapl:cores&quot; measurement, so we have to skip that entry when summing up the measurements. This is roughly as much energy as it takes to <a href="https://www.omnicalculator.com/physics/water-heating?v=dummy:0,mass:1!g,initial_temp:10!C,final_temp:50!C">heat 1 milliliter of water by 40 degrees</a>. RAPL was introduced for processor performance and thermal management, so it doesn&#39;t measure the energy consumption of other components, such as the disk. The network transfer is not measured either; we ran Maven offline, so this was not an issue in this example.</p><p>What do these numbers tell us? I&#39;ll admit that these are still very abstract and hard to act on from a software engineering perspective. But one thing we can do now is compare different runs of the same program over time. In a future post, we will try to integrate these numbers into a CI/CD pipeline to compare different versions of the same software to observe how energy consumption changes over time.</p><p>Another application would be to compare different but compatible runtimes. For example, we could compare the energy consumption of a Java application running on OpenJDK HotSpot with the same application running on Eclipse OpenJ9 or using ahead-of-time compiled <a href="https://docs.oracle.com/en/graalvm/enterprise/20/docs/reference-manual/native-image/">GraalVM Native Image</a>. Fortunately, Ionut Balosin already did this and wrote a great article on this topic: <a href="https://ionutbalosin.com/2023/07/analyzing-jvm-energy-consumption-for-jdk-17-an-empirical-study/">Analyzing JVM Energy Consumption for JDK 17: An Empirical Study</a>. He measured seven JVM distributions using different applications and found significant differences between JVMs. The code for his experiments is available on <a href="https://github.com/ionutbalosin/jvm-energy-consumption">GitHub</a>.</p><h3>Conclusion</h3><p>This post looked at the basics of measuring software efficiency and energy consumption. We learned that:</p><blockquote><em>Efficiency is the amount of useful work a software system produces per unit of energy consumed.</em></blockquote><p>We also learned that:</p><blockquote><em>Energy consumption can be measured in different units, such as Joules or Kilowatt-hours.</em></blockquote><p>We saw that:</p><blockquote><em>Energy profiling tools can help us measure the energy consumption of a process, but they are not always easy to use and don&#39;t measure all system components.</em></blockquote><p>However, they give us a first impression of the energy consumption, which will help us approximate our software&#39;s energy-related emissions.</p><p>What we haven&#39;t solved yet is how we could determine if the software actually performs &quot;useful work&quot;. One approach might be to attribute energy consumption to specific <a href="https://socadk.github.io/design-practice-repository/artifact-templates/DPR-UserStory.html">User Stories</a> or <a href="https://socadk.github.io/design-practice-repository/artifact-templates/DPR-UseCase.html">Use Cases</a> or even break it down to individual API calls.</p><h3>Further Reading</h3><p>For a more comprehensive list of energy profiling tools, see the <a href="https://luiscruz.github.io/2021/07/20/measuring-energy.html">Tools to Measure Software Energy Consumption from your Computer</a> post by Luís Cruz.</p><p>Firefox has a great article with background information on <a href="https://firefox-source-docs.mozilla.org/performance/power_profiling_overview.html">power profiling</a> that explains the different components of a processor (like the RAPL package mentioned above) and which tools can be used to measure them.</p><p>Another interesting tool for JVM-based applications is <a href="https://joular.github.io/joularjx/overview.html">JoularJX</a> by Adel Noureddine, &quot;a Java-based agent for power monitoring at the source code level with support for modern Java versions and multi-OS to monitor power consumption of hardware and software.&quot; It can report the energy consumption of individual methods, which is very useful for optimizing code and finding hotspots. We will cover it in a future post.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/661/1*ZW7UZbejdhFjOfPUoIhnaA.png" /><figcaption><em>Figure 2: Overview of topics that we covered in this post.</em></figcaption></figure><ol><li>There are efforts going in that direction. In Germany, the well-known environmental label <a href="https://www.blauer-engel.de/en/productworld/resources-and-energy-efficient-software-products">Blauer Engel</a> (blue angel) of the Federal Ministry for the Environment offers an &quot;environmental label for resource and energy-efficient software products.&quot; We will cover this in a future post.</li><li>0.040 Kilowatt-hours multiplied by my current electricity price of 0.44 CHF/Kilowatt-hour equals 0.0176 CHF. That&#39;s about 2 USD cents per hour. Not much, but it adds up over time with many devices.</li><li>The project used is <a href="https://github.com/Microservice-API-Patterns/LakesideMutual/tree/master">Lakeside Mutual</a>, a Spring Boot sample application we developed to demonstrate (microservice) API patterns.</li></ol><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=916b390593ec" width="1" height="1" alt=""><hr><p><a href="https://medium.com/growing-green-software/software-efficiency-and-energy-consumption-916b390593ec">Software Efficiency and Energy Consumption</a> was originally published in <a href="https://medium.com/growing-green-software">Growing Green Software</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Why Green Software Matters]]></title>
            <link>https://medium.com/growing-green-software/why-green-software-matters-b2f6789a82d2?source=rss-ff9700c896a8------2</link>
            <guid isPermaLink="false">https://medium.com/p/b2f6789a82d2</guid>
            <category><![CDATA[sustainable-software]]></category>
            <category><![CDATA[green-software]]></category>
            <category><![CDATA[climate-crisis]]></category>
            <category><![CDATA[sustainability]]></category>
            <category><![CDATA[software]]></category>
            <dc:creator><![CDATA[Mirko Stocker]]></dc:creator>
            <pubDate>Wed, 22 May 2024 19:05:40 GMT</pubDate>
            <atom:updated>2024-05-22T19:05:40.542Z</atom:updated>
            <content:encoded><![CDATA[<p><strong>Software is everywhere, and its development and operation consume an increasing share of our world’s energy and other resources.</strong> It’s the invisible engine that powers our modern world, from weather forecasting to streaming entertainment. But this incredible power comes at a cost — its development and operation consume increasing amounts of resources. While digitalization offers many possibilities, the environmental impact of software shouldn’t be ignored. Many industries, communities, societies, and nations are still at the beginning of their digitalization journeys, so the demand for software will continue to grow, as will its footprint on our planet. This trend is unsustainable. We know that climate change is a major global problem, and every discipline should contribute to solving it.</p><p><strong>But hold on, you might say, doesn’t digitalization also make us much more efficient and will even help us solve the climate crisis?</strong> I (partially) agree. Online meetings are less carbon-intensive than flying to in-person meetings.¹ Reading books on e-readers is often <a href="https://www.newscientist.com/lastword/mg24933211-400-is-it-better-for-the-planet-to-read-online-or-in-a-paper-format/">better for the environment</a>, as Mike Berners-Lee, a researcher who pioneered carbon accounting and footprinting has calculated: “You have to read the equivalent of at least 36 paperback books (bought new, then recycled) in e-book format before the paper saving outweighs the emissions embodied in the device.”² So, there are ways in which software and digital can help us reduce our carbon footprint. All is good then, right?</p><p>But we have to be careful not to fall into the trap of <a href="https://en.wikipedia.org/wiki/Rebound_effect_(conservation)">rebound effects</a> and <a href="https://en.wikipedia.org/wiki/Jevons_paradox">Jevons paradox</a>: when something becomes more efficient or cheaper, we tend to use or do more of it. For example, more fuel-efficient cars lead to <a href="https://www.sciencedirect.com/science/article/abs/pii/S2214629618300616">more kilometers being driven</a> overall. So just using more software and <a href="https://www.statista.com/statistics/871513/worldwide-data-created/">producing and transmitting exponentially more data</a> every year is not a solution in itself and certainly won’t heal our planet. Consider the size of websites: “[..] between June 2012 to June 2022, the median page weight increased by [..] 594%, or 1.7 MB for mobile page loads”, <a href="https://almanac.httparchive.org/en/2022/page-weight">Web Almanac</a> reports. Of course, telecommunication networks have also become more efficient. A <a href="https://www.nokia.com/about-us/news/releases/2020/12/02/nokia-confirms-5g-as-90-percent-more-energy-efficient/">study by Nokia</a> found that 5G is 90% more energy-efficient than 4G. So what about average Web page loading times? These <a href="https://www.nngroup.com/articles/the-need-for-speed/">have gone up</a>, so even our faster and more efficient networks can’t keep up with the increased page sizes — an excellent example of the Jevons paradox. There is a flip side to the increased use of digital solutions, so we should <strong>consider the sustainability of the software and how we use it</strong>. Because something is digital and seemingly lightweight, it doesn’t mean its environmental footprint is low and can be neglected.</p><p>A study by <a href="https://doi.org/10.1016/j.patter.2021.100340">Charlotte Freitag and colleagues</a> estimates that the <strong>global emissions of the Information Communication Technology (ICT) sector could already be as high as 3.9%</strong>. These calculations include components such as data centers, networks, and end-user devices. These ICT emissions cover the whole hardware lifecycle, from manufacturing and operations to disposal. During operation, the software has a significant influence on the amount of energy that is used. So, in addition to using electricity from sustainable sources, one step towards sustainability is to minimize the energy consumption of the underlying hardware caused by software, including processing (CPU, RAM), storage (hard or solid-state disks), and network devices. The EU recently published a technical report on the <a href="https://publications.jrc.ec.europa.eu/repository/handle/JRC135926">Energy Consumption in Data Centres and Broadband Communication Networks in the EU</a>, supporting these numbers. They estimate that “the combined energy use of data centres and telecommunication networks in the EU was 70–95 TWh in 2022, equivalent to 2.8–3.8% of total regional electricity use.” One country uses 18% of its electricity for data centers — can you guess which one?³</p><p>Several initiatives have sprung up in recent years, and terms such as Green/Sustainable Software or IT are entering the mainstream of the software community through conference talks, articles in professional magazines, blog posts by major cloud providers, and so on. The vision of the <a href="https://greensoftware.foundation/manifesto">Green Software Foundation</a>, for instance, is to “change the culture of building software across the tech industry, so sustainability becomes a core priority to software teams, just as important as performance, security, cost and accessibility.”</p><p>With this blog, I want to contribute to reaching this goal. Hi 👋, my name is Mirko. Computers, particularly software, have fascinated me for as long as I can remember. I have been in the industry for a quarter of a century now and worked on a broad range of software systems. I love programming languages and tinkering with new technologies, something that our industry is very efficient in churning out regularly.⁴ Lately, however, I have been thinking more and more about the sustainability of our profession. I read books and many research papers, tried out tools, listened to podcasts, and discovered that there is already a lot going on, more than I imagined. That’s awesome, but the problem is also enormously big, and it isn’t easy to figure out where to start. For example, do we even know how much energy running software consumes? How clean or dirty is that energy? <a href="https://www.theguardian.com/environment/green-living-blog/2010/oct/21/carbon-footprint-email">How much carbon emissions does an e-mail cause</a> (transmitting and storing it — probably indefinitely — in at least two accounts)? What about the hundreds of gigabytes⁵ of photos accumulating on our devices and backed up to the cloud?</p><p>I fear I don’t have answers to all these questions, but I want to try to figure it out and take you, dear reader, along my journey to discover how we can <em>grow green software</em>. I have planned a colorful bouquet⁶ of posts, some concerning more fundamental topics like emissions or measurements, to summaries of research papers to find out what we actually know and don’t know as well as experience reports with various tools and demos of APIs that we can use to make our software greener. If you are developing software and are concerned about the environment, I hope you will find this blog interesting and inspiring.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/687/1*XT8JPQdTKb0NpOu96KkoDw.png" /><figcaption><em>Figure 1: Overview of topics that we (briefly) touched in this post. This mind-map will grow with future posts.</em></figcaption></figure><p>Subscribe to this blog and let me know your questions and topics you’d like to see covered. You can also find me on <a href="https://mastodon.social/@stocker">@stocker@mastodon.social</a> and <a href="https://www.linkedin.com/in/misto/">LinkedIn</a>.</p><p>A big thank you to my two colleagues <a href="https://medium.com/@docsoc">Olaf</a> and <a href="https://stefan-kapferer.medium.com/">Stefan</a> for their feedback and encouragement, which helped me to start blogging again.</p><ol><li>Such direct one-to-one comparisons can be misleading. The alternative to online meetings isn’t always flying; sometimes, you just have to go to the offitheirce next door. And don’t we have too many meetings anyway?</li><li>In case “Berners-Lee” rings a bell, he’s the brother of Tim Berners-Lee, who invented the World Wide Web.</li><li>It is Ireland, where many “big tech” companies such as Amazon, Facebook, and Google are based.</li><li>What’s also fascinating is that with every new trend, such as cryptocurrencies or artificial intelligence, the demand for energy and hardware increases tremendously. Apparently, <a href="https://www.wsj.com/tech/ai/sam-altman-seeks-trillions-of-dollars-to-reshape-business-of-chips-and-ai-89ab3db0">OpenAI’s Sam Altman is trying to raise $7 trillion</a> (yes, that number has 12 zeros) for a new AI hardware company.</li><li>Since having children, the number of photos has just exploded. Speaking of which, this blog deliberately avoids decorative photos that only waste bandwidth.</li><li>I promise not to go overboard with gardening metaphors, although I do enjoy gardening. I will also try to keep those footnotes in check…</li></ol><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=b2f6789a82d2" width="1" height="1" alt=""><hr><p><a href="https://medium.com/growing-green-software/why-green-software-matters-b2f6789a82d2">Why Green Software Matters</a> was originally published in <a href="https://medium.com/growing-green-software">Growing Green Software</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Return to EuroPLoP — API Refactoring Patterns]]></title>
            <link>https://medium.com/olzzio/return-to-europlop-api-refactoring-patterns-217787f90930?source=rss-ff9700c896a8------2</link>
            <guid isPermaLink="false">https://medium.com/p/217787f90930</guid>
            <category><![CDATA[design-patterns]]></category>
            <category><![CDATA[writer-workshop]]></category>
            <category><![CDATA[api]]></category>
            <category><![CDATA[refactoring]]></category>
            <category><![CDATA[conference-report]]></category>
            <dc:creator><![CDATA[Mirko Stocker]]></dc:creator>
            <pubDate>Thu, 13 Jul 2023 15:28:02 GMT</pubDate>
            <atom:updated>2023-07-17T12:48:54.153Z</atom:updated>
            <content:encoded><![CDATA[<h3>Return to EuroPLoP — API Refactoring Patterns</h3><figure><img alt="API Refactoring to Patterns paper presented at EuroPLoP 23" src="https://cdn-images-1.medium.com/max/1024/1*2AO5kL6zC6KGz8GnANjCyA.png" /></figure><p><a href="https://europlop.net/content/conference">EuroPLoP</a> is one of the go-to conferences on all things patterns; our <a href="https://api-patterns.org/">“Patterns for API Design”</a> benefitted a lot from EuroPLoP writers’ workshops 2017 to 2020. All five co-authors of the <a href="https://api-patterns.org/book/">book</a> attended this year’s conference with follow-up work. For instance, <a href="https://www.ost.ch/de/person/olaf-zimmermann-1702">Olaf</a> and I brought eight API refactorings with them, and a focus group aimed at exchanging experience with pattern education.</p><p>In this post, I will share the results of our writers workshop and Olaf covers the <a href="https://medium.com/olzzio/return-to-europlop-focus-group-on-pattern-visualization-and-teaching-2f51842ce248">“Pattern Visualization in Teaching and Consulting” focus group in a separate post</a>.</p><h4>Writer’s Workshop A</h4><p>Unlike other conferences, EuroPLoP focuses on improving papers instead of only presenting them. <a href="https://hillside.net/conferences/shepherding">Shepherding</a> and <a href="https://en.wikipedia.org/wiki/Authors%27_conference#Writers&#39;_workshop">writers’ workshops</a> are the two primary ways of doing so (so is PC member/peer review feedback, which is more common). Shepherding¹ happened before the conference (for about 3 months); the writers’ workshops form the heart of the conference. Authors read each other’s papers before the conference and then discuss them on-site, following a very specific protocol.</p><p>Olaf and I got the paper “API Refactoring to Patterns” workshopped.² It contains the first eight entries from our <a href="https://interface-refactoring.github.io/">Interface Refactoring Catalog</a> that has been emerging since 2020. The following caption from the website lists the refactorings that we collected on the left and also calls out the various smells they remove (we gave “Add Wish List” top priority in the workshop):</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*GH2nNIXDnLvMeKGM.png" /><figcaption><strong>IRC: Smell Browser View</strong></figcaption></figure><p>The paper draft was well received, and we got a lot of helpful and constructive feedback to improve it further. The overall impression was that it is well-written, that the figures aided understandability and that the examples were chosen and explained well. One aspect that we will certainly improve is to clarify the target audience of the refactorings, explain patterns icon usage in figures even more, and highlight which refactorings can be applied in a fully backward-compatible way (and which ones require additional effort to keep existing clients working).³</p><p>The other draft papers in the workshop were:</p><ul><li>“Design Patterns for Approval Processes”</li><li>“Tool Support for Learning Architectural Guidance Models and Pattern Mining from Architectural Design Decision Models”</li><li>“Deployment Tracking and Exception Tracking Patterns: More monitoring design patterns for cloud-native applications”</li><li>“API Rate Limit Pattern”</li></ul><p>There were six more workshops running in parallel, covering a diverse range of topics, including pattern writing with and for ChatGPT, microservices patterns and their effect on extensibility, patterns for contextual organizational change, community-driven learning, flexible learning spaces for hybrid education, anti-patterns related to mismanagement of NFRs.</p><p>Many of the workshopped papers will eventually become available online in the ACM Digital Library; see, for instance, <a href="https://dl.acm.org/doi/10.1145/3424771.3424822">“Interface Responsibility Patterns: Processing Resources and Operation Responsibilities”</a>. The authors copy of that paper (PDF) is publicly available for <a href="http://eprints.cs.univie.ac.at/6520/1/MAP-EuroPlop2020aPaper.pdf">download</a>.</p><h4>What’s Next?</h4><p>Links to previous editions and other patterns conferences can be found <a href="https://www.europlop.net/past-conferences/">here</a>.</p><blockquote>Please consider a submission to EuroPLoP 2024 (due in January/February, so there is time)… coaching and tools for beginners are available. For instance, have a look at the “Pattern Writing” section on <a href="https://www.europlop.net/patterns/">this page</a>.</blockquote><p>See <a href="https://medium.com/olzzio/return-to-europlop-focus-group-on-pattern-visualization-and-teaching-2f51842ce248">Olaf’s story on the results of the “Pattern Visualization in Teaching and Consulting” focus group</a>.</p><h4>Notes</h4><ol><li>Shepherding is pattern community lingo for coaching w.r.t. technical writing and patterns.</li><li>Being workshopped is pattern lingo again… here is a final one: the authors of the paper that is currently discussed morph into “flies on the wall” for most of the discussion (and flies do not speak!).</li><li>We thank the workshop participants Carlos Albuquerque, Filipe F. Correia, Daniel Lübke, Cesare Pautasso, Souhaila Serbout, and Uwe Zdun for their valuable feedback!</li></ol><p><em>Originally published at </em><a href="https://ozimmer.ch/misc/2023/07/05/EuroPLoP2023.html"><em>https://ozimmer.ch</em></a><em> on July 5, 2023.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=217787f90930" width="1" height="1" alt=""><hr><p><a href="https://medium.com/olzzio/return-to-europlop-api-refactoring-patterns-217787f90930">Return to EuroPLoP — API Refactoring Patterns</a> was originally published in <a href="https://medium.com/olzzio">ZIO’s Blog</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Notes from “The Architecture and Modeling Learning Event”, Part 1]]></title>
            <link>https://medium.com/olzzio/notes-from-the-architecture-and-modeling-learning-event-part-1-1521704cc0ed?source=rss-ff9700c896a8------2</link>
            <guid isPermaLink="false">https://medium.com/p/1521704cc0ed</guid>
            <category><![CDATA[domain-storytelling]]></category>
            <category><![CDATA[ddd]]></category>
            <category><![CDATA[conference]]></category>
            <category><![CDATA[api-design]]></category>
            <category><![CDATA[architectural-principles]]></category>
            <dc:creator><![CDATA[Mirko Stocker]]></dc:creator>
            <pubDate>Fri, 02 Jun 2023 09:01:29 GMT</pubDate>
            <atom:updated>2023-06-02T09:06:58.018Z</atom:updated>
            <content:encoded><![CDATA[<h4>Vaughn Vernon Signature Series Live in Action (May 12, 2023)</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/900/0*4iLXBWAiZGx4MTgr.jpg" /></figure><p>The authors of Vaughn’s book series at Addison Wesley teamed up for a free online conference. <a href="https://www.wps.de/en/news/appointments/architecture-and-modeling-learning-event">“The Architecture and Modeling Learning Event”</a> covered not only software architecture, domain modeling and API design but also business strategy and modeling, product management and loosely coupled messaging. The morning talks are featured here, <a href="https://medium.com/olzzio/notes-from-the-architecture-and-modeling-learning-event-part-2-28287a7f13b0">Part 2</a> covers the afternoon.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*byBN5cBVpGfrzGvP.jpg" /></figure><p>Note that these are personal impressions; we do not aim to be complete.</p><h3>“Domain Storytelling — Understanding Your Users by Drawing Pictures”</h3><p>What a nice start to the day with stories at the fire pit told by <a href="https://hschwentner.io/">Henning Schwentner</a>! He introduced us to <a href="https://domainstorytelling.org/">Domain Storytelling</a>, a collaborative modeling technique comprising two main elements:</p><blockquote>Domain Storytelling = Pictographic Language + Workshop Format.</blockquote><p>The pictographic language is deliberately kept simple (actors-activities-work objects), so it is easy to pick up and one doesn’t get lost in the details of choosing among different arrows and forms of boxes. This simplicity is essential because while the domain experts tell their stories, the listeners (or artists?) draw these pictures on the fly in the workshop, applying <a href="https://en.wikipedia.org/wiki/Active_listening">active listening</a> to minimize misunderstandings.</p><h3>“The Idea of Product Architecture”</h3><p><a href="https://www.linkedin.com/in/steffen-h-4a1463180/">Steffen Hartmann</a> ‘s talk was all about product-centricity. Products are a vehicle for value exchange, meaning customers get value (for instance, new capabilities) and companies get money. So thinking about products helps to align the technology with the business side. Product architecture then provides a shared mental model that allows:</p><ol><li>“The arrangement of the functionality of a product.</li><li>The mapping from product functionality and features and their connection between each other and to business outcome.</li><li>The specification of the required dependencies and the interaction between technology and product.”</li></ol><p>We learned that this is not a new methodology, nor a roadmap, but rather a high-level representation of what’s important. This representation can serve as a strategic tool and starting point for domain modeling.</p><h3>“Adaptive Socio-Technical Systems with Architecture for Flow”</h3><p><a href="https://www.susannekaiser.net/">Susanne Kaiser</a> asked, “How to design systems that can evolve and thrive in the face of constant change?” She suggested a combination of approaches:</p><ol><li>Understanding the business landscape, for example with <a href="https://en.wikipedia.org/wiki/Wardley_map">Wardley Maps</a>.</li><li><a href="https://teamtopologies.com/">Team topologies</a> to align teams for a fast flow of feature deliveries, supported for instance by platform teams.</li><li><a href="https://socadk.github.io/design-practice-repository/activities/DPR-StrategicDDD.html">Strategic Domain-Driven Design (DDD)</a>, Bounded Contexts in particular to decompose big balls of mud.</li></ol><p>This was a highly-paced talk supported by fantastic illustrations — definitely looking forward to the release of Susanne’s book <a href="https://www.amazon.com/Adaptive-Systems-Domain-Driven-Wardley-Topologies/dp/0137393032">“Adaptive Systems With Domain-Driven Design, Wardley Mapping, and Team Topologies: Architecture for Flow”</a>.</p><h3>“A Conversation on Continuous Architecture”</h3><p><a href="https://twitter.com/eoinwoodz">Eoin Woods</a> talked about how architecture has become much more fluid and faster evolving in the past decade, with shorter release cycles, clouds, microservices and so on. But how can an overall architecture of a system be maintained without slowing down or blocking autonomously acting teams?</p><p>Traditional upfront software architecture might be of less value today, but of course, architecture is still needed, for example, there are overarching quality attributes (security, scalability), stakeholder concerns to balance and complex tradeoffs to make.</p><blockquote><a href="https://continuousarchitecture.com/">Continuous Architecture</a> is one of the emerging responses to these challenges.</blockquote><p>Continuous means that it’s not a one-off architecture but a stream of decisions.¹ The book’s six “Principles of Continuous Architecture” include:</p><ul><li>Architecting products² and</li><li>Delaying design decisions until absolutely necessary.³</li></ul><p>The four other are:</p><ul><li>Focus on quality attributes</li><li>Architect for change</li><li>Architect for build, test, deploy, and operate</li><li>Model the organization of your teams.</li></ul><h3>“The Impact of Managed Services on Modern Software Architecture”</h3><p><a href="https://twitter.com/JoeEmison">Joe Emison</a> opened his talk with a slide that read:</p><blockquote>There are no continuing education requirements in software development.</blockquote><p>You may be wondering, and I certainly was, how this relates to the managed services mentioned in the title of this talk. Joe continued to talk about the impact that managed services have on how we build software. Managed services, for example, serverless offerings such as AWS Lambda or DynamoDB, have the advantage that server operations and preserving the uptime of services are taken care of by the cloud providers. Using managed services, scaling infinitely and never going down can make teams more productive.</p><p>The catch is that teams must learn and understand how these new technologies work to take full advantage of them. And that brings us back to the opening slide: Continuing education is essential, even if it is not officially mandated, for instance, by professional associations. Joe’s upcoming book <a href="https://www.amazon.com/Serverless-Game-Changer-Addison-wesley-Signature/dp/0137392621">“Serverless As a Game Changer: How to Get the Most Out of the Cloud”</a> teaches us how to use managed cloud services effectively.</p><h3>“Balancing Coupling in Software Design”</h3><p><a href="https://twitter.com/vladikk">Vlad Khononov</a> ‘s talk was about coupling. Coupling often has a bad reputation and everybody knows that it’s not good, so we want to decouple everything. For example, we might want to break large things apart into smaller units that can evolve independently. But without any coupling, there are no relationships between individual parts of a system. So what’s essential about (de-)coupling is that it doesn’t prevent us from making the changes that we need.</p><blockquote>Coupling defines the relationship between components and limits components’ degrees of freedom.</blockquote><p>Vlad continued to present different kinds of coupling, which is the topic of his upcoming book: <a href="https://www.amazon.com/Balancing-Coupling-Software-Design-Addison-Wesley-ebook/dp/B09RV3Z3TP">“Balancing Coupling in Software Design: Successful Software Architecture in General and Distributed Systems”</a>.</p><p><em>Mirko hands over the note-taking to Olaf at this point, see </em><a href="https://medium.com/olzzio/notes-from-the-architecture-and-modeling-learning-event-part-2-28287a7f13b0"><em>Part 2</em></a><em>.</em></p><h3><strong>Notes</strong></h3><ol><li>Recorded using <a href="https://ozimmer.ch/practices/2023/04/03/ADRCreation.html">Architectural Decision Records (ADRs)</a>?</li><li>Does that ring a bell? Hint: see one of the previous talk summaries. 😃</li><li>Maybe to the <a href="https://wirfs-brock.com/blog/2011/01/18/agile-architecture-myths-2-architecture-decisions-should-be-made-at-the-last-responsible-moment/">most responsible moment</a>?</li></ol><p><em>Originally published at </em><a href="https://ozimmer.ch/modeling/2023/05/26/ArchitectureandModelingLearningEvent.html"><em>https://ozimmer.ch</em></a><em> on May 26, 2023.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=1521704cc0ed" width="1" height="1" alt=""><hr><p><a href="https://medium.com/olzzio/notes-from-the-architecture-and-modeling-learning-event-part-1-1521704cc0ed">Notes from “The Architecture and Modeling Learning Event”, Part 1</a> was originally published in <a href="https://medium.com/olzzio">ZIO’s Blog</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>