lp / abundance

Ruby SMP Processing Tool and Non-Blocking Process Mechanism

This URL has Read+Write access

name age message
file README Loading commit data...
file Rakefile
directory lib/
directory test/
README
    .    .                 .                  
   / \   |                 |                  
  /___\  |.-. .  . .--. .-.| .-.  .--. .-..-. 
 /     \ |   )|  | |  |(   |(   ) |  |(  (.-' 
'       `'`-' `--`-'  `-`-'`-`-'`-'  `-`-'`--'
               
///////////////////////////////////////////////////////////////////////////////////////

This class provides a mean to parallelize the execution of your program processes.
Based on the low maintenance Gardener,Garden,Seed natural design pattern.

Its for:
* forking otherwise blocking loops in a non-blocking fashion
* a simple abstraction for loopback communication with a forked execution
* concurrent batch processing
* scaling process intensive computations to multi-core parallel execution

And not:
* a replacement for Thread.new invocations
* a replacement for Thread friendly programming languages like Erlang

Its initial implementation uses:
* pure ruby
* standard forks as mean to parallel non-blocking execution
* fast UDP loopback sockets for process fork communication.
* serialization friendly communication with process forks
* a tier queuing fork, as a packet control middle man between process forks and the non-blocking process client
* an elemental namespace: a process queue, named the Garden, with concurrent workers, named Rows, all this getting 
orchestrated by a Gardener.

///////////////////////////////////////////////////////////////////////////////////////

Quick Start:

1. gem install abundance
2. require abundance
3. use the Abundance.gardener method to define your forking process.  Its attached block IS THE FORK.  Its return value 
IS YOUR CLIENT INSTANCE.
4. Abundance.gardener has simple commodities:
    * infinite loop inside Abundance.grow method's block
    * initialisation before Abundance.grow invocation, just put it there... you can use Abundance.init_status if you 
    need init confirmation from the forks, otherwise don't bother.
    * reader and sender for socket communication with your client.  seed.sprout reads, seed.crop sends.
5. use the client to communicate with forks: client.seed sends, client.harvest reads.
6. for detailed client docs: http://abundance.rubyforge.org/ruby-doc/classes/Gardener.html , and full docs: 
http://abundance.rubyforge.org/ruby-doc/ 
 
///////////////////////////////////////////////////////////////////////////////////////

Example:
 gardener = Abundance.gardener( :wheelbarrow => 8192, :rows => 2, :init_timeout => 2) do

  processor = SpecialProcess.new
  if processor.started_successfully?
    Abundance.init_status(true, processor.init_message)
  else
    Abundance.init_status(false, processor.init_message)
  end

  Abundance.grow do |seed|
    command = seed.sprout 
    results = processor.parse(command) 
    seed.crop( true, results)  
  end
 
 end

 id1 = gardener.seed('command1')
 id2 = gardener.seed('command2')

 result1 = gardener.harvest(id1)
 result2 = gardener.harvest(id2)

 # with many more seeds over here

 gardener.close

///////////////////////////////////////////////////////////////////////////////////////

Note that as of this first version of the library, there is no way to have two gardeners
simultaneously in your program, they will just get to killing each other.

Also, I choose to use a funky language called Ruby for programming, It inspired
me going into this crazy garden related namespace.  Sorry if anybody gets lost in it,
but the intent was for me quite the opposite, as real concepts help me to remember abstract logic.


///////////////////////////////////////////////////////////////////////////////////////

Copyright (c) 2008 Louis-Philippe Perron

Permission is hereby granted, free of charge, to any person
obtaining a copy of this software and associated documentation
files (the "Software"), to deal in the Software without
restriction, including without limitation the rights to use,
copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the
Software is furnished to do so, subject to the following
conditions:

The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
OTHER DEALINGS IN THE SOFTWARE.