I'm using puma and nxinx, and as far as I can tell it is only ever using a single thread even when I start it with the default of 16 threads or more. I've set up a fresh rails app, then gone through the set up described here:
http://blog.wiemann.name/rails-server
Which gives this sample nginx config:
upstream benchmarkapp.com {server unix:/tmp/benchmark_app.sock fail_timeout=0;}
server {
server_name benchmarkapp.com;
root /home/tristan/benchmark_app/public;
try_files $uri/index.html $uri @benchmarkapp.com;
location @benchmarkapp.com {
proxy_redirect off;
proxy_pass http://benchmarkapp.com;
}
}
Then created a simple controller action which simply sleeps for 3 seconds, then renders "hello":
class WelcomeController < ApplicationController
def index
sleep(2)
render :text => "hello"
end
end
Then I started puma with: puma -t 16 -b unix:///tmp/benchmark_app.sock -S /tmp/benchmark_app.state
once running, I hit it with 10 concurrent users using siege, and here is the result
% siege -c 10 -t 60s http://benchmarkapp.com
** SIEGE 2.70
** Preparing 10 concurrent users for battle.
The server is now under siege...
HTTP/1.1 200 2.04 secs: 25 bytes ==> /
HTTP/1.1 200 4.05 secs: 25 bytes ==> /
HTTP/1.1 200 6.06 secs: 25 bytes ==> /
HTTP/1.1 200 8.08 secs: 25 bytes ==> /
HTTP/1.1 200 10.09 secs: 25 bytes ==> /
Which is precisely what I would expect to see if the app were running single threaded. Take the first two requests. They arrive at roughly the same time. The first takes two seconds, so far so good. But the second, third, ... through the 10th all have to to wait an additional 2 seconds for each request before it. In fact, if I restart puma with only 1 thread I get exactly this result.
What am I doing wrong here? How can I get the server to actually use all of the threads that puma spawns? If everything works properly I expect to see:
% siege -c 10 -t 60s http://benchmarkapp.com
** SIEGE 2.70
** Preparing 10 concurrent users for battle.
The server is now under siege...
HTTP/1.1 200 2.04 secs: 25 bytes ==> /
HTTP/1.1 200 2.05 secs: 25 bytes ==> /
HTTP/1.1 200 2.03 secs: 25 bytes ==> /
HTTP/1.1 200 2.01 secs: 25 bytes ==> /
HTTP/1.1 200 2.06 secs: 25 bytes ==> /
How can I make this happen?