@
pagxir 模拟瓶颈在 io 也很好模拟,qemu 贴心的提供了限制 io 速度的方法,用 throttling.bps-total 限制就可以
限速到 10MB 的时候
/ # time sh -c 'dd if=/dev/sda bs=2M | gzip > /dev/null'
8+0 records in
8+0 records out
16777216 bytes (16.0MB) copied, 1.579849 seconds, 10.1MB/s
real 0m 1.59s
user 0m 0.92s
sys 0m 0.27s
/ # time sh -c 'gzip -c /dev/sda > /dev/null'
real 0m 1.53s
user 0m 0.97s
sys 0m 0.11s
作为对比,如果管道前面是 cat
/ # time sh -c 'cat /dev/sda | gzip > /dev/null'
real 0m 1.53s
user 0m 0.88s
sys 0m 0.24s
具体用时可能略有浮动( gzip 这边就很稳定在 1.53 ,dd 组有时候有异常数据到两秒以上),但是差距还是在这的
dd 的问题是:write 它也会阻塞,阻塞了之后 read 自然也不会被调用,压缩用的 cpu 太少了,以至于 io 是瓶颈的时候性能并没有啥太大区别)
关于 dd 作为缓冲的作用,有好多文章写了这个问题
https://unix.stackexchange.com/questions/345072/can-dd-be-used-to-add-a-buffer-to-a-pipehttps://unix.stackexchange.com/questions/21918/utility-to-buffer-an-unbounded-amount-of-data-in-a-pipeline