Skip to content

Instantly share code, notes, and snippets.

@foreverman
Created August 31, 2011 14:22
Show Gist options
  • Save foreverman/1183662 to your computer and use it in GitHub Desktop.
Save foreverman/1183662 to your computer and use it in GitHub Desktop.
if GC.respond_to?(:copy_on_write_friendly=)
GC.copy_on_write_friendly = true
end
jobs_per_process = 100
process_count = 10
User.find_in_batches(:batch_size => jobs_per_process * process_count) do |group|
batches = group.in_groups(process_count)
batches.each do |batch|
Process.fork do
ActiveRecord::Base.establish_connection
# Do the actual work
batch.each {|user| .. }
end
end
Process.waitall
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment