The CPU governor is a crucial component that regulates the CPU's frequency and power usage. By default, Linux servers often use the "ondemand" governor, which dynamically adjusts the CPU frequency based on system load. However, for maximum performance, switching to the "performance" governor is recommended.
To check your current CPU governor, use the following command:
sudo apt-get install cpufrequtils
Then run:
cpufreq-info
This command will display information about the current CPU frequency scaling settings. Look for the "governor" section to identify the current governor.
To set the CPU governor to "performance," execute the following command:
sudo cpufreq-set -r -g performance
This command ensures that all CPU cores are set to the "performance" governor, optimizing the server for maximum processing power.
If this doesn't work for you, you can try this command:
echo 'performance' | sudo tee /sys/devices/system/cpu/cpu*/cpufreq/scaling_governor
Monitoring CPU Clock Speed:
To monitor the current CPU clock speed in real-time, you can use the following command:
watch -n 0.4 "grep -E '^cpu MHz' /proc/cpuinfo"
This command uses the watch
utility to continuously display the CPU clock speed, updating every 0.4 seconds. It provides valuable insights into how the CPU frequency changes under different workloads.
Disabling Multiple Cores:
In specific scenarios, you might want to disable all but one processor core to dedicate resources to a particular task. To achieve this, you can use the following steps:
Identify the number of available CPU cores:
lscpu
Look for the "Core(s) per socket" entry to determine the number of cores per CPU socket.
Disable additional cores (replace [CORE_NUMBER] with the desired core number):
sudo echo 0 > /sys/devices/system/cpu/cpu[7]/online
Keep in mind that you need to leave at least one core for the best performance. Use htop
command to see how many cores are working.