[Backgroundrb-devel] Thread Pool Size?

Brian Mulloy brian at swivel.com
Fri Dec 8 22:59:15 EST 2006

Hi Ezra,

I did the upgrade to 0.2.1.  I am going to adjust how I am using the workers
based on your suggestions.

However, here is a unit test I wrote, that for better or worse has the
behavior I was hoping for.

The test creates new workers and asserts after each worker that the # of
worker threads is less than I specified with the -s option on backgroundrb

class FooWorker < BackgrounDRb::Worker::RailsBase
  def do_work(args)
    sleep 1

def test_middle_man_processes
  # thread pool size
  max_bdrb_threads = 2

  # stop bdrb just in case
  %x(RAILS_ENV=test; #{RAILS_ROOT}/script/backgroundrb stop -- -c

  # start bdrb int test with thread pool size
  %x(RAILS_ENV=test; #{RAILS_ROOT}/script/backgroundrb start -- -c
backgroundrb_test -s #{max_bdrb_threads})

  # give bdrb time to start

  # shouldn't have to do this, but we do
  ENV['RAILS_ENV'] = 'test'

  10.times do
     MiddleMan.new_worker :class => :foo_worker
     worker_count = %x(pstree | grep -v grep | grep #{:foo_worker} | wc
-l).gsub("\n", '').to_i
     puts "worker_count: #{worker_count} max_bdrb_threads:
     # assert that thread pool size is less than what we specified
     assert worker_count <= max_bdrb_threads, "expected #{max_bdrb_threads}
workers, was #{worker_count}"

  # shouldn't have to do this, but we do
  %x(RAILS_ENV=test; #{RAILS_ROOT}/script/backgroundrb stop -- -c
  ENV['RAILS_ENV'] = orig_env

thanks again for the help.  i'm going back to your other suggestions now.

On 12/8/06, Brian Mulloy <brian at swivel.com> wrote:
>         You are using the latest release of backgroundrb?
> module BackgrounDRb
>   VERSION = "0.2.0"
> end
> doh, I am going to upgrade and then give it another go.
> these are excellent thoughts, Ezra, thanks.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://rubyforge.org/pipermail/backgroundrb-devel/attachments/20061208/33913125/attachment-0001.html 

More information about the Backgroundrb-devel mailing list