Mike Aizatsky
2007-Jan-15 16:16 UTC
[Backgroundrb-devel] Backgroundrb keeps spawning processes
Hi! I''ve just a created a really simple rails scheduled worker for backgroundrb to start playing with : class SessionCleanerWorker < BackgrounDRb::Worker::RailsBase def do_work(args) logger.info "SessionCleaner> started" CGI::Session::ActiveRecordStore::Session.destroy_all( [''updated_at <?'', 120.minutes.ago] ) LoginToken.destroy_expired logger.info "SessionCleaner> done" end end SessionCleanerWorker.register It indeed works, and is being executed in the same process: 20070115-19:00:00 (6172) SessionCleaner> started 20070115-19:00:00 (6172) SessionCleaner> done 20070115-19:10:00 (6172) SessionCleaner> started 20070115-19:10:00 (6172) SessionCleaner> done However backgroundrb keeps spawning ruby processes for some strange reason without mentioning their ids in the log file: 20070115-18:50:00 (6171) Schedule triggered: #<struct #<Class:0x7773b0> job=#<Proc:0x0062fd2c@/u/apps/learnbyrote/releases/20070115150803/vendor/plugins/backgroundrb/server/lib/backgroundrb/middleman.rb:355>, trigger=#<BackgrounDRb::CronTrigger:0x28a2440 @min=[0, 10, 20, 30, 40, 50], @month=1..12, @hour=0..23, @year=nil, @day=1..31, @cron_expr="0 0,10,20,30,40,50 * * * * *", @sec=[0], @wday=0..6>, earliest=Mon Jan 15 18:50:00 +0300 2007, last=Mon Jan 15 18:50:00 +0300 2007> 20070115-18:50:00 (6171) Starting worker: session_cleaner_worker ceb1eb03562acb8cb9c866320084383d (session_cleaner_worker_ceb1eb03562acb8cb9c866320084383d) () 20070115-19:00:00 (6171) Schedule triggered: #<struct #<Class:0x7773b0> job=#<Proc:0x0062fd2c@/u/apps/learnbyrote/releases/20070115150803/vendor/plugins/backgroundrb/server/lib/backgroundrb/middleman.rb:355>, trigger=#<BackgrounDRb::CronTrigger:0x28a2440 @min=[0, 10, 20, 30, 40, 50], @month=1..12, @hour=0..23, @year=nil, @day=1..31, @cron_expr="0 0,10,20,30,40,50 * * * * *", @sec=[0], @wday=0..6>, earliest=Mon Jan 15 19:00:00 +0300 2007, last=Mon Jan 15 19:00:00 +0300 2007> 20070115-19:00:00 (6171) Starting worker: session_cleaner_worker bf18c891526f3d7d979ddb40642c0558 (session_cleaner_worker_bf18c891526f3d7d979ddb40642c0558) () ^[OC20070115-19:10:00 (6171) Schedule triggered: #<struct #<Class:0x7773b0> job=#<Proc:0x0062fd2c@/u/apps/learnbyrote/releases/20070115150803/vendor/plugins/backgroundrb/server/lib/backgroundrb/middleman.rb:355>, trigger=#<BackgrounDRb::CronTrigger:0x28a2440 @min=[0, 10, 20, 30, 40, 50], @month=1..12, @hour=0..23, @year=nil, @day=1..31, @cron_expr="0 0,10,20,30,40,50 * * * * *", @sec=[0], @wday=0..6>, earliest=Mon Jan 15 19:10:00 +0300 2007, last=Mon Jan 15 19:10:00 +0300 2007> 20070115-19:10:00 (6171) Starting worker: session_cleaner_worker ba173e9ecb22443bce084fac06545413 (session_cleaner_worker_ba173e9ecb22443bce084fac06545413) () and there''re dozens of child ruby processes spawned from 6171 according to my activity monitor. Any idea how can this be traced down and/or fixed? -- Regards, Mike
Mason Hale
2007-Jan-15 17:01 UTC
[Backgroundrb-devel] Backgroundrb keeps spawning processes
I''ve seen the same behavior before too. I found one needs to add a " self.delete" at the end of the do_work method, for the process to terminate after it''s done doing its work. Mason On 1/15/07, Mike Aizatsky <mike.aizatsky at gmail.com> wrote:> > Hi! > > I''ve just a created a really simple rails scheduled worker for > backgroundrb to start playing with : > > class SessionCleanerWorker < BackgrounDRb::Worker::RailsBase > > def do_work(args) > logger.info "SessionCleaner> started" > > CGI::Session::ActiveRecordStore::Session.destroy_all( [''updated_at > <?'', 120.minutes.ago] ) > LoginToken.destroy_expired > > logger.info "SessionCleaner> done" > end > > end > SessionCleanerWorker.register > > > It indeed works, and is being executed in the same process: > > 20070115-19:00:00 (6172) SessionCleaner> started > 20070115-19:00:00 (6172) SessionCleaner> done > 20070115-19:10:00 (6172) SessionCleaner> started > 20070115-19:10:00 (6172) SessionCleaner> done > > However backgroundrb keeps spawning ruby processes for some strange > reason without mentioning their ids in the log file: > > 20070115-18:50:00 (6171) Schedule triggered: #<struct > #<Class:0x7773b0> > > job=#<Proc:0x0062fd2c@/u/apps/learnbyrote/releases/20070115150803/vendor/plugins/backgroundrb/server/lib/backgroundrb/middleman.rb:355>, > trigger=#<BackgrounDRb::CronTrigger:0x28a2440 @min=[0, 10, 20, 30, 40, > 50], @month=1..12, @hour=0..23, @year=nil, @day=1..31, @cron_expr="0 > 0,10,20,30,40,50 * * * * *", @sec=[0], @wday=0..6>, earliest=Mon Jan > 15 18:50:00 +0300 2007, last=Mon Jan 15 18:50:00 +0300 2007> > 20070115-18:50:00 (6171) Starting worker: session_cleaner_worker > ceb1eb03562acb8cb9c866320084383d > (session_cleaner_worker_ceb1eb03562acb8cb9c866320084383d) () > 20070115-19:00:00 (6171) Schedule triggered: #<struct > #<Class:0x7773b0> > > job=#<Proc:0x0062fd2c@/u/apps/learnbyrote/releases/20070115150803/vendor/plugins/backgroundrb/server/lib/backgroundrb/middleman.rb:355>, > trigger=#<BackgrounDRb::CronTrigger:0x28a2440 @min=[0, 10, 20, 30, 40, > 50], @month=1..12, @hour=0..23, @year=nil, @day=1..31, @cron_expr="0 > 0,10,20,30,40,50 * * * * *", @sec=[0], @wday=0..6>, earliest=Mon Jan > 15 19:00:00 +0300 2007, last=Mon Jan 15 19:00:00 +0300 2007> > 20070115-19:00:00 (6171) Starting worker: session_cleaner_worker > bf18c891526f3d7d979ddb40642c0558 > (session_cleaner_worker_bf18c891526f3d7d979ddb40642c0558) () > ^[OC20070115-19:10:00 (6171) Schedule triggered: #<struct > #<Class:0x7773b0> > > job=#<Proc:0x0062fd2c@/u/apps/learnbyrote/releases/20070115150803/vendor/plugins/backgroundrb/server/lib/backgroundrb/middleman.rb:355>, > trigger=#<BackgrounDRb::CronTrigger:0x28a2440 @min=[0, 10, 20, 30, 40, > 50], @month=1..12, @hour=0..23, @year=nil, @day=1..31, @cron_expr="0 > 0,10,20,30,40,50 * * * * *", @sec=[0], @wday=0..6>, earliest=Mon Jan > 15 19:10:00 +0300 2007, last=Mon Jan 15 19:10:00 +0300 2007> > 20070115-19:10:00 (6171) Starting worker: session_cleaner_worker > ba173e9ecb22443bce084fac06545413 > (session_cleaner_worker_ba173e9ecb22443bce084fac06545413) () > > > and there''re dozens of child ruby processes spawned from 6171 > according to my activity monitor. Any idea how can this be traced down > and/or fixed? > > -- > Regards, > Mike > _______________________________________________ > 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/20070115/528f3fcf/attachment.html
Mason''s observation is correct here. A worker spawns and stays around until told to terminate, so you will have to explicitly tell the worker to exit. An alternative strategy is, when you use the scheduler for example, is to let the worker live and repeatedly have the scheduler call a method on the same worker. You can do this by specifying the job_key - it will then use an existing worker or spawn a new worker. /skaar * Mason Hale (masonhale at gmail.com) [070115 10:57]:> I''ve seen the same behavior before too. I found one needs to add a > "self.delete" at the end of the do_work method, for the process to > terminate after it''s done doing its work. > > Mason > > On 1/15/07, Mike Aizatsky <[1]mike.aizatsky at gmail.com> wrote: > > Hi! > > I''ve just a created a really simple rails scheduled worker for > backgroundrb to start playing with : > > class SessionCleanerWorker < BackgrounDRb::Worker::RailsBase > > def do_work(args) > [2]logger.info "SessionCleaner> started" > > CGI::Session::ActiveRecordStore::Session.destroy_all( [''updated_at > <?'', 120.minutes.ago] ) > LoginToken.destroy_expired > > [3]logger.info "SessionCleaner> done" > end > > end > SessionCleanerWorker.register > > It indeed works, and is being executed in the same process: > > 20070115-19:00:00 (6172) SessionCleaner> started > 20070115-19:00:00 (6172) SessionCleaner> done > 20070115-19:10:00 (6172) SessionCleaner> started > 20070115-19:10:00 (6172) SessionCleaner> done > > However backgroundrb keeps spawning ruby processes for some strange > reason without mentioning their ids in the log file: > > 20070115-18:50:00 (6171) Schedule triggered: #<struct > #<Class:0x7773b0> > job=#<Proc:0x0062fd2c@/u/apps/learnbyrote/releases/20070115150803/vendor/plugins/backgroundrb/server/lib/backgroundrb/middleman.rb:355>, > trigger=#<BackgrounDRb::CronTrigger:0x28a2440 @min=[0, 10, 20, 30, 40, > 50], @month=1..12, @hour=0..23, @year=nil, @day=1..31, @cron_expr="0 > 0,10,20,30,40,50 * * * * *", @sec=[0], @wday=0..6>, earliest=Mon Jan > 15 18:50:00 +0300 2007, last=Mon Jan 15 18:50:00 +0300 2007> > 20070115-18:50:00 (6171) Starting worker: session_cleaner_worker > ceb1eb03562acb8cb9c866320084383d > (session_cleaner_worker_ceb1eb03562acb8cb9c866320084383d) () > 20070115-19:00:00 (6171) Schedule triggered: #<struct > #<Class:0x7773b0> > job=#<Proc:0x0062fd2c@/u/apps/learnbyrote/releases/20070115150803/vendor/plugins/backgroundrb/server/lib/backgroundrb/middleman.rb:355>, > trigger=#<BackgrounDRb::CronTrigger:0x28a2440 @min=[0, 10, 20, 30, 40, > 50], @month=1..12, @hour=0..23, @year=nil, @day=1..31, @cron_expr="0 > 0,10,20,30,40,50 * * * * *", @sec=[0], @wday=0..6>, earliest=Mon Jan > 15 19:00:00 +0300 2007, last=Mon Jan 15 19:00:00 +0300 2007> > 20070115-19:00:00 (6171) Starting worker: session_cleaner_worker > bf18c891526f3d7d979ddb40642c0558 > (session_cleaner_worker_bf18c891526f3d7d979ddb40642c0558) () > ^[OC20070115-19:10:00 (6171) Schedule triggered: #<struct > #<Class:0x7773b0> > job=#<Proc:0x0062fd2c@/u/apps/learnbyrote/releases/20070115150803/vendor/plugins/backgroundrb/server/lib/backgroundrb/middleman.rb:355>, > trigger=#<BackgrounDRb::CronTrigger:0x28a2440 @min=[0, 10, 20, 30, 40, > 50], @month=1..12, @hour=0..23, @year=nil, @day=1..31, @cron_expr="0 > 0,10,20,30,40,50 * * * * *", @sec=[0], @wday=0..6>, earliest=Mon Jan > 15 19:10:00 +0300 2007, last=Mon Jan 15 19:10:00 +0300 2007> > 20070115-19:10:00 (6171) Starting worker: session_cleaner_worker > ba173e9ecb22443bce084fac06545413 > (session_cleaner_worker_ba173e9ecb22443bce084fac06545413) () > > and there''re dozens of child ruby processes spawned from 6171 > according to my activity monitor. Any idea how can this be traced down > and/or fixed? > > -- > Regards, > Mike > _______________________________________________ > Backgroundrb-devel mailing list > [4]Backgroundrb-devel at rubyforge.org > [5]http://rubyforge.org/mailman/listinfo/backgroundrb-devel > > References > > Visible links > 1. mailto:mike.aizatsky at gmail.com > 2. http://logger.info/ > 3. http://logger.info/ > 4. mailto:Backgroundrb-devel at rubyforge.org > 5. http://rubyforge.org/mailman/listinfo/backgroundrb-devel> _______________________________________________ > Backgroundrb-devel mailing list > Backgroundrb-devel at rubyforge.org > http://rubyforge.org/mailman/listinfo/backgroundrb-devel-- ---------------------------------------------------------------------- |\|\ where in the | s_u_b_s_t_r_u_c_t_i_o_n | | >=========== W.A.S.T.E. | genarratologies |/|/ (_) is the wisdom | skaar at waste.org ----------------------------------------------------------------------