Skip to content

Instantly share code, notes, and snippets.

@ddk50
Created October 28, 2016 09:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ddk50/1fafad9f9ae246c575b9312e9c9cdd8f to your computer and use it in GitHub Desktop.
Save ddk50/1fafad9f9ae246c575b9312e9c9cdd8f to your computer and use it in GitHub Desktop.
rmとddのベンチマーク
#!/usr/bin/env ruby
# -*- coding: utf-8 -*-
# 以下2つのプロセスを用意して、同時に実行
# 1つ目のプロセスで1MBのファイルを40000個削除する
# 2つ目のプロセスでddで/dev/zeroから1GBファイルをディスクにwrite
# * 40000ファイルrmとddを同時に行う(チョークなし)実験結果
# 1. 1073741824 bytes (1.1 GB) copied, 13.3225 s, 80.6 MB/s
# 2. 1073741824 bytes (1.1 GB) copied, 14.1681 s, 75.8 MB/s
# 3. 1073741824 bytes (1.1 GB) copied, 14.2344 s, 75.4 MB/s
# 4. 1073741824 bytes (1.1 GB) copied, 13.2137 s, 81.3 MB/s
# 5. 1073741824 bytes (1.1 GB) copied, 14.33 s, 74.9 MB/s
# 平均: 77.60 MB/s
# * 40000rmとddを同時に行う(rm側にチョークあり, 1ファイル消すごとに50ms)実験結果
# 1. 1073741824 bytes (1.1 GB) copied, 15.1325 s, 71.0 MB/s
# 2. 1073741824 bytes (1.1 GB) copied, 17.3953 s, 61.7 MB/s
# 3. 1073741824 bytes (1.1 GB) copied, 16.9412 s, 63.4 MB/s
# 4. 1073741824 bytes (1.1 GB) copied, 17.0393 s, 63.0 MB/s
# 5. 1073741824 bytes (1.1 GB) copied, 17.2306 s, 62.3 MB/s
# 平均: 64.28 MB/s
# $ cat /sys/block/sda/queue/scheduler
# noop [deadline] cfq
TARGET_DIR = "/tmp/rmbench"
NUM_OF_FILES = 40000
CHOKE_DELETE = false
def run
puts "prepare #{NUM_OF_FILES} files in #{TARGET_DIR}..."
prepare_many_files(NUM_OF_FILES)
puts "done"
puts "start benchmark"
pid = Process.fork {
# 子プロセスの処理
# 1000ファイル削除
do_rm_many_files(NUM_OF_FILES)
puts "done rm files"
}
do_stress_io
puts "done dd"
Process.kill(:INT, pid)
Process.waitpid pid
end
def prepare_many_files(numoffiles)
`rm -rf #{TARGET_DIR}/*`
ary = [].fill(1, 0..(1024 * 1024))
packed = ary.pack('C*')
numoffiles.times{|id|
File.open("#{TARGET_DIR}/#{id}", "wb") do |file|
file.write(packed)
end
}
end
def do_rm_many_files(numoffiles)
## ret = `rm -rf /tmp/rmbench/*`
## p ret
numoffiles.times{|id|
File.delete("#{TARGET_DIR}/#{id}")
if CHOKE_DELETE
sleep(0.05)
end
}
end
def gracefile_rm_many_files(numoffiles)
end
def do_stress_io
ret = `time dd if=/dev/zero of=/tmp/hdparm_write.tmp ibs=1M obs=1M count=1024 oflag=dsync,direct`
end
run
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment