Mac: Slowing Down Your Disk Speed by 60x
Sometimes in the development process, we need to simulate slow disk conditions to verify if our code can still function on low-performance machines. Typically, we would use cgroup or Docker for this purpose, but it can be cumbersome on a MacBook. However, there’s a built-in tool on macOS that can help us achieve this: dmc.
This piece was originally published in the Medium MPP plan. If you’re a Medium user, feel free to follow me on Medium. Thanks!
Using dmc
macOS comes with dmc, which we can explore using dmc -h.
1 | ➜ /tmp dmc -h |
It offers various disk profiles to choose from:
1 | ➜ /tmp dmc list |
Each profile corresponds to different speed modes, such as:
1 | ➜ /tmp dmc show 0 |
Using it is straightforward. Suppose our disk is mounted on /tmp/data, and we want to set it to level 0. We simply execute:
1 | sudo dmc start /tmp/data 0 |
Then, to verify the status:
1 | ➜ /tmp dmc status /tmp/data |
Verification
We can validate using the fio tool:
1 | ➜ /tmp fio --filename=./data/test1 -direct=1 --rw=write --ioengine=posixaio --bs=1m --iodepth=32 --size=1G --numjobs=1 --runtime=60 --time_base=1 --group_reporting --name=test-seq-read --log_avg_msec=1000 |
Writing a 1GB file sequentially yields a speed of only 95.4MB/s, with IOPS at 91:
1 | Run status group 0 (all jobs): |
Now, with dmc turned off and the same command:
1 | /tmp sudo dmc stop /tmp/data |
The test results in 3211MB/s and IOPS of 3061, which represents the true speed of the disk:
1 | WRITE: bw=3062MiB/s (3211MB/s), 3062MiB/s-3062MiB/s (3211MB/s-3211MB/s), io=179GiB (193GB), run=60006-60006msec |
In conclusion, dmc is quite handy in testing scenarios. I hadn’t known about this software before; if you find it useful, give it a try.