# Mongrel + nginx + fork

**URL:** <https://www.ruby-forum.com/t/mongrel-nginx-fork/123733>\
**Category:** Deployment\
**Created:** [December 20, 2007, 4:10am UTC](https://www.ruby-forum.com/t/mongrel-nginx-fork/123733 "2007-12-20T04:10:53Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![bincedecrabe](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/77aa72/32.png) [@bincedecrabe](https://www.ruby-forum.com/u/bincedecrabe)\
**Post date:** [December 20, 2007, 4:10am UTC](https://www.ruby-forum.com/t/mongrel-nginx-fork/123733/1 "2007-12-20T04:10:53Z")

</div>

I’m trying to kick off simple (yet long running) background processes  
from within my rails app. I’m using Tom Anderson’s spawn plugin  
[http://rubyforge.org/projects/spawn/](http://rubyforge.org/projects/spawn/) to fork a child process and unhook  
the active record DB connections to keep rails happy. Anyway,  
everything works great when I hit a mongrel process directly  
([http://myapp:3000/controller/action](http://myapp:3000/controller/action)). The action quickly executes, the  
results are returned to my browser, and the child process takes its time  
doing the heavy lifting. I can hit that mongrel process again and  
verify that it’s free to serve up another request.

Life is good-- that is until, I bring nginx into the mix. With nginx  
proxying to the upstream :3000 mongrel, the response isn’t immediately  
returned to my browser. Instead, the rails log file shows that the  
request is finished, but my browser continues to spin, waiting for the  
response. If I stop the request, I can load an alternate action to  
verify that the lone mongrel is free to serve another request.

Has anyone had success with nginx, mongrel, and child processes? I just  
installed pen to balance the single mongrel, and it worked as expected.

My dev box is intel mac, ruby 1.8.6, mongrel 1.1.2, nginx 0.5.34 (tried  
with same results on 0.5.32)

Thanks!

---

<div class="post-metadata">

**Author:** ![bincedecrabe](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/77aa72/32.png) [@bincedecrabe](https://www.ruby-forum.com/u/bincedecrabe)\
**Post date:** [December 20, 2007, 10:35am UTC](https://www.ruby-forum.com/t/mongrel-nginx-fork/123733/2 "2007-12-20T10:35:43Z")

</div>

Hi,

You could try background\_fu[1] or Backgroundrb[2] for long running  
background processes.

[1] → [https://svn.trix.pl/public/background\_fu/README](https://svn.trix.pl/public/background_fu/README)  
[2] → [http://backgroundrb.rubyforge.org/](http://backgroundrb.rubyforge.org/)

On Dec 20, 5:10 am, Nicky Be [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
wrote:

> proxying to the upstream :3000 mongrel, the response isn’t immediately
> 
> Thanks!

–  
Aurelian

[http://www.locknet.ro](http://www.locknet.ro)

---

<div class="post-metadata">

**Author:** ![bincedecrabe](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/77aa72/32.png) [@bincedecrabe](https://www.ruby-forum.com/u/bincedecrabe)\
**Post date:** [December 20, 2007, 7:28pm UTC](https://www.ruby-forum.com/t/mongrel-nginx-fork/123733/3 "2007-12-20T19:28:56Z")

</div>

aurelian wrote:

> Hi,
> 
> You could try background\_fu[1] or Backgroundrb[2] for long running  
> background processes.

Thanks for the suggestions; I had seen BackgroundRb, but background\_fu  
looks much lighter. I was hoping to stay away from running a daemon to  
ease deployment issues. If I can’t figure out the nginx issue, I might  
have to go that route, but I was really hoping fork would get me there.
