Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
n_shards = 128
n_simulations = 1_000_000
processed_booted_for_minimum_two_per_shard = []
n_simulations.times do |i| # Number of simulations
booted = 0
booted_by_shard = [0] * n_shards
done = [false] * n_shards
done_count = 0
until done_count == n_shards
shard = rand(n_shards) # 'roll the die', or 'boot the process'
booted += 1
if (booted_by_shard[shard] += 1) >= 2 && !done[shard]
done[shard] = true
done_count += 1
end
end
processed_booted_for_minimum_two_per_shard << booted
end
processed_booted_for_minimum_two_per_shard.sort!
booted = processed_booted_for_minimum_two_per_shard
puts "Max: #{booted.max}"
puts "Min: #{booted.min}"
puts "P50: #{booted[booted.size / 2]}"
puts "P99: #{booted[(booted.size / 100 * 99.0).to_i]}"
puts "P999: #{booted[(booted.size / 100 * 99.9).to_i]}"
puts "P9999: #{booted[(booted.size / 100 * 99.99).to_i]}"
# Max: 2829
# Min: 507
# P50: 939
# P99: 1532
# P999: 1849
# P9999: 2167
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment