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

  1. "Energy Efficiency across Programming Languages": https://sites.google.com/view/energy-efficiency-languages/
  2. TinyGo: https://tinygo.org
  3. "Energy Efficiency in Programming Languages (Benchmarks)": https://github.com/greensoftwarelab/Energy-Languages
  4. oCIS: https://owncloud.dev/ocis/
  5. "Profiling Go Programs": https://go.dev/blog/pprof
  6. cdperf: https://github.com/owncloud/cdperf
  7. k6: https://k6.io/open-source/
  8. Benchmarks: https://pkg.go.dev/testing#hdr-Benchmarks
  9. Effective Go: https://go.dev/doc/effective_go
  10. GoCV: https://pkg.go.dev/gocv.io/x/gocv
  11. Drone: https://www.drone.io
  12. Gocache: https://github.com/eko/gocache
  13. "A Guide to the Go Garbage Collector": https://go.dev/doc/gc-guide
  14. "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/
  15. "proposal: testing: report energy consumption figures": https://github.com/golang/go/issues/30108
  16. "Energy Efficiency across Programming Languages, Results": https://sites.google.com/view/energy-efficiency-languages/results

Buy this article as PDF

Express-Checkout as PDF
Price $2.95
(incl. VAT)

Buy Linux Magazine

SINGLE ISSUES
 
SUBSCRIPTIONS
 
TABLET & SMARTPHONE APPS
Get it on Google Play

US / Canada

Get it on Google Play

UK / Australia

Related content

  • Blue Angel Eco-Label

    Germany created Blue Angel, the world's first eco-label for software, back in 2000. The methodology behind Blue Angel could serve as a model for other countries as governments turn their attention to the environmental impact of software.

  • Sustainability by Design

    Sustainability studies for the IT industry often ignore the contributions of software. This article explores what developers and admins can do to create and maintain more energy-efficient systems.

  • Energy Study

    It's getting easier to measure the environmental impact of software. A new study suggests criteria for determining how the choice of software impacts resource use.

  • Tracking Energy Usage

    Want to bring down your electric bill? Investigate your favorite household appliances with a consumption meter and a Raspberry Pi.

  • Intel Atom Platform: Smaller, More Energy-Efficient

    Intel's reworked Atom platform enhances netbooks and Internet devices with integrated graphics and memory controller.

comments powered by Disqus
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.

Learn More

News