jthopple / babypool forked from benb/executor

Trivially small thread pool implementation for Ruby

This URL has Read+Write access

jthopple (author)
Fri Oct 16 08:34:57 -0700 2009
commit  8d9429540902782cd1b6d5b0cf011057983fdcf4
tree    8cbfc32f93dde6ef06090974841919430fc521d4
parent  4dee6298f8fa76a469a363f67f19c8762a3ffe62
name age message
file .gitignore Loading commit data...
file LICENCE
file README.rdoc
file babypool.gemspec
directory lib/
README.rdoc

Baby Pool — Simple thread pool for Ruby. Released under the "MIT" license

Baby Pool is a simple, but solid implementation of a thread pool using Ruby green threads. Pools are initialized with a thread count and an execution limit. Baby Pool creates an array or workers each in their own thread that listen for incoming jobs.

The pool will continue to accept work until it is drained by calling the drain method.

A quick example:

  • Initialize the pool with a thread count and an execution limit. Each thread’s worker will timeout it’s current job when it reaches the pool’s execution limit.
          pool = BabyPool.new(:thread_count => 2, :execution_limit => 20)
    
  • Give the pool 20 jobs to do.
          (0..20).each do |job|
            pool.work(job) do
              puts "Thread #{i} handling job #{job}."
            end
          end
    
  • When you are done, shut down the pool by calling the drain method
          pool.drain