Can I simulate a slow hard drive?

I have hunch that a certain intermittent bug might only manifest itself when there is a slow disk read rate. Troubleshooting is difficult because I can't reliably reproduce it.

Short of simply gobbling IO with a high priority process, is there any way for me to simulate having a slow hard drive?


Solution 1:

Use nbd, the Network Block Device, and then rate limit access to it using say trickle.

sudo apt-get install nbd-client nbd-server trickle

Solution 2:

# echo 1 > /proc/sys/vm/drop_caches

That'll slow you down :)

It'll force you to read from disk, instead of taking advantage of the cached page.

If you really wanted to get sophisticated you could do something like fake a read error every nth time using the scsi fault injection framework.

http://scsifaultinjtst.sourceforge.net/

Solution 3:

Have a USB 1.1 hub? Or a slow SD card? They'll get you down to under 10mbps.

Solution 4:

This is by no means a complete solution, but it may help in conjunction with other measures: There is an I/O scheduler much like a process scheduler, and it can be tweaked.

Most notably, you can actually choose amongst different schedulers:

~# cat /sys/block/sda/queue/scheduler 
noop anticipatory deadline [cfq] 
~# echo "deadline" > /sys/block/sda/queue/scheduler
~# cat /sys/block/sda/queue/scheduler 
noop anticipatory [deadline] cfq 
~# 

deadline may help you get more strongly reproducible results.

noop, as its name implies, is insanely dumb, and will enable you to wreck absolute havoc on I/O performance with little effort.

anticipatory and cfq both try to be smart about it, though cfq is generally the smarter of the two. (As I recall, anticipatory is actually the legacy scheduler from right before the kernel started supporting multiple schedulers.)

Solution 5:

You can use a Virtual Machine and throttle disk access ... here are some tips about how do it in Virtualbox 5.8. Limiting bandwidth for disk images https://www.virtualbox.org/manual/ch05.html#storage-bandwidth-limit