# Backgroundrb workers won't die!

**URL:** <https://www.ruby-forum.com/t/backgroundrb-workers-wont-die/106863>\
**Category:** Rails\
**Created:** [June 14, 2007, 7:36pm UTC](https://www.ruby-forum.com/t/backgroundrb-workers-wont-die/106863 "2007-06-14T19:36:15Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![stewbawka](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/a9adbd/32.png) [@stewbawka](https://www.ruby-forum.com/u/stewbawka)\
**Post date:** [June 14, 2007, 7:36pm UTC](https://www.ruby-forum.com/t/backgroundrb-workers-wont-die/106863/1 "2007-06-14T19:36:15Z")

</div>

Hi,

I’m using backgroundrb workers to do a lot of work that is being  
unloaded to a different system… it works, but over a period of time  
with much usage the server my rails app is on gets overloaded with  
backgroundrb workers that didn’t get killed. this eventually causes  
backgroundrb to stop working and my server takes a massive performance  
hit with all the memory getting eaten up… i’ve heard about a trick  
where instead of doing doing this:

```
      key = MiddleMan.new_worker(:class => :myapp_worker)
      worker = MiddleMan.worker(key)
      worker.do_work
      worker.delete

```

where i make a new worker in my controller each time i need it to do  
something… that instead i can have a single worker created and just  
use that one worker throughout my rails app…

so how do i do that?

Thanks,

Stuart

---

<div class="post-metadata">

**Author:** ![stewbawka](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/a9adbd/32.png) [@stewbawka](https://www.ruby-forum.com/u/stewbawka)\
**Post date:** [June 14, 2007, 9:35pm UTC](https://www.ruby-forum.com/t/backgroundrb-workers-wont-die/106863/2 "2007-06-14T21:35:43Z")

</div>

Hi Stuart,

stewbawka wrote:

> with much usage the server my rails app is on gets overloaded with  
> backgroundrb workers that didn’t get killed.

Are you sure the workers aren’t getting killed? I mean, do you see the  
worker process pids? I ask because the code you posted didn’t  
disconnect  
from the database and memory leaks due to not closing db connections is  
a  
known problem when using BackgroundRb.

If you want to test it out, use these in your worker to kill it off.

ActiveRecord::Base.connection.disconnect!  
::BackgrounDRb::MiddleMan.instance.delete\_worker @\_job\_key

hth,  
Bill

---

<div class="post-metadata">

**Author:** ![stewbawka](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/a9adbd/32.png) [@stewbawka](https://www.ruby-forum.com/u/stewbawka)\
**Post date:** [February 26, 2008, 11:49am UTC](https://www.ruby-forum.com/t/backgroundrb-workers-wont-die/106863/3 "2008-02-26T11:49:14Z")

</div>

Starting only one instance of worker for the same work is a good idea,  
you just pass different args, but it has some limitations eg. you cannot  
run two tasks simultaneously and worker should be stateless.
