Operations 31 min read

Master Linux Performance Testing: CPU, Memory, Network & I/O Stress Techniques

This guide explains how to evaluate and improve Linux server performance by conducting comprehensive CPU, memory, network, and I/O stress tests using tools such as stress, stressapptest, Valgrind, ApacheBench, JMeter, wrk, siege, httperf, and fio, with detailed command examples and result analysis.

Deepin Linux
Deepin Linux
Deepin Linux
Master Linux Performance Testing: CPU, Memory, Network & I/O Stress Techniques

Linux operating systems dominate the server market because of their stability, security, and open‑source nature. As workloads grow, administrators need to assess and improve system performance through systematic stress testing.

Part 1 – CPU Stress Testing

The stress command creates high‑load CPU scenarios. Install it with:

sudo apt-get install stress
sudo yum install -y epel-release && sudo yum install -y stress

Run a test on a 4‑core CPU: stress -c 4 Monitor usage with top (press 1 to see each core), uptime for average load, mpstat -P ALL for per‑core statistics, and pidstat -u 1 to identify the process consuming CPU.

Alternative CPU checks include calculating π with bc to stress floating‑point operations:

echo "scale=5000; 4*a(1)" | bc -l -q

Part 2 – Memory Stress Testing

StressAppTest

is a free, open‑source memory tester used by Google. Install it on various distributions:

sudo apt install stressapptest
sudo dnf install stressapptest
sudo emerge stressapptest
sudo zypper install stressapptest

Key parameters: -M <MB> – allocate memory size. -s <seconds> – test duration. -m <threads> – number of threads. -W – add CPU load.

Example: stressapptest -M 2048 -m 8 -s 3600 -W During the test, use top and free -s 5 to watch CPU and memory usage.

Valgrind provides deep memory diagnostics. Common tools:

memcheck – detects leaks, uninitialized reads, out‑of‑bounds accesses.

callgrind – profiles function calls.

cachegrind – analyzes cache behavior.

helgrind – finds thread‑synchronization issues.

massif – measures heap usage.

Example code with a leak, uninitialized variable, and out‑of‑bounds access:

#include <stdlib.h>
void leak() { int *ptr = new int[10](); }
void uninit() { int x; if (x > 0) { /* ... */ } }
int main() {
    int *arr = (int*)malloc(sizeof(int) * 20);
    arr[20] = 0; // out‑of‑bounds
    leak();
    uninit();
    free(arr);
    return 0;
}

Compile with debugging symbols: g++ -g -O0 demo.cpp -o demo Run Valgrind:

valgrind --tool=memcheck --leak-check=full ./demo

The output pinpoints the uninitialized variable, the out‑of‑bounds write, and the memory leak with file and line numbers.

Part 3 – Network Stress Testing

The ApacheBench ( ab) tool simulates concurrent HTTP requests. Install it:

sudo apt-get install apache2-utils
sudo yum install httpd-tools

Basic syntax: ab [options] http://hostname[:port]/path Common options: -n <requests> – total number of requests. -c <concurrency> – simultaneous connections. -t <seconds> – maximum test duration. -r – continue on socket errors. -p <file> – POST data file. -T <type> – Content‑Type header.

Example (1000 requests, 100 concurrent):

ab -n 1000 -c 100 http://localhost:8080/index.html

Result highlights include requests per second, time per request (client and server view), transfer rate, and detailed connection time statistics.

Other network testing tools:

JMeter – GUI‑based, supports many protocols.

wrk – lightweight, event‑driven, scriptable with Lua.

siege – multi‑protocol, records per‑user response times.

httperf – high‑performance, supports HTTP/1.1 and SSL.

Choose the tool that matches the protocol and reporting needs of your workload.

Part 4 – I/O Stress Testing

The stress utility can generate I/O load: stress --io 4 --timeout 60 For deeper analysis, use fio. Important parameters: --name – task label. --direct=1 – bypass OS cache. --rw – read/write mode (read, write, randread, randwrite, randrw). --bs – block size. --size – file size. --numjobs – concurrent processes. --runtime – test duration. --group_reporting – aggregate results.

Sequential read example:

fio --name=seq_read --direct=1 --rw=read --bs=128k --size=1G --numjobs=4 --runtime=60 --group_reporting

Random write example:

fio --name=rand_write --direct=1 --rw=randwrite --bs=4k --size=512M --numjobs=8 --runtime=120 --group_reporting

Mixed random read/write example (70% read, 30% write):

fio --name=mix_randrw --direct=1 --rw=randrw --rwmixread=70 --rwmixwrite=30 --bs=8k --size=1G --numjobs=6 --runtime=180 --group_reporting

Analyze bandwidth (bw), IOPS, and latency (lat) to assess storage subsystem performance under different workloads.

Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

Performance TestingnetworkI/OCPUMemorystress test
Deepin Linux
Written by

Deepin Linux

Research areas: Windows & Linux platforms, C/C++ backend development, embedded systems and Linux kernel, etc.

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.