Energy-efficient programming with Go and beyond

Hungry AI

Training neural networks burns large amounts of energy. The longer you train a neural network for its task, the more accurately it will work later on. But, due to the computing power required for this, in extreme cases, you could emit even more CO2 than five cars in their entire service life [14]. If you train a neural network beyond what is actually necessary for the task, you are wasting a great deal of energy. An environmentally harmful AI like this is known as a red AI.

In addition, many scientists in AI research rely on Python. They resort to some tricks to speed up the computations. One of them is using the Cython compiler, which converts Python code into its C counterpart. In addition, many Python libraries are implemented directly in C. If you develop AI models, you need to design and train them to be as energy-efficient as possible. If you use pre-configured examples, go for variants that are already energy-efficient.

Strengths and Weaknesses

You can only use a programming language efficiently if you know its advantages and disadvantages. For example, the source code of some scripting languages is quite short. If the interpreter processes these instructions quickly, the scripts run as efficiently as their compiled counterparts and are also far easier to maintain.

In addition, some languages are tailored for very specific purposes. For example, PHP is primarily used to create dynamic web applications. Only a few programmers are likely to use it for complex numerical analysis. And if you need numerical analysis, the Julia functional programming language is a good choice. Today, it is mainly server-based services and command-line programs that are created in Go. The language offers pretty efficient string manipulations, but some tasks that execute in parallel can be solved efficiently with Goroutines.

Because Go has only been around for a few years, the programs written in it draw on libraries that are also quite young. The situation is different with established programming languages such as C, Python, or PHP. All too often, inefficient legacy systems lurk in software developed years ago. Refactoring and retiring old libraries can help save energy. The oCIS developers used the reimplementation of their file sharing platform to dump some legacy material. For instance, unlike ownCloud, oCIS does not require a classic database.

If You Perform Your Own Measurements …

At the end of the day, only your own measurements will help you find out how much energy is going to which parts of your code. These measurements should take place during the development phase and in real time. On Linux, for example, you can check energy consumption using Intel's RAPL interface.

In the case of Go, however, you need to use auxiliary applications to check energy consumption, because Go programs lack this capability. A proposal for a function that checks energy consumption, dating back to 2019, was rejected by the developers because, in their view, neither operating systems nor CPUs provide precise consumption values for the short pieces of code that are executed [15]. At the time of going to press, there were no libraries that Go developers could use to measure energy consumption.

But Go at least comes with some debugging functions in its standard library. For example, the debug package contains a function that you can use to trigger garbage collection. The ReadMemStats() function prints information about memory usage from the runtime package, and you can generate your own metrics with the metrics package.

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.

  • Intel Atom Platform: Smaller, More Energy-Efficient

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

  • Tracking Energy Usage

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

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