I have simple Sinatra based application which freezes each request for 30 seconds:
get '/test' do
puts "#{@@counter}, #{Thread.current.object_id}"
1.upto(30) {|i| sleep 1;puts "#{Thread.current.object_id}, #{i}"}
[200, "#{Thread.current.object_id}, #{@@counter += 1}"]
end
I set up puma (2.5.1) web server on rubinius 2.0.0-rc1 with following puma config:
pidfile "#{app_path}/pid_files/puma.pid"
state_path "#{app_path}/pid_files/puma.state"
environment 'production'
threads 3, 3
bind "tcp://x.x.x.x:9292"
daemonize true
I was expecting that this config will be able to process 3 requests concurrently while 4th and subsequent request will be waiting for unused thread. But it appeared that requests are run consequentially. Processing of the second request is started only after first request is finished. Why?
How are you testing this? In my testing firing up multiple browser windows all pointed at the same url results in the requests being handled in sequence, but this seems to be because the browser is only sending one request at a time (I’m using Chrome, I didn’t check any others).
Having multiple browser windows opening different urls on the server results in the requests being handled concurrently as expected (you can use the Sinatra
splat
param to test this easily, with a route likeget '/*/ do ...
).Using
curl
to send multiple requests at once, even all to the same url, also works as expected.