My understanding is that thin
is threaded by default, unless you disable that. So your request handler can be executed asynchronously using Eventmachine::Defer
.
Yes, as the comment by @user2246674 says, if your handler is executed in the reactor thread then it will block everything.
As to the alternatives, I just searched Google for ActiveRecord and Eventmachine
and the first hit was this post with some code: http://www.mikeperham.com/2010/03/30/using-activerecord-with-eventmachine/. You might find it useful to take a look at "em-synchrony": https://github.com/igrigorik/em-synchrony that has support for ActiveRecord
.
Here is also my own question on a related subject: async requests using sinatra streaming API There I use Sinatra's streaming API to implement asynchronous request processing.
I personally would use direct DB access from my Sinatra app. That is what I always do. ActiveRecord
is too heavy for me.