Multi-threaded client actions


#1

I’m running some actions that are lengthy, and was contemplating spawning
off ruby threads to execute them in parallel within a recipe. (Formatting
many large file systems)
Thinking about it a bit more, that’s probably going to need to be wrapped in
ruby_block.

Do folks have experience or thoughts on this?


#2

So, I ended up with something like this:
disks.each { | k |
a = execute “make filesystem on #{k[:name]}” do
command "echo ‘formatting #{k[:name]}’ ; mkfs.ext3 -F #{k[:name]}"
returns [0,1]
not_if “tune2fs -l #{k[:name]}” # if there’s a superblock - assume
good.
action :nothing
end
actions << a
}

spawn threads as part of the convergence phase, and format

the file systems in parallel. Wait for activity to complete.

ruby_block “Format things in parallel” do
block do
threads = []
actions.each { | a|
threads << Thread.new { |t| a.run_action(:run)}
}
threads.each { |t| t.join }
end
end

Does that seem reasonable?

On Thu, Sep 15, 2011 at 12:37 PM, andi abes andi.abes@gmail.com wrote:

I’m running some actions that are lengthy, and was contemplating spawning
off ruby threads to execute them in parallel within a recipe. (Formatting
many large file systems)
Thinking about it a bit more, that’s probably going to need to be wrapped
in ruby_block.

Do folks have experience or thoughts on this?