The Artima Developer Community
Sponsored Link

Java Buzz Forum
Why drbunix:// is Cool

0 replies on 1 page.

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 0 replies on 1 page
Brian McCallister

Posts: 1282
Nickname: frums
Registered: Sep, 2003

Brian McCallister is JustaProgrammer who thinks too much.
Why drbunix:// is Cool Posted: Apr 22, 2006 11:37 AM
Reply to this message Reply

This post originated from an RSS feed registered with Java Buzz by Brian McCallister.
Original Post: Why drbunix:// is Cool
Feed Title: Waste of Time
Feed URL: http://kasparov.skife.org/blog/index.rss
Feed Description: A simple waste of time and weblog experiment
Latest Java Buzz Posts
Latest Java Buzz Posts by Brian McCallister
Latest Posts From Waste of Time

Advertisement

So, ruby threads have issues. Multiprocessing, on the other hand, works great. I have been doing stuff like:

#!/usr/bin/env ruby

require 'drb'
URI = "drbunix:///tmp/foopie"

class Master
    def initialize(count=100)
        @jobs = []
        count.times do |i|
            @jobs << "Job ##{i}"
        end
    end
    
    def take(n)
      taken = []
      while taken.length < n && !@jobs.empty?
        taken << @jobs.shift
      end
      taken
    end
end

DRb.start_service URI, Master.new

pids = []
10.times do |i|
    pids << fork do
        DRb.start_service
        master = DRbObject.new_with_uri URI
        until (jobs = master.take(2)).empty?
          jobs.each do |j| 
            puts j
            sleep rand
          end
        end
    end
end

puts "started children" 
pids.each { |pid| Process.wait(pid) }

To slam though jobs in ruby. Doing it over unix sockets instead of tcp is just nicer =) It just spreads the workload across processes instead of threads.

Read: Why drbunix:// is Cool

Topic: RedMonk Radio Episode 06 - GreenHat SOA Testing, Old SOA in New Bottles, Retrofitting Management Previous Topic   Next Topic Topic: The best feature in MS-Word has got to be…

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use