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.
« Previous 1 2 3 4 Next »
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.