[Backgroundrb-devel] Stopping DRb after using BackgrounDRb::MiddleManDRbObject.init

Ezra Zygmuntowicz ezmobius at gmail.com
Fri Jan 19 19:01:19 EST 2007

On Jan 19, 2007, at 3:37 PM, Robert Bjarnason wrote:

> Hi Ezra,
> I would like to control which uri is used to start the DRb  
> connection for Rails based load-balancing purposes from multiple  
> mongrels connecting to multiple backgroundrbs running on several  
> boxes.  I don't see how I could BackgrounDRb::MiddleManRailsProxy  
> for this purpose.  Any ideas?
> Thanks,
> Robert


	Ahh ok I see. Well maybe something like this(untested!)

# start ----
require 'pathname'
BACKGROUNDRB_ROOT = Pathname.new(RAILS_ROOT).realpath.to_s
require 'backgroundrb'

# Set up a MiddleMan for the BackgrounDRb server configured for this
# particular instance of Rails.
class BackgrounDRb::MiddleManProxyBalancer
   def self.init(server_pool={})
     config = { :config => "#{BACKGROUNDRB_ROOT}/config/ 
backgroundrb.yml" }
     @@proxy_members = {}
     server_pool.each {|num, drburi|
       @@proxy_members[num] = BackgrounDRb::MiddleManDRbObject.init 
(:uri => drburi)
     return self

   def self.[](key)


server_pool = {
   1 => "druby://localhost:22221",
   2 => "druby://localhost:22222",
   3 => "druby://",
   4 => "druby://"

MiddleManPool = BackgrounDRb::MiddleManProxyBalancer.init(server_pool)

# end ----

	Then you would use the MiddleManPool in your rails apps instead of  
the normal rails proxy. You would have to key the middleman you want  
my the number in the server_pool. So it would look like this to use:

session[:jobkey] = MiddleManPool[1].new_worker( :class => :someshit )

session[:otherjobkey] = MiddleManPool[2].new_worker( :class  
=> :someshit )

worker = MiddleManPool[1].worker(session[:jobkey])

worker = MiddleManPool[2].worker(session[: otherjobkey])

	This is just a sketch but I think you could take this and run with  
it. You would use the above to replace the  
BackgrounDRb::MiddleManRailsProxy  in the lib dir of the plugin so  
that rails would load your new proxy instead of the old connection  

	So this would make sure that every mongrel had a connection to every  
server in the server_pool. ANd you woudl just need to always use the  
number of which drb server you want from the pool. But it caches the  
connection so that each mongrel only gets one connection to every drb  
server. No new connection should be made after the thing boots  
because the connections are cached.

	Make sense? Please give this or something like this a shot and let  
us know how it goes for you. I am interested in adding something like  
this to the project.


-- Ezra Zygmuntowicz 
-- Lead Rails Evangelist
-- ez at engineyard.com
-- Engine Yard, Serious Rails Hosting
-- (866) 518-YARD (9273)

More information about the Backgroundrb-devel mailing list