💾 Benchmark Write Speed to a Disk
Sometimes you need to test how fast a (network) disk can handle writes.
A common method is:
- Write one large file
- Split it into many small files
- Benchmark copying them using
rsyncorcp
Why? Some storage systems handle large sequential writes very well, but struggle with many small files (metadata overhead, IOPS limits, etc.).
1️⃣ Create a Large Random File
Generate a large file locally:
# Create a ~1GB file (conv=fdatasync: really write it to disk before dd stops)
dd if=/dev/urandom of=random_file bs=1M count=1024 conv=fdatasync
Measure how long it takes:
time dd if=/dev/urandom of=random_file bs=1M count=1024 conv=fdatasync
💡 Use
count=10for ~10GB, etc.
Alternative example (slightly smaller blocks):
dd if=/dev/urandom of=random_file bs=128K count=10000
2️⃣ Split Into Many Small Files
Create a directory and split the large file into 1MB chunks:
mkdir random_dir
split -b 1M -a 3 random_file random_dir/file_
This creates many small files like:
file_aaa
file_aab
file_aac
...
3️⃣ Benchmark with rsync
Copy Single Large File
rsync --info=progress2 random_file /target/path/
Copy Many Small Files
rsync --info=progress2 -r random_dir/ /target/path/
Example targets:
rsync --info=progress2 -r random_dir/ /mnt/storage1/test/
rsync --info=progress2 -r random_dir/ /mnt/storage2/test/
rsync --info=progress2 -r random_dir/ /mnt/bigstorage/test/
4️⃣ Local Copy Benchmark
You can also benchmark locally:
rsync --info=progress2 -r random_dir/ random_dir2/
Or using cp:
time cp -r random_dir random_dir2
5️⃣ Metadata / IOPS Test (Many Small Files)
To stress-test metadata performance:
time bash -c 'for i in $(seq 1 1000); do touch random_dir/$i; done'
This tests how fast the filesystem can create many small files.
🧪 What This Tests
| Test Type | What It Measures |
|---|---|
dd large file | Sequential write throughput |
rsync large file | Network + sequential performance |
rsync small files | Metadata + IOPS + network |
touch loop | Pure metadata performance |
⚠️ Pitfalls
- Without
conv=fdatasync(oroflag=direct),ddmeasures how fast Linux fills its memory cache, not the disk. That’s why the commands above use it. /dev/urandomitself can be slower than a fast NVMe disk. To test only the disk, create the random file once and then copy it, or write zeros:dd if=/dev/zero of=/target/zero_file bs=1M count=1024 conv=fdatasync(compressing storage will cheat with zeros, though).
🧰 The proper tool: fio
For real numbers (throughput and IOPS, sequential and random), use fio:
sudo apt install fio # or: sudo dnf install fio
# sequential write, 1 GB, 1 MB blocks
fio --name=seqwrite --filename=/target/path/fio.test --rw=write --bs=1M --size=1G --direct=1
# random 4k writes: what databases and many small files feel like
fio --name=randwrite --filename=/target/path/fio.test --rw=randwrite --bs=4k --size=1G --direct=1 --iodepth=32 --ioengine=libaio --runtime=60 --time_based
Delete fio.test afterwards.