simon.wilkinson at 434wireless.com
2007-Apr-13 15:49 UTC
[Backgroundrb-devel] deleting a worker
Hi, I have workers being created from within my main rails app when it receives XML documents. These workers then parse the XML and store the data that it contains. I would like the worker to delete itself at the end of its do_work method, so that the main rails app does not need to keep track of all the generated workers. I currently have the following lines at the end of the do_work method: ActiveRecord::Base.connection.disconnect! self.delete When I track usage, I see that the number of tasks that are running is equal to the number of workers, and that they disappear when the worker finishes it''s parsing. However, I also noticed that the amount of memory used goes up every time a worker is created. At first it goes up by a lot, and then after the task completes the memory drops back down again, but remains higher than it was before the worker was created. This value doesn''t seem to reduce at all over longer periods of inactivity. Is this a result of how I am deleting the worker, or are there known memory issues with using BackgrounDRb, or is there another step that I am missing to accomplish this? Any help would be appreciated. Thanks, Simon
On 4/13/07, simon.wilkinson at 434wireless.com <simon.wilkinson at 434wireless.com> wrote:> Hi, > > I have workers being created from within my main rails app when it receives XML documents. These workers then parse the XML and store the data that it contains. I would like the worker to delete itself at the end of its do_work method, so that the main rails app does not need to keep track of all the generated workers. > > I currently have the following lines at the end of the do_work method: > > ActiveRecord::Base.connection.disconnect! > self.delete > > When I track usage, I see that the number of tasks that are running is equal to the number of workers, and that they disappear when the worker finishes it''s parsing. However, I also noticed that the amount of memory used goes up every time a worker is created. At first it goes up by a lot, and then after the task completes the memory drops back down again, but remains higher than it was before the worker was created. This value doesn''t seem to reduce at all over longer periods of inactivity. > > Is this a result of how I am deleting the worker, or are there known memory issues with using BackgrounDRb, or is there another step that I am missing to accomplish this? Any help would be appreciated. >If you are using 0.2.xx version then: You can use self.delete ( search the list, this question has been asked many times) Another easy solution is, to simply put "exit 0", which works because all the workers are separate processes anyway.