# Processing loop

**URL:** <https://www.ruby-forum.com/t/processing-loop/148360>\
**Category:** Ruby\
**Created:** [September 12, 2008, 2:50am UTC](https://www.ruby-forum.com/t/processing-loop/148360 "2008-09-12T02:50:32Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![doctoromms](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/258eb7/32.png) [@doctoromms](https://www.ruby-forum.com/u/doctoromms)\
**Post date:** [September 12, 2008, 2:50am UTC](https://www.ruby-forum.com/t/processing-loop/148360/1 "2008-09-12T02:50:32Z")

</div>

Hey guys,

I am trying to write an application with some various infinite loops  
that basically poll data in a queue. Essentially, it is an asynchronous  
webseerver, where requests come in, queue up the request and immediately  
send a success response to the user. I am planning on having a separate  
process polling this queue and handling the requests.

what i had in mind was something like:  
while(1) do  
queue.first.handle()  
sleep(1)  
end

I know Mongrel is single threaded so I was planning on using a  
multithreaded server like Thin or LiteSpeed.

Any thoughts?

Thanks!

-Omri

---

<div class="post-metadata">

**Author:** ![doctoromms](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/258eb7/32.png) [@doctoromms](https://www.ruby-forum.com/u/doctoromms)\
**Post date:** [September 12, 2008, 7:01pm UTC](https://www.ruby-forum.com/t/processing-loop/148360/2 "2008-09-12T19:01:23Z")

</div>

Hi Omri,

Another option (which I’ve had some success with) is using BackgrounDRb  
to manage a separate worker process which consumes items from a work  
queue. This worker process can be multithreaded. Your web app processes  
(mongrels or otherwise) would add work jobs to the queue using  
BackgrounDRb’s IPC mechanisms. The work queue could be a database table,  
or maintained in memory by the worker process.

Cheers,  
Pete
