I've got extremely simple Sinatra application to test multithreading (or multiprocessing – I just want to get response back in a 3 seconds, no matter, how much else queries was processed on a server).
require 'sinatra/base'
class MyApp < Sinatra::Base
set :threaded, true
get '/freeze' do
Thread.new {
sleep 3
}.join
'Its finished'
end
run! if app_file == $0
end
From this topic I discovered, that Sinatra is actually multithreaded since 1.3 (I've got 1.4.5). Is Sinatra multi threaded?
I tried it with thin and unicorn, run through thin --threaded
and just ruby my_app.rb
. No difference, the second request takes 6 seconds to process. I tryed to switch a gem to a async_sinatra
or sinatra-synchrony
but all was pointless.
What I am doing wrong?