<div>I'm on BDRB v 1.0.3 and am trying to understand how thread_pool and pool_size work. I have to kick of dozens of jobs on schedule (each hour or so). Other than the fact that they're all accessing the same DB there's no reason for them to not run in parallel. thread_pool/pool_size should be the way to go right?</div>
<div><br></div><div>I've put in sample code with its results below:</div><div><br></div><div>My Rails controller kicks off 5 jobs in a loop - each calling the run_concurrent method in my foo worker. run_concurrent then calls my_actual_method which just logger.infos a message with a time stamp and sleeps for 5 seconds to simulate a long running job. I did this as per <a href="http://backgroundrb.rubyforge.org/workers/#thread_pool">http://backgroundrb.rubyforge.org/workers/#thread_pool </a>Since I'm calling this via a defer and have a pool size of 10, I expect to see that my_actual_method actually gets called 5 times in quick succession (since the pool size is greater than the # of calls). However I find that run_concurrent doesn't even call my_actual_method. Here's the output from my backgroundrb log when I go to <a href="http://mysite.com/some/foobar" target="_blank">http://mysite.com/some/foobar</a></div>
<div><br></div><div>Can someone help me understand what I'm doing wrong here?</div><div><br>Thanks,</div><div><br>Raghu</div>
<div><div>====================================================<br></div><div><span class="Apple-style-span" style="font-weight: bold;"><span class="Apple-style-span" style="background-color: rgb(255, 255, 51);">Rails controller code</span></span></div>
</div>
<div>class SomeController < ApplicationController</div><div> def foobar</div><div> i = 0</div><div> while i < 5</div><div> worker = MiddleMan.worker(:foo_worker)</div>
<div> result = worker.run_concurrent(:job_key => random_string(10))</div><div> i += 1</div><div> end</div><div> render :text => 'all done at ' + Time.now.to_s</div>
<div><br></div><div> end</div><div>end</div><div>====================================================</div><div><span class="Apple-style-span" style="font-weight: bold;"><span class="Apple-style-span" style="background-color: rgb(255, 255, 51);">Worker code</span></span></div>
<div>class FooWorker < BackgrounDRb::MetaWorker</div><div><br></div><div> set_worker_name :foo_worker</div>
<div> pool_size 10</div><div><br></div><div> def create</div><div> # this method is called, when worker is loaded for the first time</div><div> end</div><div><br></div><div> def run_concurrent(args)</div>
<div> <a href="http://logger.info" target="_blank">logger.info</a> "*** FOO_WORKER/RUN_CONCURRENT at " + Time.now.to_s</div><div> thread_pool.defer(:my_actual_method)</div><div> end</div>
<div>
<br></div><div> def my_actual_method(args)</div><div> <a href="http://logger.info" target="_blank">logger.info</a> "*** FOO_WORKER/MY_ACTUAL_METHOD at " + Time.now.to_s</div><div> sleep 5</div>
<div> end</div><div>end</div><div><div>====================================================</div><div><div><div><span class="Apple-style-span" style="font-weight: bold;"><span class="Apple-style-span" style="background-color: rgb(255, 255, 51);">Here's the output</span></span></div>
<div># Logfile created on Wed Dec 31 09:15:21 +0000 2008 by /<br></div><div><div>foo_worker started (pid:5087)</div><div>Schedules for worker loaded (pid:5087)</div><div>run_concurrent job_keydfvq5o4m0s (pid:5087)</div><div>
*** FOO_WORKER/RUN_CONCURRENT at Wed Dec 31 09:15:26 +0000 2008 (pid:5087)</div><div>run_concurrent job_keyy4tascam6k (pid:5087)</div><div>*** FOO_WORKER/RUN_CONCURRENT at Wed Dec 31 09:15:26 +0000 2008 (pid:5087)</div><div>
run_concurrent job_key8gw2eegeqs (pid:5087)</div><div>*** FOO_WORKER/RUN_CONCURRENT at Wed Dec 31 09:15:26 +0000 2008 (pid:5087)</div><div>run_concurrent job_keyywb1oop73t (pid:5087)</div><div>*** FOO_WORKER/RUN_CONCURRENT at Wed Dec 31 09:15:26 +0000 2008 (pid:5087)</div>
<div>run_concurrent job_key17gfkqtzjh (pid:5087)</div><div>*** FOO_WORKER/RUN_CONCURRENT at Wed Dec 31 09:15:26 +0000 2008 (pid:5087)</div><div><div>====================================================</div><div><br></div>
<div></div></div></div></div></div></div>