After reading all posts about parallelism in Ruby, I got only confused, so I will describe what I want to do.
I have names
that contains around 1000 names.
names
=> [{"name"=>"tickets"}, {"name"=>"events"}, {"name"=>"channel"}, {"name"=>"primes"}]
For each name I want to drop a table if it exists using pg.
drop_str = "DROP TABLE IF EXISTS %s ;"
create_str = "CREATE TABLE %s (id SERIAL PRIMARY KEY,bkk varchar(255))"
names.each do |name|
conn.exec((drop_str % name["name"]) + (create_str % name["name"]))
end
But, I do not want to drop tables one after another one. I want to do it in parallel.
My idea is to use following:
threads = []
drop_str = "DROP TABLE IF EXISTS %s ;"
create_str = "CREATE TABLE %s (id SERIAL PRIMARY KEY,bkk varchar(255))"
names.each do |name|
threads.push(Thread.new{conn.exec((drop_str % name["name"]) + (create_str % name["name"]))})
end
and then to join the threads.
In reality will the tables be dropped in parallel or still one after another one?