A quick CPU check is the first step in diagnosing server slowness. The right commands on Linux: lscpu, nproc, cat /proc/cpuinfo, top, htop. The numbers that matter: cores, threads, frequency, and utilization.
Table of contents
- The CPU summary
- The number of cores
- The CPU frequency
- The current utilization
- The per-process CPU
- The historical CPU
- FAQ
The CPU summary
The first command to run: lscpu. The output is a summary of the CPU: the architecture, the number of cores, the number of threads, the frequency, the cache sizes, the virtualization features.
The output is the easiest way to know what the CPU is. The team that wants the answer in 5 seconds runs lscpu.
The number of cores
The number of cores is the number of physical CPUs on the chip. The command: nproc. The output is the number of cores available to the process.
The team that has a workload that uses multiple cores wants to know this number. The team that has a workload that is single-threaded does not need multiple cores; the team that has a workload that is multi-threaded wants as many cores as possible.
The CPU frequency
The CPU frequency is the clock speed of the CPU. The command: lscpu | grep MHz or cat /proc/cpuinfo | grep MHz.
The team that has a workload that is single-threaded wants the highest possible frequency. The team that has a workload that is multi-threaded cares more about the number of cores than the frequency.
The current utilization
The current CPU utilization is the percentage of time the CPU is doing work. The command: top or htop.
The output shows the per-process CPU utilization and the system-wide CPU utilization. The team that sees 100% CPU is the team that has a workload that is CPU-bound. The team that sees 5% CPU on a 16-core machine is the team that is over-provisioned.
The per-process CPU
The per-process CPU is the CPU utilization of a specific process. The command: top -p <pid> or ps -p <pid> -o %cpu.
The team that has a workload that is using all the CPU finds the process that is using it. The fix is usually in the application (an infinite loop, a missing index, a slow query).
The historical CPU
The historical CPU utilization is the CPU utilization over time. The tool: sar, collectd, or the cloud provider’s metrics.
The team that has a workload that spikes at 3 a.m. every night finds the spike in the historical CPU. The fix is usually to add a buffer, to add a queue, or to schedule the work for a different time.
FAQ
How do I check the CPU on a Linux server?
The first command: lscpu. The output is a summary of the CPU. The number of cores: nproc. The current utilization: top or htop. The per-process CPU: top -p <pid>.
What is the difference between cores and threads?
A core is a physical CPU. A thread is a virtual CPU. The team that has a CPU with hyperthreading has 2 threads per core. The team that has a workload that is single-threaded does not benefit from hyperthreading.
What is the right CPU utilization for a server?
The right answer depends on the workload. The team that has a workload with a peak at 80% is at the limit. The team that has a workload with a peak at 50% has headroom. The team that has a workload with a peak at 10% is over-provisioned.
What is the difference between CPU utilization and CPU load?
CPU utilization is the percentage of time the CPU is doing work. CPU load is the number of processes that are waiting for the CPU. The team that has a load of 10 on a 4-core machine is the team that has a workload that is CPU-bound.
How do I reduce CPU utilization?
Right-size the workload. Add an index. Cache the result. Tune the code. The right answer depends on the workload. The first step is to profile the application and find the function that is using the CPU.
How do I check the CPU on a Windows server?
Task Manager or Get-Counter '\Processor(*)\% Processor Time'. The team that wants a more detailed view uses Performance Monitor.
If you are sizing a server tier for a new project, the RunxBuild hosting calculator is the place to model the line items. The CPU, the memory, the storage, the I/O - each one is a separate number, and the team’s mental model for the platform is the sum of those numbers. The RunxBuild dashboard is where the team sees the actual CPU usage in one place.