Performance Measurement Tools

Essential tools for measuring network and computer performance. Quick reference for performance analysis.


Network Performance

iperf3 - Network Bandwidth Testing

 1# Install
 2sudo apt install iperf3  # Linux
 3brew install iperf3      # macOS
 4scoop install iperf3     # Windows
 5
 6# Server mode
 7iperf3 -s
 8
 9# Client mode (test to server)
10iperf3 -c server_ip
11
12# Test for 30 seconds
13iperf3 -c server_ip -t 30
14
15# Test UDP
16iperf3 -c server_ip -u -b 100M
17
18# Reverse mode (server sends)
19iperf3 -c server_ip -R
20
21# Parallel streams
22iperf3 -c server_ip -P 4
23
24# JSON output
25iperf3 -c server_ip -J > results.json

netstat - Network Statistics

 1# Show all connections
 2netstat -a
 3
 4# Show listening ports
 5netstat -l
 6netstat -tuln  # TCP/UDP numeric
 7
 8# Show statistics
 9netstat -s
10
11# Show routing table
12netstat -r
13
14# Show with process info
15netstat -tulpn  # Linux
16netstat -anv    # macOS
17
18# Continuous monitoring
19netstat -c
20
21# Show specific port
22netstat -an | grep :8080

tcpdump - Packet Capture

 1# Capture on interface
 2sudo tcpdump -i eth0
 3
 4# Capture specific host
 5sudo tcpdump host 192.168.1.1
 6
 7# Capture specific port
 8sudo tcpdump port 80
 9
10# Capture and save to file
11sudo tcpdump -i eth0 -w capture.pcap
12
13# Read from file
14tcpdump -r capture.pcap
15
16# Capture HTTP traffic
17sudo tcpdump -i eth0 'tcp port 80'
18
19# Capture with verbose output
20sudo tcpdump -i eth0 -vv
21
22# Capture first 100 packets
23sudo tcpdump -i eth0 -c 100
24
25# Filter by protocol
26sudo tcpdump -i eth0 icmp
27sudo tcpdump -i eth0 tcp

ping & traceroute

 1# Ping
 2ping google.com
 3ping -c 10 google.com  # 10 packets
 4ping -i 0.2 google.com # Fast ping
 5
 6# Traceroute
 7traceroute google.com
 8traceroute -n google.com  # No DNS lookup
 9
10# Windows
11tracert google.com
12
13# MTR (better traceroute)
14mtr google.com
15mtr -r -c 100 google.com  # Report mode

CPU Performance

top - Process Monitor

 1# Start top
 2top
 3
 4# Sort by CPU
 5top -o %CPU
 6
 7# Sort by memory
 8top -o %MEM
 9
10# Show specific user
11top -u username
12
13# Batch mode (for scripts)
14top -b -n 1
15
16# Show threads
17top -H

htop - Interactive Process Viewer

 1# Install
 2sudo apt install htop  # Linux
 3brew install htop      # macOS
 4
 5# Start htop
 6htop
 7
 8# Keyboard shortcuts:
 9# F2 - Setup
10# F3 - Search
11# F4 - Filter
12# F5 - Tree view
13# F6 - Sort by
14# F9 - Kill process
15# F10 - Quit

perf - Linux Performance Analysis

 1# Install
 2sudo apt install linux-tools-common linux-tools-generic
 3
 4# Record CPU profile
 5sudo perf record -g ./myapp
 6
 7# View report
 8sudo perf report
 9
10# Record for specific duration
11sudo perf record -g -a sleep 30
12
13# Record specific process
14sudo perf record -g -p <PID>
15
16# CPU statistics
17sudo perf stat ./myapp
18
19# Top-like view
20sudo perf top
21
22# Flamegraph generation
23sudo perf record -g -a sleep 30
24sudo perf script > out.perf
25./flamegraph.pl out.perf > flamegraph.svg

Memory Performance

free - Memory Usage

 1# Show memory usage
 2free
 3
 4# Human-readable
 5free -h
 6
 7# Show in MB
 8free -m
 9
10# Continuous monitoring
11free -h -s 2  # Every 2 seconds

vmstat - Virtual Memory Statistics

 1# Show statistics
 2vmstat
 3
 4# Update every 2 seconds
 5vmstat 2
 6
 7# Show 10 updates
 8vmstat 2 10
 9
10# Show in MB
11vmstat -S M 2

ps - Process Status

 1# Show all processes
 2ps aux
 3
 4# Show process tree
 5ps auxf
 6
 7# Show specific user
 8ps -u username
 9
10# Sort by memory
11ps aux --sort=-%mem | head
12
13# Sort by CPU
14ps aux --sort=-%cpu | head
15
16# Show threads
17ps -eLf
18
19# Custom format
20ps -eo pid,ppid,cmd,%mem,%cpu --sort=-%mem | head

Disk Performance

iostat - I/O Statistics

 1# Install
 2sudo apt install sysstat
 3
 4# Show I/O statistics
 5iostat
 6
 7# Update every 2 seconds
 8iostat 2
 9
10# Show extended statistics
11iostat -x 2
12
13# Show specific device
14iostat -x sda 2
15
16# Human-readable
17iostat -h 2

iotop - I/O Monitor

 1# Install
 2sudo apt install iotop
 3
 4# Start iotop
 5sudo iotop
 6
 7# Show only processes doing I/O
 8sudo iotop -o
 9
10# Batch mode
11sudo iotop -b -n 5

df & du - Disk Usage

 1# Show disk space
 2df -h
 3
 4# Show inodes
 5df -i
 6
 7# Show specific filesystem
 8df -h /home
 9
10# Show directory size
11du -sh /path/to/dir
12
13# Show top 10 largest directories
14du -h /path | sort -rh | head -10
15
16# Show all subdirectories
17du -h --max-depth=1 /path

Application Profiling

Go

 1import (
 2    _ "net/http/pprof"
 3    "net/http"
 4)
 5
 6func main() {
 7    go func() {
 8        http.ListenAndServe("localhost:6060", nil)
 9    }()
10    // Your application code
11}
 1# CPU profile
 2go tool pprof http://localhost:6060/debug/pprof/profile?seconds=30
 3
 4# Memory profile
 5go tool pprof http://localhost:6060/debug/pprof/heap
 6
 7# Goroutine profile
 8go tool pprof http://localhost:6060/debug/pprof/goroutine
 9
10# Generate flamegraph
11go tool pprof -http=:8080 profile.pb.gz

Python

 1# cProfile
 2python -m cProfile -o output.prof script.py
 3
 4# View results
 5python -m pstats output.prof
 6
 7# line_profiler
 8@profile
 9def my_function():
10    pass
11
12# Run with
13kernprof -l -v script.py
14
15# memory_profiler
16@profile
17def my_function():
18    pass
19
20# Run with
21python -m memory_profiler script.py

Node.js

 1# CPU profiling
 2node --prof app.js
 3node --prof-process isolate-*-v8.log > processed.txt
 4
 5# Inspect
 6node --inspect app.js
 7# Open chrome://inspect
 8
 9# Clinic.js
10npm install -g clinic
11clinic doctor -- node app.js
12clinic flame -- node app.js
13clinic bubbleprof -- node app.js

Flamegraphs

 1# Install FlameGraph
 2git clone https://github.com/brendangregg/FlameGraph
 3cd FlameGraph
 4
 5# Generate from perf data
 6sudo perf record -F 99 -a -g -- sleep 30
 7sudo perf script > out.perf
 8./stackcollapse-perf.pl out.perf > out.folded
 9./flamegraph.pl out.folded > flamegraph.svg
10
11# Open in browser
12firefox flamegraph.svg

Benchmarking

Apache Bench (ab)

 1# Install
 2sudo apt install apache2-utils
 3
 4# Basic test
 5ab -n 1000 -c 10 http://localhost:8080/
 6
 7# With keep-alive
 8ab -n 1000 -c 10 -k http://localhost:8080/
 9
10# POST request
11ab -n 1000 -c 10 -p data.json -T application/json http://localhost:8080/api
12
13# With authentication
14ab -n 1000 -c 10 -H "Authorization: Bearer token" http://localhost:8080/

wrk - HTTP Benchmarking

 1# Install
 2sudo apt install wrk
 3
 4# Basic test
 5wrk -t12 -c400 -d30s http://localhost:8080/
 6
 7# With script
 8wrk -t12 -c400 -d30s -s script.lua http://localhost:8080/
 9
10# Example script (script.lua)
11wrk.method = "POST"
12wrk.body   = '{"key":"value"}'
13wrk.headers["Content-Type"] = "application/json"

hey - HTTP Load Generator

 1# Install
 2go install github.com/rakyll/hey@latest
 3
 4# Basic test
 5hey -n 1000 -c 10 http://localhost:8080/
 6
 7# With custom headers
 8hey -n 1000 -c 10 -H "Authorization: Bearer token" http://localhost:8080/
 9
10# POST request
11hey -n 1000 -c 10 -m POST -d '{"key":"value"}' http://localhost:8080/api

Monitoring Dashboard


Quick Reference

 1# Network
 2iperf3 -c server_ip              # Bandwidth test
 3netstat -tuln                    # Listening ports
 4tcpdump -i eth0 port 80          # Capture HTTP
 5
 6# CPU
 7top                              # Process monitor
 8htop                             # Interactive monitor
 9perf record -g ./app             # Profile app
10
11# Memory
12free -h                          # Memory usage
13vmstat 2                         # VM stats
14ps aux --sort=-%mem | head       # Top memory processes
15
16# Disk
17iostat -x 2                      # I/O stats
18df -h                            # Disk space
19du -sh /path                     # Directory size
20
21# Benchmarking
22ab -n 1000 -c 10 http://url      # Apache Bench
23wrk -t12 -c400 -d30s http://url  # wrk
24hey -n 1000 -c 10 http://url     # hey

Related Snippets