How to Benchmark CPU, RAM, and Disk Performance on Linux

How to Benchmark CPU, RAM, and Disk Performance on Linux

Regularly monitoring system performance is essential for maintaining optimal functionality on your Linux server or desktop. This guide offers detailed explanations and instructions on using multiple commands and tools to benchmark CPU, RAM, and disk performance on Linux.

Checking CPU Performance on Linux

Using sysbench for CPU Performance

Installation:

sudo apt install sysbench  # Ubuntu/Debian
sudo yum install epel-release && sudo yum update -y && sudo yum install sysbench -y  # CentOS/RHEL

CPU Benchmark Commands:

  • Single-threaded test:
sysbench --test=cpu --cpu-max-prime=20000 run
  • Multi-threaded (4 threads):
sysbench --test=cpu --cpu-max-prime=20000 --num-threads=4 run

Explanation: The commands perform prime number calculations to stress-test the CPU. Lower completion times indicate better CPU performance.

Using top and htop

  • Real-time CPU usage:
top
htop  # Interactive, user-friendly version of top

Explanation: Displays CPU usage dynamically, allowing you to monitor process-level details.

Using mpstat

  • CPU core statistics:
mpstat

Explanation: Provides detailed statistics on individual CPU cores, showing metrics like idle and busy percentages.

Checking RAM Performance on Linux

Using sysbench for RAM Performance

  • Read Speed Test:
sysbench --test=memory --memory-block-size=1K --memory-scope=global --memory-total-size=100G --memory-oper=read run
  • Write Speed Test:
sysbench --test=memory --memory-block-size=1K --memory-scope=global --memory-total-size=100G --memory-oper=write run

Explanation: Measures read/write speeds by repeatedly accessing memory. Higher operation rates and data transfer values indicate better performance.

Using free and vmstat

  • RAM utilization:
free -h
vmstat -s

Explanation: Provides quick and detailed memory statistics respectively, useful for monitoring RAM usage and identifying memory bottlenecks.

Checking Disk Performance on Linux

Using fio for Disk Benchmarking

Installation:

sudo apt install fio -y  # Ubuntu/Debian
sudo yum install epel-release -y && sudo yum install fio -y  # CentOS/RHEL
  • Simultaneous Random Read/Write Test:
fio --randrepeat=1 --ioengine=libaio --direct=1 --gtod_reduce=1 --name=TGS --filename=TGS --bs=4k --iodepth=64 --size=4G --readwrite=randrw --rwmixread=75
  • Random Read Test:
fio --randrepeat=1 --ioengine=libaio --direct=1 --gtod_reduce=1 --name=TGS --filename=TGS --bs=4k --iodepth=64 --size=4G --readwrite=randread
  • Random Write Test:
fio --randrepeat=1 --ioengine=libaio --direct=1 --gtod_reduce=1 --name=TGS --filename=TGS --bs=4k --iodepth=64 --size=4G --readwrite=randwrite

Explanation: Evaluates disk performance by measuring the input/output operations per second (IOPS) for random reads and writes. Higher values indicate better performance.

Using ioping to Measure Latency

  • Install and Run:
sudo apt install ioping -y
ioping -c 10 .

Explanation: Tests latency by measuring response time for disk requests. Low latency (under 1 ms) is ideal.

Additional Performance Checking Methods

Using Stress-ng for Stress Testing

Installation:

sudo apt install stress-ng
  • CPU Stress Test:
stress-ng --cpu 4 --timeout 60s
  • RAM Stress Test:
stress-ng --vm 2 --vm-bytes 1G --timeout 60s
  • Disk Stress Test:
stress-ng --hdd 2 --timeout 60s

Explanation: Stress-ng imposes high load on your system resources (CPU, RAM, Disk) to evaluate stability and performance under intense conditions.

Using Glances for Real-Time Monitoring

Installation:

sudo apt install glances
  • Run Glances:
glances

Explanation: Provides an interactive real-time dashboard showing comprehensive system metrics, including CPU, RAM, disk usage, network activity, and running processes.

Using Nmon for System Monitoring

Installation:

sudo apt install nmon
  • Run Nmon:
nmon

Explanation: Nmon offers an interactive monitoring interface displaying detailed system metrics, including CPU, RAM, disk performance, and network stats. It allows you to generate reports and logs for further analysis.

Benchmarking the Entire Linux Server

Geekbench 5

  • Run Geekbench:
wget https://cdn.geekbench.com/Geekbench-5.4.5-Linux.tar.gz --no-check-certificate
tar xf Geekbench-5.4.5-Linux.tar.gz
cd Geekbench-5.4.5-Linux/
./geekbench5

YABs (Yet Another Benchmark Script)

  • Run YABs:
curl -sL yabs.sh | bash
# or
wget -qO- yabs.sh | bash

Conclusion

Regularly benchmarking your Linux system using the tools and commands detailed above ensures optimal performance and reliability. Use these detailed methods to proactively identify, troubleshoot, and enhance your system’s efficiency.

Comments

No comments yet. Why don’t you start the discussion?

Leave a Reply

Your email address will not be published. Required fields are marked *