Noobie Question: Using Parallel against an array

I guess this is more of a design question, but I’m trying to use
Parallel to spawn 10 threads of the same process.

trunk = cat pools

trunk.each do |pool|
Parallel.each(["#{pool}"], :in_threads=>10) { |k| rsync -av user@machine:/#{k} /mnt/backup/#{k} }
end

I may be doing this all wrong, but currently I only see one thread
running (am I doing something wrong, or am I incorrect in my
understanding of threading?)

Thanks

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA512

On 11/9/11 1:07 AM, brettg wrote:

I guess this is more of a design question, but I’m trying to use
Parallel to spawn 10 threads of the same process.

trunk = cat pools

trunk.each do |pool| Parallel.each(["#{pool}"], :in_threads=>10) {
|k| rsync -av user@machine:/#{k} /mnt/backup/#{k} } end

Use threadify:
% gem i threadify

% cat a.rb
require threadify

… add some items for processing to mylist

result_listmylist.threadify do |item|

do what you want with item

end

If you want 10 threads processing the result:

% time ruby -rthreadify -e ‘puts (1…10).to_a.threadify(10) {|i|
sleep(1); i+1}’
2
3
4
5
6
7
8
9
10
11
ruby -rthreadify -e ‘puts (1…10).to_a.threadify(10) {|i| sleep(1);
i+1}’ 0.41s user 0.03s system 27% cpu 1.617 total


All the best, Sandor Sz

trunk.each do |pool|
Parallel.each(["#{pool}"], :in_threads=>10) { |k| rsync -av user@machine:/#{k} /mnt/backup/#{k} }
end

Instead, try

Parallel.each(trunk.lines, :in_threads => 10) { |k| # yadayada }