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
-
Thousands of Linux Servers Infected with Stealth Malware Since 2021
Perfctl is capable of remaining undetected, which makes it dangerous and hard to mitigate.
-
Halcyon Creates Anti-Ransomware Protection for Linux
As more Linux systems are targeted by ransomware, Halcyon is stepping up its protection.
-
Valve and Arch Linux Announce Collaboration
Valve and Arch have come together for two projects that will have a serious impact on the Linux distribution.
-
Hacker Successfully Runs Linux on a CPU from the Early ‘70s
From the office of "Look what I can do," Dmitry Grinberg was able to get Linux running on a processor that was created in 1971.
-
OSI and LPI Form Strategic Alliance
With a goal of strengthening Linux and open source communities, this new alliance aims to nurture the growth of more highly skilled professionals.
-
Fedora 41 Beta Available with Some Interesting Additions
If you're a Fedora fan, you'll be excited to hear the beta version of the latest release is now available for testing and includes plenty of updates.
-
AlmaLinux Unveils New Hardware Certification Process
The AlmaLinux Hardware Certification Program run by the Certification Special Interest Group (SIG) aims to ensure seamless compatibility between AlmaLinux and a wide range of hardware configurations.
-
Wind River Introduces eLxr Pro Linux Solution
eLxr Pro offers an end-to-end Linux solution backed by expert commercial support.
-
Juno Tab 3 Launches with Ubuntu 24.04
Anyone looking for a full-blown Linux tablet need look no further. Juno has released the Tab 3.
-
New KDE Slimbook Plasma Available for Preorder
Powered by an AMD Ryzen CPU, the latest KDE Slimbook laptop is powerful enough for local AI tasks.