Toward Sustainable Software for HPC, Cloud, and AI Workloads

Software applications are considerable consumers of computing resources, leading to a significant carbon footprint. Recent estimates suggest that Information Technology accounts for approximately 11% of global energy consumption. Projections indicate that by 2030, data centers alone could account for 3–13% of global electricity use, a stark increase from the 1% recorded in 2010, propelled by escalating demands and emerging trends like large-scale AI workloads. The software industry is responsible for about 3% of global carbon emissions, which is very close to that associated with the aviation industry, and it could deteriorate if left unaddressed. Researchers have estimated that training a single machine learning algorithm for natural language processing may emit as much CO2e (carbon dioxide equivalent) as a small town with 120 homes would emit in a year. Another study reported that AI workloads in data centers made up 15% of Google’s total electricity consumption, which was 18.3 terawatt hours (equivalent to the City of Atlanta’s annual power consumption) in 2021.

Code Smells

Figure 1: Code smell distribution across 31
popular open-source applications.  
The quest for efficient and dependable design and development of software in the aggressively competitive and rapidly evolving environment brings unprecedented challenges. Emergent complications stem from the intricate, collaborative, and decentralized methodology inherent in modern software development, compounded by an escalated demand for novel features and a compressed timeframe to market. These factors render contemporary software susceptible to “code smells,” which are defined as characteristics in software source code indicating a deeper, underlying issue. Figure 1 illustrates a sampling of code smells and their distribution across 31 popular open-source applications analyzed in our recent work. Software engineers constantly strive to restructure their code to eliminate the code smells, a mechanism popularly known as refactoring. While current code refactoring practices prioritize the elimination of smells that impact software quality and usability, there has been a significant oversight regarding the analysis of the impact of such refactorings on energy consumption and carbon footprint, a critical issue related to code smells. Research has demonstrated that certain code smells contribute to excessive resource consumption in software. However, the potential effects of code smell refactoring practices on software carbon footprint have only been sparsely studied.

Energy Smells

Certain categories of code smells can lead to a substantial increase in energy consumption (thus also referred to as energy smells), mainly due to inefficient utilization of computing resources. However, it is crucial to note that not all code smell refactorings inevitably lead to enhanced resource utilization. Intriguingly, certain refactoring techniques and tools can inadvertently introduce new complexities. For instance, refactoring the long class smell involves decomposing a large class into smaller ones. This segmentation necessitates increased interclass communication, burdening the CPU with additional tasks, which in turn escalates CPU usage. Similar implications can occur when refactoring long method and long parameter list smells, thereby exacerbating the application’s CPU and memory consumption, hence increasing the carbon footprint. Previous research in this area has predominantly focused on the impact of code smell refactoring on resource consumption within the context of smartphone applications. However, these prior investigations have often been narrowly focused, considering only the isolated impact of a select few code smells and disregarding the potential cumulative effects of refactoring a broader array of smells. Furthermore, these studies were limited in scope, examining only a small pool of applications, thus limiting their ability to form broad-based conclusions or predictions regarding their influence on energy consumption and CO2 emissions.

Energy-aware Code Smell Refactoring

Figure 2: Impact of intelligent/selective code smell
refactoring on application resource consumption.

In our recent work, we performed a detailed analysis of 16 distinct code smells within 31 real-world open-source applications in Java and Python. To ensure the precision of our performance analysis, we gathered data concerning resource usage at the method level. Through this examination, we not only established a foundation for the relationship between code smells and resource consumption but also revealed the significant influence of batch refactoring of code smells on CPU and memory usage and, consequently, energy consumption. Our research provided evidence that several common refactoring techniques employed for dealing with certain types of code smells, such as god classgod method, long parameter, and specific instances of type checking, can inadvertently increase CPU and memory usage. This, in turn, escalates the overall energy consumption of the application. We demonstrated that a selective approach to code smell refactoring could result in considerable resource savings. For certain applications, our approach yielded a reduction of up to 39% in CPU utilization and a decrease of up to 48% in memory utilization (Figure 2). These findings underscore the potential of our proposed approach to yield significantly energy-efficient software.

Opportunities & Future Research Directions

We need a comprehensive analysis of 100s of code smells and other coding malpractices in different programming languages (especially for Java, Python, and C++, which are widely used in HPC, Cloud, and AI workload programming), and should investigate the impact of their refactoring on application energy consumption and carbon footprint. This analysis should include identifying code smells that impact resource utilization and understanding the relationships between code smell refactoring and energy consumption. Through this research, the community would gain a deeper understanding of the impact of code smell refactoring on energy consumption, which can help inform the development of low-carbon software systems.

We need to develop pre-trained AI-based models for energy-aware code smell refactoring. These models should be trained on large datasets of real-world software applications to predict the impact of code smell refactoring on energy consumption and carbon emissions. This will enable software engineers to accurately analyze and optimize energy consumption and carbon emissions in software applications due to code smells and other coding malpractices.

Depending on the goal of the application developers, these developed models will enable intelligent selection of which smells should be refactored together and which ones should not be refactored. If the primary goal is easy-to-maintain code, then all smells can be refactored. In that case, these models can provide the developers with an estimation of the expected change in resource utilization after batch refactoring. If the concern is not only easy maintenance but also resource consumption of the application, these models will help the developers intelligently decide which smells to refactor jointly to minimize the energy consumption and carbon footprint of the application.

The outcomes of research in this area have the potential to revolutionize energy optimization in software systems by offering a comprehensive framework that addresses the complex challenges of code smell refactoring and energy consumption. Through the integration of sophisticated machine learning models and a rigorous validation process, it can pave the way for sustainable and low-carbon software development practices, benefiting both the software industry and the environment at large.



Comments

Popular posts from this blog

Spring'24 Seminar Course on Green Computing and Sustainability

Reading List for My Seminar Course on "Green Computing and Sustainability"