Skip to content

Instantly share code, notes, and snippets.

@jnewland
Created June 17, 2010 16:50
Show Gist options
  • Save jnewland/442388 to your computer and use it in GitHub Desktop.
Save jnewland/442388 to your computer and use it in GitHub Desktop.
# estimate the duration of an ALTER TABLE statement in mysql
# this code estimates the worst case, as most of the time, an ALTER will result in a table that is smaller than the original
percentage = 0
interval = 10
while(true) do
begin
sleep(interval)
new_percentage = (File.size('#sql-137f_5dee5a6.ibd')*1.0 / File.size('users.ibd')*1.0)
change = new_percentage - percentage
intervals = (1.0-percentage)/change
duration = intervals*interval
eta = Time.now + duration
percentage = new_percentage
puts "percent done: #{percentage}"
puts "eta: #{eta}"
puts "estimated duration: #{duration/60} minutes (#{duration/60/60} hours)"
rescue RangeError
retry
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment