Vote count:
0
My question is specific to MRI. It looks like since Ruby 1.9 all threads are native but MRI continues to run them one at a time. This sounds like parallel execution of threads is not possible in MRI but does using Threads improve concurrency in your program for something that looks like this?
In other words do you get any benefit from using threads to upload a lot of files onto S3?
# http://ift.tt/1GmM9Y7
...
file_number = 0
mutex = Mutex.new
threads = []
thread_count.times do |i|
threads[i] = Thread.new {
until files.empty?
mutex.synchronize do
file_number += 1
Thread.current["file_number"] = file_number
end
file = files.pop rescue nil
next unless file
data = File.open(file)
if File.directory?(data)
data.close
next
else
obj = s3_bucket.objects[path]
obj.write(data, { acl: :public_read })
data.close
end
end
}
end
threads.each { |t| t.join }
...
asked 1 min ago
Do threads in Ruby improve concurrency?
Aucun commentaire:
Enregistrer un commentaire