# Uploading file behaviour in Mongrel

**URL:** <https://www.ruby-forum.com/t/uploading-file-behaviour-in-mongrel/118854>\
**Category:** Rails\
**Created:** [October 31, 2007, 6:12pm UTC](https://www.ruby-forum.com/t/uploading-file-behaviour-in-mongrel/118854 "2007-10-31T18:12:42Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![matthew](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/ed655f/32.png) [@matthew](https://www.ruby-forum.com/u/matthew)\
**Post date:** [October 31, 2007, 6:12pm UTC](https://www.ruby-forum.com/t/uploading-file-behaviour-in-mongrel/118854/1 "2007-10-31T18:12:42Z")

</div>

Hi

Please could someone clarify how Mongrel behaves when uploading  
files? I have an application with Apache which proxies to about 5  
mongrels. Files are uploaded to the system from mobile PDAs using  
GPRS, and the files are about 1 - 3 MB (so uploads take several  
minutes). Will this mean that a Mongrel will be tied up serving the  
upload for the duration of the upload? I know Rails is single  
threaded, but I thought Mongrel wasn’t. I expect (perhaps wrongly)  
that Mongrel creates a new thread that handles the upload, streams it  
to a TempFile (or something like it), then when it is ready, passes  
the request on to Rails, which deals with it. That is what the trace  
from the server looks like, as the upload actions take a few  
milliseconds to complete. Or is it that for the duration of the  
upload, that Mongrel will be blocked and won’t service requests until  
the upload is complete?

Thanks very much for anybody’s help.

---

<div class="post-metadata">

**Author:** ![matthew](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/ed655f/32.png) [@matthew](https://www.ruby-forum.com/u/matthew)\
**Post date:** [October 31, 2007, 9:42pm UTC](https://www.ruby-forum.com/t/uploading-file-behaviour-in-mongrel/118854/2 "2007-10-31T21:42:15Z")

</div>

On 31 Oct 2007, at 18:12, matt wrote:

> from the server looks like, as the upload actions take a few  
> milliseconds to complete. Or is it that for the duration of the  
> upload, that Mongrel will be blocked and won’t service requests until  
> the upload is complete?

You are correct in your assumption that mongrel will write to a  
tempfile and invoke rails when the upload has completely finished.

Best regards

Peter De Berdt

---

<div class="post-metadata">

**Author:** ![matthew](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/ed655f/32.png) [@matthew](https://www.ruby-forum.com/u/matthew)\
**Post date:** [October 31, 2007, 10:54pm UTC](https://www.ruby-forum.com/t/uploading-file-behaviour-in-mongrel/118854/3 "2007-10-31T22:54:10Z")

</div>

Hi Peter

Thanks. Does that mean that a Mongrel will spawn a new thread to deal  
with the file upload and still be able to service other requests in  
the meantime?

Cheers

---

<div class="post-metadata">

**Author:** ![matthew](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/ed655f/32.png) [@matthew](https://www.ruby-forum.com/u/matthew)\
**Post date:** [November 1, 2007, 1:57pm UTC](https://www.ruby-forum.com/t/uploading-file-behaviour-in-mongrel/118854/4 "2007-11-01T13:57:42Z")

</div>

I was at Railscon Europe and the guy from Twitter said that Mongrel  
was single thread. Their config is set to only send one job at a time  
to each mongrel using some of the newer Apache load balancing stuff.  
So, tempfile or not, it may be a bit of a wait. He recommended passing  
off long-running jobs to a daemon not sure how you’d do this for file  
upload though.

---

<div class="post-metadata">

**Author:** ![matthew](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/ed655f/32.png) [@matthew](https://www.ruby-forum.com/u/matthew)\
**Post date:** [November 1, 2007, 2:10pm UTC](https://www.ruby-forum.com/t/uploading-file-behaviour-in-mongrel/118854/5 "2007-11-01T14:10:37Z")

</div>

On 1 Nov 2007, at 12:57, ghoti wrote:

> I was at Railscon Europe and the guy from Twitter said that Mongrel  
> was single thread. Their config is set to only send one job at a time  
> to each mongrel using some of the newer Apache load balancing stuff.  
> So, tempfile or not, it may be a bit of a wait. He recommended passing  
> off long-running jobs to a daemon not sure how you’d do this for file  
> upload though.

mongrel is single threaded from the point of view of serving rails  
requests, which was all that was discussed at that session. Other than  
that it is multithreaded ([http://mongrel.rubyforge.org/faq.html](http://mongrel.rubyforge.org/faq.html)) and  
uploading a file won’t block a mongrel instance (you can even show an  
upload progress page - see  
[http://mongrel.rubyforge.org/docs/upload\_progress.html](http://mongrel.rubyforge.org/docs/upload_progress.html)  
Fred
