1

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?

Community
  • 1
  • 1
shlajin
  • 1,416
  • 10
  • 23

1 Answers1

1

The most likely reason for that blocking behaviour is that you are testing from two different tabs in your web browser, which is blocking the second call until the first call is done. You can easily see that happen with Firefox's network monitor, for instance. Try instead from the command line:

curl http://localhost:3000/freeze &
To마SE
  • 573
  • 8
  • 19