CPU Governor and Frequency Scaling Tuning for Latency-Sensitive Servers
AI generated
$
/etc
Linux · CPU Governor · cpufreq · Latency
CPU Governor and Frequency Scaling Tuning
Why powersave needlessly slows down latency-sensitive Magento servers

The wrong CPU governor forces a server to ramp up its clock speed on every incoming request before it can actually respond. This delay is barely visible in monitoring, but shows up in practice as fluctuating response times, especially under bursty PHP-FPM traffic.

16 min read cpupower · schedutil · C-states · Turbo Boost Linux · Bare Metal · Cloud VMs

1. Why the CPU governor matters for web latency

Modern CPUs do not permanently run at their maximum clock speed, instead dynamically adjusting the clock rate based on current load to save energy. The CPU governor, a kernel component, is responsible for this and decides how quickly and how aggressively the clock speed is adapted to load. On desktop systems this behavior is usually desirable, but on a latency-sensitive Magento web server the wrong CPU governor can cause every incoming request to first wait for the clock speed to ramp up.

This effect shows up particularly clearly under PHP-FPM workloads with many short, bursty requests: a worker process that has been idle for a while runs, under a conservative CPU governor, initially at reduced clock speed, and scaling up to full frequency takes, depending on hardware and governor settings, several milliseconds, which directly shows up in time to first byte.

This article shows which CPU governor types the Linux kernel offers, how the current configuration is determined and permanently adjusted, and how C-states and Turbo Boost together with the governor affect the actual response time of a Magento server.

2. cpufreq basics: clock speed, scaling, and governors

The kernel's cpufreq subsystem provides the interface through which the clock speed of every individual CPU core can be controlled independently. Each CPU supports a range between a minimum and a maximum frequency, and the CPU governor continuously decides within this range which frequency is currently appropriate. This decision is based on various heuristics depending on the chosen governor type, and is typically re-evaluated several times per second.

The transition between frequency steps is not instantaneous. Depending on the hardware generation, a full ramp-up from the minimum to the maximum frequency takes anywhere from a few microseconds on modern Intel and AMD platforms with hardware P-states, up to several milliseconds on older hardware or in certain virtualized environments. For a single HTTP request that may sound negligible, but at thousands of requests per second this delay adds up to a measurable degradation of P99 latency.

3. The main governor types in detail

The powersave governor keeps the CPU at its lowest available frequency by default and only raises it under genuinely sustained load, which offers maximum energy efficiency but causes the highest response latency under bursty load. The performance governor, in contrast, keeps the CPU permanently at its maximum possible frequency regardless of current utilization, eliminating any response delay but noticeably increasing power consumption and heat generation.

The more modern schedutil governor, the default on many distributions for several kernel versions now, works closely with the CFS scheduler and reacts significantly faster to sudden load spikes than older governors like ondemand, because it accesses scheduler information directly instead of periodically polling utilization. For many latency-sensitive web workloads, schedutil has become a good compromise between energy efficiency and response speed, though it does not quite reach the constant zero delay of performance.

4. Finding the current governor and clock speed

Before changing a CPU governor, the current state should be known. The tool cpupower frequency-info shows, for every CPU core, the currently active governor, the supported frequency steps, and the actually measured current clock speed. On systems without cpupower, the virtual files under /sys/devices/system/cpu/cpu*/cpufreq/ provide the same information directly.

It is important to check these values under realistic load, not just at idle. A server that appears correctly configured with performance at idle can still be effectively throttled in virtualized environments if the hypervisor itself enforces its own frequency or CPU limits that are not visible from the guest operating system.


# Show current governor, min/max frequency, and live clock speed per core
cpupower frequency-info

# Same information directly from sysfs, per core
for cpu in /sys/devices/system/cpu/cpu[0-9]*; do
  echo "$cpu: $(cat $cpu/cpufreq/scaling_governor) @ $(cat $cpu/cpufreq/scaling_cur_freq) kHz"
done

# List all governors supported by the current driver
cat /sys/devices/system/cpu/cpu0/cpufreq/scaling_available_governors

5. Setting the governor to performance or schedutil permanently

A change via cpupower frequency-set -g performance takes effect immediately, but is lost after a reboot unless persistence has been set up. For production Magento servers, a systemd service that automatically re-applies the desired CPU governor at every boot is recommended, similar to the well-known issue with transparent huge pages, where a one-off manual change is likewise not persistent.

On many cloud platforms and in container environments, access to cpufreq is restricted or fully abstracted away by the hypervisor, so a governor change there remains ineffective. In this case it is worth looking at the performance options of the respective cloud provider instead, for example dedicated, non-shared CPU instance types that guarantee consistently high clock speeds, rather than trying to optimize at the governor level itself.


# Apply immediately to all cores
cpupower frequency-set -g performance

# Verify the change took effect
cpupower frequency-info | grep "governor"

# /etc/systemd/system/cpu-governor.service
[Unit]
Description=Set CPU governor to performance at boot
After=multi-user.target

[Service]
Type=oneshot
ExecStart=/usr/bin/cpupower frequency-set -g performance
RemainAfterExit=yes

[Install]
WantedBy=multi-user.target

# Enable with: systemctl daemon-reload && systemctl enable --now cpu-governor.service

6. C-states: idle depth and wake-up latency

Besides clock speed itself, so-called C-states influence how deeply a CPU core sleeps while idle. A deeper C-state saves more energy but takes longer to bring the core back to full readiness when a new request arrives. This wake-up latency adds to the plain CPU governor ramp-up and can, on some server platforms, range from several microseconds to low milliseconds.

For maximally latency-sensitive workloads, the maximum permitted C-state depth can be limited via the kernel parameter intel_idle.max_cstate or the tool cpupower idle-set, so idle cores only sleep shallowly and therefore respond faster, at the cost of higher baseline consumption even without load. This measure is only worthwhile when governor tuning alone is not enough and the remaining latency is demonstrably caused by deep C-states.


# List available C-states and their exit latency (microseconds)
cpupower idle-info

# Disable the deepest C-state to reduce wake-up latency
cpupower idle-set -d 3

7. Understanding Turbo Boost and thermal limits

Turbo Boost, or AMD Precision Boost respectively, allows a CPU to briefly clock beyond its nominal maximum frequency, as long as thermal and power limits allow it. Combined with the performance CPU governor, individual cores under brief heavy load benefit from this extra frequency, which becomes noticeable especially for individual slow PHP requests that briefly need maximum compute power.

It is important to understand that Turbo Boost is not a permanent guarantee. Under sustained high utilization across all cores, the CPU automatically reduces the turbo frequency to stay within its thermal limits. A server running consistently high parallel PHP-FPM load therefore benefits less from Turbo Boost than a server with bursty, unevenly distributed load, where individual cores remain free in between.

8. Common mistakes in governor tuning

The most common mistake is setting the CPU governor only temporarily via the command line, without setting up persistence for the next reboot. After a kernel update or server reboot the server then silently falls back to the default governor, often powersave or ondemand, and the latency problem originally fixed returns without any obvious cause appearing in monitoring.

A second mistake is changing the CPU governor on virtualized instances without checking whether the hypervisor even passes the change through. On many shared cloud instances, the guest system's governor setting has no effect whatsoever, because the host manages the actual clock speed centrally. A third mistake is applying performance blindly to every server, without considering the extra energy and heat load for servers with many physical cores, which can measurably increase operating costs under continuous operation.

9. Governor strategies compared

The following table compares the relevant CPU governor options for latency-sensitive servers.

Governor Latency under load spikes Power consumption
powersave High, slow ramp-up Minimal
ondemand Medium, periodic polling Low to medium
schedutil Low, scheduler-based Low to medium
performance Minimal, constant maximum clock High, even at idle

For most latency-sensitive production Magento servers, either performance or a current schedutil governor is the right choice. For development and staging environments with lower latency priority, the more energy-efficient ondemand or powersave governor can make more sense to reduce operating costs.

Mironsoft

CPU governor and latency tuning for Magento servers

Is the wrong CPU governor slowing down your response times?

We measure your actual clock speed under real load, set the right governor persistently across reboots, and tune C-states and Turbo Boost to your traffic.

Governor audit

Measure current configuration and actual clock speed under load

Persistent configuration

Set up governor, C-states, and Turbo Boost to survive reboots

Latency monitoring

Track P99 latency measurably before and after tuning

10. Summary

The CPU governor determines how quickly a server responds to bursty load, and is often an overlooked lever on latency-sensitive Magento web servers. powersave saves energy at the cost of response time, performance eliminates frequency delays entirely, and schedutil now offers a good compromise thanks to close coupling with the scheduler. cpupower frequency-info reveals the current state, while cpupower frequency-set combined with a systemd service makes it reboot-safe.

C-states and Turbo Boost complement the plain CPU governor choice: shallower C-states reduce wake-up latency at the cost of higher baseline consumption, and Turbo Boost delivers a brief performance boost but is no permanent guarantee under sustained high load. For latency-critical production servers, combining performance or schedutil with reduced C-state depth is usually the most robust choice.

CPU Governor and Frequency Scaling Tuning — Key Takeaways

Check status

cpupower frequency-info shows the active governor and measured clock speed.

Set the governor

performance or schedutil for latency-sensitive web workloads.

Persist it

A systemd service that re-applies the governor at every boot.

Limit C-states

cpupower idle-set for lower wake-up latency when needed.

11. FAQ: CPU Governor and Frequency Scaling Tuning

1What does the CPU governor do?
Controls how clock speed is dynamically adjusted to load.
2Which governor for Magento?
performance or a current schedutil governor for minimal latency.
3Why is powersave problematic?
Keeps CPU at lowest frequency, causes delay under bursty requests.
4How do I check the current governor?
With cpupower frequency-info or directly in /sys/devices/system/cpu.
5Does a change survive reboot?
No, a systemd service must re-apply the governor at every boot.
6Does it work on every cloud instance?
Not always, some hypervisors manage clock speed centrally.
7What are C-states?
Idle depth of a core, deeper states save energy but cost wake-up latency.
8Is Turbo Boost permanently guaranteed?
No, under sustained full load the turbo frequency is thermally limited.
9Does performance increase costs?
Yes, with many cores, measurably higher energy consumption under continuous operation.
10Is schedutil worth it?
Yes, reacts quickly based on scheduler data at slightly lower consumption than performance.