Tuong.Le at Emulex.Com
2009-Feb-26 22:55 UTC
[Backgroundrb-devel] When does a worker terminate
Hi, In Rails, it seems I can create a new worker with: worker_abc = Middleman.worker(:foo_worker) And later on uses it like: worker_abc.async_some_task(:arg => data) My question is when does this "worker_abc" go away and its resources freed up? How does Ruby/Rails/backgroundrb know that I am done using "worker_abc"? Thanks. Tuong -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://rubyforge.org/pipermail/backgroundrb-devel/attachments/20090226/7bf620c4/attachment-0001.html>
On Fri, Feb 27, 2009 at 4:25 AM, <Tuong.Le at emulex.com> wrote:> Hi, > > > > In Rails, it seems I can create a new worker with: > > ????? worker_abc = Middleman.worker(:foo_worker) > >You don''t create a new worker like that. It just gives you a handle for already running worker.You use MiddleMan.new_worker for creating new workers. More details: http://backgroundrb.rubyforge.org/rails/#new_worker> > And later on uses it like: > > ????? worker_abc.async_some_task(:arg => data) > > > > My question is when does this "worker_abc" go away and its resources freed > up?? How does Ruby/Rails/backgroundrb know that I am done using > "worker_abc"? >It doesn''t. You need to explicitly close/exit your workers.
Hemant - I thought that script/background start starts all workers and script/background stop stops all workers. How does one explicitly close/exit a particular worker from within Rails? On Thu, Feb 26, 2009 at 10:19 PM, hemant <gethemant at gmail.com> wrote:> On Fri, Feb 27, 2009 at 4:25 AM, <Tuong.Le at emulex.com> wrote: > > Hi, > > > > > > > > In Rails, it seems I can create a new worker with: > > > > worker_abc = Middleman.worker(:foo_worker) > > > > > > You don''t create a new worker like that. It just gives you a handle > for already running worker.You use MiddleMan.new_worker for creating > new workers. More details: > > http://backgroundrb.rubyforge.org/rails/#new_worker > > > > > > And later on uses it like: > > > > worker_abc.async_some_task(:arg => data) > > > > > > > > My question is when does this "worker_abc" go away and its resources > freed > > up? How does Ruby/Rails/backgroundrb know that I am done using > > "worker_abc"? > > > > It doesn''t. You need to explicitly close/exit your workers. > _______________________________________________ > Backgroundrb-devel mailing list > Backgroundrb-devel at rubyforge.org > http://rubyforge.org/mailman/listinfo/backgroundrb-devel >-------------- next part -------------- An HTML attachment was scrubbed... URL: <http://rubyforge.org/pipermail/backgroundrb-devel/attachments/20090226/5dedf73d/attachment.html>
script/background actually starts/stop the backgroundrb process. If your worker is set to autoload it will load up on start up. You can create workers using MiddleMan.new_worker( :worker => :foobar_worker ) or MiddleMan.new_worker( :worker => :foobar_worker, :worker_key=> ''some_key'' ) and use the delete method on the worker if you want to remove them. MiddleMan.all_worker_info will give you a list of current workers. Samer Masry http://www.dryblis.com On Feb 26, 2009, at 10:48 PM, Raghu Srinivasan wrote:> Hemant - I thought that script/background start starts all workers > and script/background stop stops all workers. > > How does one explicitly close/exit a particular worker from within > Rails? > > On Thu, Feb 26, 2009 at 10:19 PM, hemant <gethemant at gmail.com> wrote: > On Fri, Feb 27, 2009 at 4:25 AM, <Tuong.Le at emulex.com> wrote: > > Hi, > > > > > > > > In Rails, it seems I can create a new worker with: > > > > worker_abc = Middleman.worker(:foo_worker) > > > > > > You don''t create a new worker like that. It just gives you a handle > for already running worker.You use MiddleMan.new_worker for creating > new workers. More details: > > http://backgroundrb.rubyforge.org/rails/#new_worker > > > > > > And later on uses it like: > > > > worker_abc.async_some_task(:arg => data) > > > > > > > > My question is when does this "worker_abc" go away and its > resources freed > > up? How does Ruby/Rails/backgroundrb know that I am done using > > "worker_abc"? > > > > It doesn''t. You need to explicitly close/exit your workers. > _______________________________________________ > Backgroundrb-devel mailing list > Backgroundrb-devel at rubyforge.org > http://rubyforge.org/mailman/listinfo/backgroundrb-devel > > _______________________________________________ > Backgroundrb-devel mailing list > Backgroundrb-devel at rubyforge.org > http://rubyforge.org/mailman/listinfo/backgroundrb-devel-------------- next part -------------- An HTML attachment was scrubbed... URL: <http://rubyforge.org/pipermail/backgroundrb-devel/attachments/20090226/279c693e/attachment.html>
On Fri, Feb 27, 2009 at 12:18 PM, Raghu Srinivasan <raghu.srinivasan at gmail.com> wrote:> Hemant ?- I thought that script/background start starts all workers > and?script/background stop stops all workers. > How does one explicitly close/exit a ?particular worker from within Rails? >You can call #delete on worker. For example: MiddleMan.worker("worker_name",<optional_worker_key>).delete Or you can call #exit from within the worker.
Tuong.Le at Emulex.Com
2009-Feb-27 17:37 UTC
[Backgroundrb-devel] When does a worker terminate
I think #exit is what I was looking for but all your feedback got me questioning whether I am using backgroundrb the right way, or the most optimized way. Please advise. I was thinking of having my Rails app creating a new worker (Middleman.NEW_worker ...) EVERYTIME a time-consuming task is requested. As a result, I could have thousands of workers running at the same time. In my case, my Rails don''t need to monitor the worker status, so I can just use #exit when a worker is done with its task. Questions: 1. Should I create a new worker everytime like that? Or just having 1 worker, and call async_some_method() when I need to do some long running task? Is this where thread_pool come into place? 2. If I should create a new worker everytime, is there any reason why I shouldn''t put the time-consuming task inside the worker''s create() method? 3. At the Linux prompt, is there a way I can monitor how many workers are currently active? Thank you everyone for your help. Tuong -----Original Message----- From: hemant [mailto:gethemant at gmail.com] Sent: Friday, February 27, 2009 12:18 AM To: Raghu Srinivasan Cc: Le, Tuong; backgroundrb-devel at rubyforge.org Subject: Re: [Backgroundrb-devel] When does a worker terminate On Fri, Feb 27, 2009 at 12:18 PM, Raghu Srinivasan <raghu.srinivasan at gmail.com> wrote:> Hemant ?- I thought that script/background start starts all workers > and?script/background stop stops all workers. > How does one explicitly close/exit a ?particular worker from within Rails? >You can call #delete on worker. For example: MiddleMan.worker("worker_name",<optional_worker_key>).delete Or you can call #exit from within the worker.
On Fri, Feb 27, 2009 at 11:07 PM, <Tuong.Le at emulex.com> wrote:> I think #exit is what I was looking for but all your feedback got me questioning whether I am using backgroundrb the right way, or the most optimized way. ?Please advise. > > I was thinking of having my Rails app creating a new worker (Middleman.NEW_worker ...) EVERYTIME a time-consuming task is requested. ?As a result, I could have thousands of workers running at the same time. ?In my case, my Rails don''t need to monitor the worker status, so I can just use #exit when a worker is done with its task. > > Questions: > > 1. Should I create a new worker everytime like that? ?Or just having 1 worker, and call async_some_method() when I need to do some long running task? ?Is this where thread_pool come into place?It really depends on nature of work you are doing within worker. If task is IO bound and can run concurrently within thread pool without stepping on each other''s toe you can use that. However if your task is CPU bound, ruby threads will be of no use and tasks will wait in queue for execution within thread pool.> 2. If I should create a new worker everytime, is there any reason why I shouldn''t put the time-consuming task inside the worker''s create() method?By all means, yes you can!> > 3. At the Linux prompt, is there a way I can monitor how many workers are currently active? >Not at Linux prompt, but at ./script/console you can use MiddleMan.all_worker_info which will give you a list of all currently active workers.> -----Original Message----- > From: hemant [mailto:gethemant at gmail.com] > Sent: Friday, February 27, 2009 12:18 AM > To: Raghu Srinivasan > Cc: Le, Tuong; backgroundrb-devel at rubyforge.org > Subject: Re: [Backgroundrb-devel] When does a worker terminate > > On Fri, Feb 27, 2009 at 12:18 PM, Raghu Srinivasan > <raghu.srinivasan at gmail.com> wrote: >> Hemant ?- I thought that script/background start starts all workers >> and?script/background stop stops all workers. >> How does one explicitly close/exit a ?particular worker from within Rails? >> > > You can call #delete on worker. For example: > > MiddleMan.worker("worker_name",<optional_worker_key>).delete > > Or you can call #exit from within the worker. >-- Let them talk of their oriental summer climes of everlasting conservatories; give me the privilege of making my own summer with my own coals. http://gnufied.org