To check the available states:
# cat /sys/devices/system/cpu/cpu0/cpufreq/scaling_available_governors
conservative ondemand userspace powersave performance schedutil
To check the current states:
cat /sys/devices/system/cpu/cpu*/cpufreq/scaling_governor
To set the states:
for i in $(seq 0 $(($(nproc --all) - 1))); do cpufreq-set -c $i -g performance; done
or
codeniner echo performance | sudo tee /sys/devices/system/cpu/cpu*/cpufreq/scaling_governor
To make it persist. Add to /etc/rc.locl before exit 0 after shebang. Make sure rc.local is executable.
#!/bin/bash
for i in $(seq 0 $(($(nproc --all) - 1))); do cpufreq-set -c $i -g performance; done
exit 0
What each state does:
- Performance: This governor keeps the CPU at the highest possible frequency.
- Powersave: This governor keeps the CPU at the lowest possible frequency.
- Userspace: This allows user-level programs to select the desired CPU frequency.
- Ondemand: This governor increases the CPU frequency when the system is busy and decreases the frequency when the system is idle. This is typically the default governor in many distributions as it provides a good balance between performance and power usage.
- Conservative: Similar to the "ondemand" governor, but it increases and decreases the CPU frequency more gradually. This can result in more efficient power usage but also slightly less responsive performance.
- Schedutil: Available with newer kernels (4.7 and above), it makes use of the CPU scheduler's load tracking to select CPU frequency in a more efficient manner.
Zoinkies If you’re on a VPS/Semi Dedicated setup the platform will ban you.
Very sound advice, only do this on a dedicated server you have full control of. Unmanaged means YOU manage the server, if it's been set for anything less than performance, then it's not fit for purpose in my opinion. I am paying for performance I expect it. However, your mileage may vary.... I've never had to do this until I got the server below, all other servers have been fine or I've tweaked the bios ever so slightly.
I recently picked up a dedicated box, that I have VNC access too, but they've locked out the bios (ionos) therefore I can't go and check/tweek speedstep settings and they've detuned the cpu from 4.8GHz max turbo to 4.5Ghz max turbo. I can't change that, but 2.6 - 2.9GHz base clock is fast enough, if a particular PHP thread is lasting seconds, then it will likely turbo boost to 4.5GHz. Most the time the thread is done before it can get past 3GHz. However, it's 'default' install of ubuntu has this set at "ondemand" and I was getting 800Mhz before making this change.
Another thing is how often your server is loaded, if it's a lot all the time, then a more conservative governor is probably ok, as the cores will be running higher more often. But if your getting more infrequent hits and the cores aren't getting over 800MHz or 1.4GHz then setting this to performance mode will certainly reduce that ramp up time.
If you don't know what you're doing, research and/or ask. Blindly copying commands is never a sensible thing. Tweaking server bios settings if you're not very familiar with them is asking for trouble. You can damage the server and then be on the hook for a $2000+ processor! That being said a CPU WILL thermal throttle well before it's likely to meltdown unless you really messed up the bios settings.
Or as Zoinkies has testified, they'll ban you. So proceed with caution and understanding.