Fixing a dedicated server CPU not running at full max speed by setting an upper and lower limit with cpufrequtils.
A processor will scale for certain reasons like power consumption, temperature and stability. However, at a lower clock rate tasks will take longer and the CPU could put itself under more load than if it was running at full speed, to begin with.
A CPU’s speed is the rate in wave frequencies which it can execute tasks, also called a clock rate.
Running this command will give you the CPU name/model/type, thread count and the speed (MHz) that thread is running at
grep -E '^model name|^cpu MHz' /proc/cpuinfo
Chances are that on a VPS your allocated CPU will be running at its max speed. On a dedicated however it will have speed scaling enabled. This means that when the CPU isn’t under intensive strain it will find a lower clock speed that makes it comfortably able to do simple tasks.
I found that my Intel Xeon E3-1245 v5 @ 3.50GHz stayed at a mere 800 Mhz most of the time when doing small tasks. Removing CPU scaling and setting a ceiling for the CPU speed was rather easy.
Install cpufrequtils with
sudo apt install cpufrequtils
Once that has finished run:
This returns plenty of details about the CPU like its limits, hardware restriction, current speed, and steps.
Set max speed
As my max CPU speed is 3.50GHz I am going to set that as the max upper limit
sudo cpufreq-set -u 3.5Ghz
Set minimum speed
Next is the lower limit, what it will be at when not under a load. I can set 3.5Ghz meaning the CPU will run at that speed 24/7 even if it has no load or I can be conservative.
sudo cpufreq-set -d 3.3Ghz
Sets the CPU minimum clock speed at 3.3GHz, this fixes the problem of my CPU scaling its speeds and not running some tasks at/close to full speed and capability.