Optimizing Linux performance using Stacer

The performance of a Linux system is impacted by several factors—various configurations, settings, and attributes all come into play. Linux performance is typically measured by how quickly the system can execute commands or run programs.

This article will cover practical concepts that can help speed up a Linux machine. We will examine Linux performance through the following aspects:

  • Power consumption
  • I/O scheduler optimization
  • CPU scalability
  • Performance monitoring tools like Stacer

Those new to Linux and users with limited knowledge about it might need to realize what impacts its performance and how to measure or boost its efficiency. Depending on your individual needs or specific use case, some methods will be more advantageous than others.

Whether using Linux as a primary desktop operating system or as a secondary server for another platform, it’s important to understand how these options impact the user experience with this OS.

Why optimization matters

Optimizing Linux performance is essential for several reasons:

  • It boosts the overall speed and efficiency of the system, which in turn enhances user experience and makes the system better equipped to handle demanding tasks.
  • Optimization reduces the strain on system resources such as CPU and memory, which can improve stability and prevent system slowdowns or crashes.
  • It can extend the lifespan of the system by reducing wear and tear on hardware components.
  • Optimization helps the system run as efficiently and securely as possible.

Monitoring your Linux performance using Stacer

You will need a Linux distribution before starting this tutorial.

Stacer is a tool used for optimizing Linux that deletes unwanted cache and sorting processes by looking at memory usage and CPU. Stacer reveals how services and processes are performing and which user is executing the processes. It is a must-have if your goal is to efficiently optimize your Linux system.

To install Stacer, start by adding the Stacer repository:

$ sudo add-apt-repository ppa:oguzhaninan/stacer

Next, update the advanced package manager:

$ sudo apt-get update

Finally, use the following command to install Stacer on your Linux machine. You can get more installation details for different flavors here.

$ sudo apt-get install stacer

After successfully installing Stacer, use the following command to launch it:

$ stacer

Stacer will now launch with a graphical interface, displaying its optimization tools such as:

  • System cleaner
  • Process manager
  • Service manager
  • Uninstaller
  • Resource and APT manager
The Stacer system cleaner Fig. 1: The Stacer system cleaner

If you no longer wish to use Stacer, use the following command to uninstall it:

sudo apt-get remove stacer

Optimizing the I/O scheduler

The I/O scheduler is a program that organizes and sorts requests to determine their priority. It helps optimize system performance by reordering the requests for more efficient processing. The I/O scheduler also helps ensure that requests from different processes are handled fairly and efficiently.

Here are examples of I/O schedulers:

  • Completely fair queuing: This is the default scheduler for many because it evenly distributes read and write requests.
  • No operation: This I/O scheduler transfers read and write requests to the storage channel, where they will be reordered.
  • Deadline I/O scheduler: an algorithm used by operating systems to manage disk I/O requests. It prioritizes requests based on a predetermined deadline, with requests whose deadlines are closer receiving higher priority. This ensures that time-critical requests are handled first, reducing latency and improving overall system performance.
  • Anticipatory I/O: Used by old Linux kernels, it is now classified as obsolete.

Here is a list of parameters you can use to optimize the I/O scheduler:

  • fifo_batch: specifies how many requests will be made in one batch
  • read_expire: adds a deadline in milliseconds to a read request
  • write_expire: adds a deadline in milliseconds to a write request

Use the following command to improve your I/O scheduler using the fifo_batch parameter:

# echo 32 > /sys/block/sdb/queue/iosched/fifo_batch

Optimizing power usage

Power management configuration in Linux comprises a set of settings and configurations used to optimize energy usage and battery life. It includes settings for managing CPU frequency, suspending or hibernating the system, dimming the display, and more. It saves energy, prolongs the battery life of a Linux machine, and reduces the power consumption of a desktop system.

Linux provides several parameters for optimizing power consumption:

  • -S: allows you to specify and set the standby time for the drive
  • -B: activates the Advanced Power Management API
  • -M: sets the Automatic Acoustic Management feature that reduces output noise

hdparm is a command line utility for Linux and Unix systems for viewing and manipulating various hard drive parameters. It is mainly used to set the drive parameters, such as its spin-up time, acoustic management, power management, and read-ahead caching.

You can use the above parameters in the command below to optimize the power usage:

# hdparm -B /dev/sda

Scaling your CPU to meet demand

Scaling down the CPU whenever less CPU memory is needed will save power and resources; scaling it up during high CPU demand will improve system performance. With Linux, there are several key components to consider when scaling CPU usage. These include

  • The number of CPU cores: This is the physical number of CPU cores available on the system, which determines how many tasks can be run simultaneously.
  • The CPU clock speed: The speed, measured in GHz, at which the CPU processes instructions. Higher clock speeds mean faster processing times for individual tasks. However, excessive CPU speeds can lead to an increase in electricity consumption, which leads to higher temperatures.
  • The CPU cache: This is a small amount of memory built into the CPU that is used to store frequently accessed data, which can improve performance by reducing the need to access slower main memory.
  • The CPU architecture: This refers to the design of the CPU and how it processes instructions. Different architectures can have different performance characteristics and thus be better suited to certain types of workloads.
  • The operating system and its scheduling policies: The operating system plays a crucial role in managing CPU resources and determining which tasks get access to the CPU and when. The scheduling policies used by the OS can affect the performance of the system and how it scales with increasing workloads.

In general, to scale CPU usage on a Linux system you should:

  • Increase the number of CPU cores to improve the clock speed
  • Optimize the use of the CPU cache
  • Use a CPU architecture that is well-suited to the workload
  • Carefully manage the operating system's scheduling policies

Here are three commands recommended by Arch Linux:

  • Set the minimum clock frequency in gigahertz or megahertz:
    # cpupower frequency-set -d clock_freq
  • Set the CPU to run at a specified frequency in gigahertz or megahertz. You should not overclock the CPU, otherwise you may damage the computer’s processor, motherboard, and, in some cases, RAM.
    # cpupower frequency-set -f clock_freq
  • Set the CPU limit for a certain process:
    $ cpulimit -l 50 -p 5081

Conclusion

Using a slow Linux machine can have several negative consequences, including

  • Increased frustration: Slow performance means users may have to wait longer for tasks to complete or deal with unresponsive applications.
  • Inability to run certain applications: Some applications require a certain level of performance or may not be optimized for slower machines.
  • Poor user experience: In general, a slow machine inevitably leads to a poor user experience, with sluggish response times and overall slow performance.

A slow Linux machine can be more vulnerable to cyber threats if it’s unable to run security updates and apply other protective measures quickly or efficiently enough.

There are multiple different ways to improve the speed and responsiveness of your Linux machine, from tweaking the kernel’s settings to adjusting the CPU frequency and optimizing the battery life. In this article, we covered the methods that are most likely to help fix a slow Linux system.

Was this article helpful?
Monitor your Linux environment

Check the health and availability of your Linux servers for optimal performance with Site24x7's Linux monitoring tool.

Related Articles

Write For Us

Write for Site24x7 is a special writing program that supports writers who create content for Site24x7 "Learn" portal. Get paid for your writing.

Write For Us

Write for Site24x7 is a special writing program that supports writers who create content for Site24x7 “Learn” portal. Get paid for your writing.

Apply Now
Write For Us