February 16, 2013
巨大なファイルを高速に作るメモ。
実行結果はさくらのVPS 1GにUbuntu 12.10を入れた環境でのものです。
埋めるというか空っぽのsparse fileですが。
$ time dd if=/dev/zero of=temp.bin bs=1 count=0 seek=1G
0+0 records in
0+0 records out
0 bytes (0 B) copied, 1.1289e-05 s, 0.0 kB/s
dd if=/dev/zero of=temp.bin bs=1 count=0 seek=1G 0.00s user 0.00s system 0% cpu 0.002 total
真面目に書き込む場合の結果です。
$ time dd if=/dev/zero of=temp.bin bs=1G count=1
1+0 records in
1+0 records out
1073741824 bytes (1.1 GB) copied, 29.3218 s, 36.6 MB/s
dd if=/dev/zero of=temp.bin bs=1G count=1 0.00s user 10.84s system 36% cpu 29.666 total
擬似乱数でも気にしないのであれば、/dev/random
や /dev/urandom
を流し込むより openssl rand
コマンドを使うのがいいみたいです。
$ time openssl rand 1073741824 > temp.bin
openssl rand 1073741824 > temp.bin 35.07s user 1.35s system 99% cpu 36.524 otal
/dev/urandom
を流し込んだ場合の結果です。
$ time dd if=/dev/urandom of=temp.bin bs=1G count=1
1+0 records in
1+0 records out
1073741824 bytes (1.1 GB) copied, 134.728 s, 8.0 MB/s
dd if=/dev/urandom of=temp.bin bs=1G count=1 0.00s user 105.87s system 78% cpu 2:14.98 total