Cyber Services / All lessons / CentOS / Linux Administration / Adjusting Tuning Profiles

Adjusting Tuning Profiles

Module 14 of 33 · 5 min read · Free to read

MODULES ↓ Command blocks have a COPY button

Optimizing CentOS Performance for Specific Workloads

A default CentOS installation is a generalist; it's configured to perform reasonably well for any task. However, a production server is a specialist. A database server has vastly different performance requirements than a virtualization host or a file server. Performance tuning is the art and science of adjusting the operating system's kernel and subsystem parameters to optimize its performance for a specific, intended workload. On modern CentOS/RHEL systems, this is managed by a powerful service called tuned.

The `tuned` Daemon: The Server's Performance Coach

The `tuned` daemon is a dynamic, adaptive tuning service. Instead of forcing you to manually change dozens of complex kernel parameters, `tuned` bundles them into easy-to-use **profiles**. When you activate a profile, `tuned` automatically applies all the corresponding system settings.

How `tuned` Works

tuned monitors system components and usage, and can dynamically adjust settings on the fly. It manages a wide range of subsystems, including:

  • CPU governor settings (performance vs. powersave)
  • Disk I/O schedulers and read-ahead values
  • Kernel memory management parameters
  • Network stack tuning

Managing Profiles with `tuned-adm`

The primary command for interacting with `tuned` is tuned-adm.

  1. Installation and Service Management: `tuned` is installed by default on most CentOS systems, but if not:
    sudo dnf install -y tuned
    sudo systemctl enable --now tuned
  2. List Available Profiles: See all the pre-built tuning profiles available on your system.
    $ tuned-adm list
    Available profiles:
    - balanced
    - desktop
    - hpc-compute
    - latency-performance
    - network-latency
    - network-throughput
    - powersave
    - throughput-performance
    - virtual-guest
    - virtual-host
    Current active profile: virtual-guest
  3. View the Active Profile:
    $ tuned-adm active
    Current active profile: virtual-guest
  4. Recommend a Profile: `tuned` can analyze your system and suggest the most appropriate profile.
    $ tuned-adm recommend
    virtual-guest
  5. Activate a New Profile: This is how you apply a new set of tuning parameters.
    # Switch to a profile optimized for network throughput
    $ sudo tuned-adm profile network-throughput

Commonly Used Profiles and Their Purpose

Profile NameIdeal Use CaseWhat it Does (Simplified)
balancedDefault for most systems. A good mix of performance and power saving.Keeps CPU in a moderate state, uses a balanced I/O scheduler.
throughput-performanceDatabase, file, and application servers.Optimized for raw performance. Disables power saving, tunes kernel for high disk and network I/O.
network-latencySystems sensitive to network response time (e.g., high-frequency trading).Disables power saving, tunes the network stack for the lowest possible latency.
virtual-guestThe default profile when running inside a virtual machine (like our lab VMs).Optimized for running as a VM. Reduces virtual memory swappiness.
virtual-hostA physical machine that is hosting many virtual machines (a hypervisor).Tunes the kernel for high virtualization performance.

Process Scheduling: `nice` and `renice`

While `tuned` manages the entire system, you often need to influence the priority of a single, specific process. The Linux kernel's scheduler decides which processes get access to the CPU. You can influence this decision using a "niceness" value.

Understanding Niceness

  • The niceness value ranges from -20 (highest priority) to +19 (lowest priority).
  • A process with a lower nice value is "less nice" to other processes and demands more CPU time.
  • A process with a higher nice value is "nicer" to other processes, yielding its CPU time more readily.
  • The default nice value for new processes is 0.
  • Only the `root` user can set a negative (high-priority) nice value.

Commands for Influencing Priority

  • nice: Starts a new command with a specified niceness.

    CentOS Server Example: You need to run a CPU-intensive data compression job, but you don't want it to impact the performance of the main web server application. You start it with a high (low-priority) nice value.

    # The -n 15 flag sets the niceness to 15
    $ nice -n 15 tar -czvf /tmp/large_archive.tar.gz /var/log/
  • renice: Changes the niceness of a process that is already running.

    CentOS Server Example: You notice in `top` that a backup script (PID 12345) started by another admin is consuming a lot of CPU. You decide to lower its priority to ensure it doesn't interfere with users.

    # The -n 10 sets the niceness, -p specifies the PID
    $ sudo renice -n 10 -p 12345
Comprehensive Practice Lab: Tuning a Web Server

Scenario: You are setting up a new CentOS server that will function as a dedicated, high-performance web and database server. You need to apply the correct tuning profile and manage a long-running process.

  1. Install `tuned`: Verify `tuned` is installed and the service is enabled and running.
  2. Check the Current Profile: Run tuned-adm active. Since it's a VM, it will likely be `virtual-guest`.
  3. Apply the Correct Profile: For a database and web server, the `throughput-performance` profile is ideal. Activate it.
    sudo tuned-adm profile throughput-performance
    Verify the change with tuned-adm active.
  4. Simulate a Long-Running Job: Start a CPU-intensive process in the background.
    # This command will run indefinitely
    (while true; do :; done) &
  5. Identify and Renice the Job: Use top to find the PID of the `while` or `bash` process that is consuming 100% CPU. Note its PID. Exit `top`.
  6. Lower the Priority: Use renice to make the process "nicer" (lower priority).
    # Replace  with the actual process ID
    sudo renice -n 19 -p 
  7. Observe the Change: Run top again. Find your process. You will see that its niceness value (in the "NI" column) is now 19. While it may still consume a lot of CPU (if the system is otherwise idle), the kernel will now always prioritize more important processes (like the web server) over this one.
  8. Clean Up: Kill the background process using its PID: kill -9 .
Modules (33) ← CentOS / Linux Administration