Skip to content

Instantly share code, notes, and snippets.

@pzol
Created June 5, 2012 07:23
Show Gist options
  • Save pzol/2873316 to your computer and use it in GitHub Desktop.
Save pzol/2873316 to your computer and use it in GitHub Desktop.
RVM + Puma + Ubuntu

Running Puma on Nginx

I use the latest Puma v1.4.0 from rubygems.

Make sure you have nginx installed with these options:

>/opt/nginx/sbin/nginx -V
nginx version: nginx/1.0.15
built by gcc 4.6.1 (Ubuntu/Linaro 4.6.1-9ubuntu3) 
TLS SNI support enabled
configure arguments: --prefix=/opt/nginx --with-http_ssl_module --with-http_gzip_static_module --with-cc-opt=-Wno-error --add-module=/usr/local/rvm/gems/ruby-1.9.3-p0/gems/passenger-3.0.12/ext/nginx --with-http_ssl_module --with-pcre=/tmp/pcre/pcre-8.30

We installed nginx using passenger as you can see above, as we run currently most apps with it, but that is of course not required for puma to run.

# created by pzol for testing independent worker pools, do not delete, please
upstream puma {
server unix://tmp/puma.sock fail_timeout=0;
}
server {
listen 9099;
server_name localhost;
root /var/www/root;
error_log /var/log/nginx/puma_error.log;
access_log /var/log/nginx/puma_access.log;
location /bmsweb {
rewrite ^/bmsweb/(/?)(.*) /$2 break;
proxy_pass http://puma;
proxy_set_header Host $host:$server_port;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
location /static/ {
alias /usr/local/nginx/static/;
}
rack_env acceptance;
}
> ab -c 20 -n 1000 '***secret***'
Server Software: nginx/1.0.15
Server Hostname: hotx.resfinity.com
Server Port: 8088
Document Path: ***secret***
Document Length: 14656 bytes
Concurrency Level: 20
Time taken for tests: 20.504 seconds
Complete requests: 1000
Failed requests: 0
Write errors: 0
Total transferred: 15536000 bytes
HTML transferred: 14656000 bytes
Requests per second: 48.77 [#/sec] (mean)
Time per request: 410.086 [ms] (mean)
Time per request: 20.504 [ms] (mean, across all concurrent requests)
Transfer rate: 739.94 [Kbytes/sec] received
Connection Times (ms)
min mean[+/-sd] median max
Connect: 1 4 2.3 3 20
Processing: 113 402 148.1 390 1179
Waiting: 110 398 148.1 386 1177
Total: 117 406 148.0 394 1182
Percentage of the requests served within a certain time (ms)
50% 394
66% 428
75% 480
80% 519
90% 581
95% 701
98% 798
99% 897
100% 1182 (longest request)
# default 8-16 threads
# notice the number of failed requests
> ab -c 20 -n 1000 '***secret***'
Server Software: nginx/1.0.15
Server Hostname: hotx.resfinity.com
Server Port: 9099
Document Path: ***secret***
Document Length: 173 bytes
Concurrency Level: 20
Time taken for tests: 64.359 seconds
Complete requests: 1000
Failed requests: 980
(Connect: 0, Receive: 0, Length: 980, Exceptions: 0)
Write errors: 0
Non-2xx responses: 20
Total transferred: 15148480 bytes
HTML transferred: 14366340 bytes
Requests per second: 15.54 [#/sec] (mean)
Time per request: 1287.179 [ms] (mean)
Time per request: 64.359 [ms] (mean, across all concurrent requests)
Transfer rate: 229.86 [Kbytes/sec] received
Connection Times (ms)
min mean[+/-sd] median max
Connect: 1 3 3.0 2 24
Processing: 3 1273 3490.3 1053 64263
Waiting: 3 1270 3490.4 1048 64261
Total: 6 1276 3490.3 1055 64267
Percentage of the requests served within a certain time (ms)
50% 1055
66% 1240
75% 1390
80% 1470
90% 1707
95% 2039
98% 2531
99% 2801
100% 64267 (longest request)
description "Puma webservice for bmsweb"
author "Piotr Zolnierek <pz@anixe.pl>"
respawn
respawn limit 15 5
env PADRINO_ENV=acceptance
env APP_PATH=/opt/bmsweb/current
env LOG=/var/log/nginx/puma_bmsweb.log
env BASE_URI=/bmsweb
console output
chdir /opt/bmsweb/current
script
exec su root -c bash -l -c "cd $APP_PATH && PADRINO_ENV=$PADRINO_ENV SCRIPT_NAME=$BASE_URI RACK_BASE_URI=$BASE_URI bundle exec puma -b 'unix:///tmp/puma.sock' -S $APP_PATH/tmp/puma >> $LOG"
end script
@corbanb
Copy link

corbanb commented Aug 6, 2013

@pzol what was your final opinion of puma here? Seems much slower than passenger based on the benchmarks you have.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment