Is a client uploading a file a slow client from unicorn's point of view?

Laas Toom laas at
Tue Oct 9 06:31:36 UTC 2012

On 09.10.2012, at 4:58, Eric Wong <normalperson at> wrote:

> I'm not familiar with the nginx upload module, but stock nginx will
> already do full request buffering for you.  It looks like the nginx
> upload module[1] is mostly meant for standalone apps written for
> nginx, and not when nginx is used as a proxy for Rails app...

AFAIK the upload module will give you two things:

1) handle the whole body parsing up to the point of storing the file to disk in correct place. Then it strips the file from POST request and replaces with reference to the location on disk.

2) make the upload progress available, so e.g. AJAX-powered upload forms can show progressbar, which is really neat. No need for Flash-based uploaders.

I have a Rails app that accepts media uploads. All the processing happens in background, front-end handles only the actual upload and stores it to disk.
But with uploads as large as 1.4 GB, I've seen Rails response times > 200 secs. This starts to give timeouts in weird places.

Eric, correct me if I'm wrong, but doesn't Nginx-Unicorn-Rails stack write the whole file up to 3 times to disk:
1) Nginx buffers the body (in encoded state)
2) Unicorn parses the body and writes to TMP folder (as requested by Rails)
3) if Rails accepts the file, it moves it to actual storage. But as /tmp is often different device from storage, this is actually a full copy.

In such a situation the upload module would help out, because instead of simply buffering the body on disk, it actually parses the body. And it is implemented in C, which should make it faster.
Afterwards it will only handle out the file location and Rails can complete it's work a lot faster, freeing up workers.

Unicorn won't even see the file and Rails has the responsibility to delete the file if it's invalid.


More information about the mongrel-unicorn mailing list