[ANN] slave-0.2.0

Discussion in 'Ruby' started by ara.t.howard@noaa.gov, Sep 23, 2006.

  1. Guest

    SYNOPSIS

    the Slave class forks a process and starts a drb server in the child using
    any object as the server. the process is detached so it is not required
    (nor possible) to wait on the child pid. a Heartbeat is set up between the
    parent and child processes so that the child will exit of the parent exits
    for any reason - preventing orphaned slaves from running indefinitely. the
    purpose of Slaves is to be able to easily set up a collection of objects
    communicating via drb protocols instead of having to use IPC.

    typical usage:

    obj = AnyClass::new

    slave = Slave::new obj

    p slave.object # handle on drb object
    p slave.uri # uri of the drb object
    p slave.socket # unix domain socket path for drb object
    p slave.psname # title shown in ps/top

    other usage:

    set the pulse_rate used for the Heartbeat

    slave = Slave::new MyClass::new, 'pulse_rate' => 10

    same

    Slave::pulse_rate = 10
    slave = Slave::new MyClass::new

    same

    ENV['SLAVE_PULSE_RATE'] = 10
    slave = Slave::new MyClass::new

    to avoid having a copy of the object in both the parent and child use the
    block form

    slave = Slave::new{ Server::new } # copy only in child!
    server = slave.object

    if both an object AND a block are passed the object is passed to the block
    in the child process

    slave = Slave::new(Server::new){|server| p 'in child!' }

    slaves may be configured via the environment, the Slave class, or via the
    ctor for object itself. attributes which may be configured include

    * socket_creation_attempts
    * pulse_rate
    * psname
    * debug

    HISTORY

    0.2.0:
    incorporated joel vanderWerf's patch such that, if no object is passed the
    block is used to create one ONLY in the child. this avoids having a copy
    in both parent and child is that needs to be avoided due to, for instance,
    resource consumption.


    0.0.1:
    - patch from Logan Capaldo adds block form to slave new, block is run in the
    child

    - added a few more samples/*

    - added Slave#wait

    - added status information to slaves

    - added close-on-exec flag to pipes in parent process

    0.0.0:
    - initial version


    enjoy.

    -a
    --
    in order to be effective truth must penetrate like an arrow - and that is
    likely to hurt. -- wei wu wei
     
    , Sep 23, 2006
    #1
    1. Advertising

  2. On Sep 23, 2006, at 3:52 PM, wrote:

    >
    > SYNOPSIS
    >
    > the Slave class forks a process and starts a drb server in the
    > child using
    > any object as the server. the process is detached so it is not
    > required
    > (nor possible) to wait on the child pid. a Heartbeat is set up
    > between the
    > parent and child processes so that the child will exit of the
    > parent exits
    > for any reason - preventing orphaned slaves from running
    > indefinitely. the
    > purpose of Slaves is to be able to easily set up a collection of
    > objects
    > communicating via drb protocols instead of having to use IPC.
    >
    > <snip>
    >
    > -a



    This is a great library Ara, I am writing a library that wraps up
    the slave lib into another interface for controlling jobs with timers
    and a few other things. So the master process holds a thread pool
    with references to slave classes in it so that you can set a limit on
    the number of running slaves. Using it to offload jobs from a rails
    app to not hold up the http flow. I have a question though. What
    would be the cleanest way to have a slave class signal that it is
    finished working and needs to be kill'ed. I know there is the
    shutdown method that you could call from the master process to
    shutdown a slave. But is there something similar that can be called
    from a slave process? Or should I just let the slave process exit!
    and let the heartbeat cleanup after the dead slaves?

    Thanks
    -Ezra
     
    Ezra Zygmuntowicz, Sep 24, 2006
    #2
    1. Advertising

  3. Guest

    On Sun, 24 Sep 2006, Ezra Zygmuntowicz wrote:

    > This is a great library Ara, I am writing a library that wraps up the
    > slave lib into another interface for controlling jobs with timers and
    > a few other things. So the master process holds a thread pool with
    > references to slave classes in it so that you can set a limit on the
    > number of running slaves. Using it to offload jobs from a rails app to
    > not hold up the http flow. I have a question though. What would be the
    > cleanest way to have a slave class signal that it is finished working
    > and needs to be kill'ed. I know there is the shutdown method that you
    > could call from the master process to shutdown a slave. But is there
    > something similar that can be called from a slave process? Or should I
    > just let the slave process exit! and let the heartbeat cleanup after
    > the dead slaves?


    hmmm. good question. i could add a feature where at_exit handlers could be
    added, somthing like


    s = Slave.new( :at_exit => lambda{}){ do_child_stuff }


    would that be sufficient?

    -a
    --
    in order to be effective truth must penetrate like an arrow - and that is
    likely to hurt. -- wei wu wei
     
    , Sep 24, 2006
    #3
  4. On Sep 24, 2006, at 8:57 AM, wrote:

    > On Sun, 24 Sep 2006, Ezra Zygmuntowicz wrote:
    >
    >> This is a great library Ara, I am writing a library that wraps up
    >> the
    >> slave lib into another interface for controlling jobs with timers
    >> and
    >> a few other things. So the master process holds a thread pool with
    >> references to slave classes in it so that you can set a limit on the
    >> number of running slaves. Using it to offload jobs from a rails
    >> app to
    >> not hold up the http flow. I have a question though. What would
    >> be the
    >> cleanest way to have a slave class signal that it is finished
    >> working
    >> and needs to be kill'ed. I know there is the shutdown method that
    >> you
    >> could call from the master process to shutdown a slave. But is there
    >> something similar that can be called from a slave process? Or
    >> should I
    >> just let the slave process exit! and let the heartbeat cleanup after
    >> the dead slaves?

    >
    > hmmm. good question. i could add a feature where at_exit handlers
    > could be
    > added, somthing like
    >
    >
    > s = Slave.new( :at_exit => lambda{}){ do_child_stuff }
    >
    >
    > would that be sufficient?
    >
    > -a



    Ara-

    Yeah that would work fine I think. So that would call the lambda
    when the child process calls exit! ? Is there any way for a slave to
    call back to the parent process? Or is there a way to get the drb uri
    of the parent from the child?

    Thanks for slave and all your other codeforpeople ;) I have learned
    a lot by reading through your code and by googling "cat a.rb" ;)


    Cheers-
    -Ezra
     
    Ezra Zygmuntowicz, Sep 24, 2006
    #4
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Colin Jackson

    VHDL for FPGA VME Slave

    Colin Jackson, Aug 15, 2003, in forum: VHDL
    Replies:
    2
    Views:
    5,000
    Tullio Grassi
    Aug 19, 2003
  2. [ANN] slave-1.0.0

    , Oct 13, 2006, in forum: Ruby
    Replies:
    2
    Views:
    136
  3. Ara.T.Howard

    [ANN] slave-1.1.0

    Ara.T.Howard, Nov 28, 2006, in forum: Ruby
    Replies:
    11
    Views:
    211
  4. [ANN] slave-1.2.0.rb

    , Dec 8, 2006, in forum: Ruby
    Replies:
    0
    Views:
    157
  5. Ara.T.Howard

    [ANN] slave-1.2.1

    Ara.T.Howard, Apr 27, 2007, in forum: Ruby
    Replies:
    1
    Views:
    116
    John Stoffel
    Feb 17, 2009
Loading...

Share This Page