Energy-efficient programming with Go and beyond
… Make Sure You Measure Something Meaningful
When measuring energy consumption, there is also the question of which program paths your code executes. As Freitag points out, errors are not allowed to occur during the measurements. Errors often cause an operation to abort and the program to generate less load.
You also need to measure under real-life conditions if possible. Developers sometimes get in a hurry and simplify the test environment in ways that could affect the measurement results. During their measurements, the oCIS developers resorted to the simplest authentication method (Basic Authentication). As a result, the system repeatedly decoded the same security token in a computationally intensive way. After switching to OpenID Connect, the entire system was measurably faster.
Energy measurements need to cover as many of the software parts as possible. Freitag recommends identifying several practical use cases and testing them. With file sharing software, it makes a difference whether a company shares only a few very large files or an extremely large number of small files. You need to take an average value into account in your measurements.
You can read the results of the SLE study online if you are interested [16], and you will find the test programs on GitHub [3]. OCIS developers are hoping to disclose their comparisons of ownCloud, oCIS, and Nextcloud. At the time this article was written, an internal validation was still in progress. But you can measure the performance yourself with the open source cdperf
tool.
Conclusions
The C, Pascal, and Go languages help developers achieve an optimal compromise between runtime, memory usage, and energy efficiency – at least that's what the SLE study suggests. Nevertheless, the Go compiler does not automatically produce energy-efficient applications. Too many other factors play a role.
According to Freitag, it is primarily the software architecture that influences the performance and, indirectly, the energy efficiency of an application. For example, communication among Internet services can consume more energy than saving a file. In addition, efficient implementation is important, and that – in turn – depends on the use case.
There is no doubt that it is worthwhile to get started with resource-efficient programming now. See the box entitled "Tips for Energy-Efficient Implementation" for some tips on greener coding.
Tips for Energy-Efficient Implementation
- All stakeholders need to keep energy efficiency in mind at all times during the development process.
- Go for a compiler language such as Go, C, or Rust rather than an interpreted language such as Python.
- Choose a software architecture that efficiently solves the task at hand. For example, a blog should not consist of numerous microservices constantly communicating with each other.
- Use efficient algorithms. Eliminate costly polling and avoid unnecessary loops. Using a profiler can reveal inefficient pieces of code.
- If you use third-party libraries and code, extend your testing to ensure the third-party components also run as efficiently as possible.
- Reduce the volume of data to be processed, for example, by making do with smaller preview images, and store intermediate results in a cache.
- Make trade-offs in accuracy. A neural network does not always have to deliver perfect results. Integers are more efficient than floating point numbers as counter variables in loops.
- Use low-power specialist hardware such as AI accelerators whenever possible.
- As part of the testing process, measure power requirements, or at least performance, continuously. Optimize the inefficient operations identified in the process.
- Pay attention to the energy consumption of the software pipeline. Does the CI system really have to rebuild the software once an hour outside working hours and run through all the tests?
Infos
- "Energy Efficiency across Programming Languages": https://sites.google.com/view/energy-efficiency-languages/
- TinyGo: https://tinygo.org
- "Energy Efficiency in Programming Languages (Benchmarks)": https://github.com/greensoftwarelab/Energy-Languages
- oCIS: https://owncloud.dev/ocis/
- "Profiling Go Programs": https://go.dev/blog/pprof
- cdperf: https://github.com/owncloud/cdperf
- k6: https://k6.io/open-source/
- Benchmarks: https://pkg.go.dev/testing#hdr-Benchmarks
- Effective Go: https://go.dev/doc/effective_go
- GoCV: https://pkg.go.dev/gocv.io/x/gocv
- Drone: https://www.drone.io
- Gocache: https://github.com/eko/gocache
- "A Guide to the Go Garbage Collector": https://go.dev/doc/gc-guide
- "Training a single AI model can emit as much carbon as five cars in their lifetimes": https://www.technologyreview.com/2019/06/06/239031/training-a-single-ai-model-can-emit-as-much-carbon-as-five-cars-in-their-lifetimes/
- "proposal: testing: report energy consumption figures": https://github.com/golang/go/issues/30108
- "Energy Efficiency across Programming Languages, Results": https://sites.google.com/view/energy-efficiency-languages/results
« Previous 1 2 3 4
Buy this article as PDF
(incl. VAT)
Buy Linux Magazine
Subscribe to our Linux Newsletters
Find Linux and Open Source Jobs
Subscribe to our ADMIN Newsletters
Support Our Work
Linux Magazine content is made possible with support from readers like you. Please consider contributing when you’ve found an article to be beneficial.
News
-
Ubuntu 24.04 Comes with a “Flaw"
If you're thinking you might want to upgrade from your current Ubuntu release to the latest, there's something you might want to consider before doing so.
-
Canonical Releases Ubuntu 24.04
After a brief pause because of the XZ vulnerability, Ubuntu 24.04 is now available for install.
-
Linux Servers Targeted by Akira Ransomware
A group of bad actors who have already extorted $42 million have their sights set on the Linux platform.
-
TUXEDO Computers Unveils Linux Laptop Featuring AMD Ryzen CPU
This latest release is the first laptop to include the new CPU from Ryzen and Linux preinstalled.
-
XZ Gets the All-Clear
The back door xz vulnerability has been officially reverted for Fedora 40 and versions 38 and 39 were never affected.
-
Canonical Collaborates with Qualcomm on New Venture
This new joint effort is geared toward bringing Ubuntu and Ubuntu Core to Qualcomm-powered devices.
-
Kodi 21.0 Open-Source Entertainment Hub Released
After a year of development, the award-winning Kodi cross-platform, media center software is now available with many new additions and improvements.
-
Linux Usage Increases in Two Key Areas
If market share is your thing, you'll be happy to know that Linux is on the rise in two areas that, if they keep climbing, could have serious meaning for Linux's future.
-
Vulnerability Discovered in xz Libraries
An urgent alert for Fedora 40 has been posted and users should pay attention.
-
Canonical Bumps LTS Support to 12 years
If you're worried that your Ubuntu LTS release won't be supported long enough to last, Canonical has a surprise for you in the form of 12 years of security coverage.