Skip to content

Instantly share code, notes, and snippets.

@jthornber
Created January 21, 2014 14:08
Show Gist options
  • Save jthornber/8540733 to your computer and use it in GitHub Desktop.
Save jthornber/8540733 to your computer and use it in GitHub Desktop.
#!/usr/bin/env ruby
dev_size = 2048 * 1024 * 1024 # 1T
block_size = 2048 * 1
nr_blocks = dev_size / block_size
io_size = 128
#----------------------------------------------------------------
def calc_cows(n, nr_blocks)
alpha = (nr_blocks - 1).fdiv(nr_blocks)
num = 1.0 - (alpha ** n)
den = 1.0 - alpha
num / den
end
# find the 50% mark
step = 1024
n_low = 0
n_high = 1000000
half = nr_blocks.fdiv(2)
fifty_percent = catch :done do
loop do
if n_high - n_low == 1
throw :done, n_high
end
mid = (n_high + n_low) / 2
c = calc_cows(mid, nr_blocks)
if c < half
n_low = mid
elsif c > half
n_high = mid
else
throw :done, n_high
end
end
end
one_t = 2048 * 1024 * 1024
userland_io = fifty_percent * io_size
puts "fifty percent cows takes #{fifty_percent} ios, #{userland_io / 2048}m sectors of userland io, throughput fraction #{use\
rland_io.fdiv(userland_io + one_t) * 100.0}%"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment