Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How is my single-threaded Rails app handling concurrent requests?

I have a single-threaded Rails app running on thin in single-threaded mode on Heroku Cedar.

While I do a huge POST request (a file upload) that takes more than a minute, I can do other GET requests at the same time.

Heroku support assures me that their routing layer is not storing the request and then sending it all at once (which is the behavior of many proxies, such as nginx). They insist that my app is handling concurrent requests.

What's going on here?

like image 801
John Bachir Avatar asked Apr 01 '12 07:04

John Bachir


1 Answers

Thin is built on top of EventMachine, which provides event-based IO.

This means that Thin does async receiving of your POST request, while serving GET requests in the meanwhile. When POST data is uploaded, Thin then goes on to pass it to Rails (where it is processed synchronously and blocks other requests until finished).

like image 161
Sergio Tulentsev Avatar answered Sep 30 '22 17:09

Sergio Tulentsev