Answer the question
In order to leave comments, you need to log in
Nginx + Puma Rails. Why is it slow? How to check what's wrong?
Hello.
There was a question about the speed of interaction between the reverse nginx server and the puma application server.
The application is written in Ruby on Rails.
Puma renders the page in 30ms, passes it to nginx.
Nginx gives it to the browser in 300ms.
What it does is over 260ms. How to understand what is the problem? How to optimize?
Website jobsgalore.eu
Sample puma log
I, [2019-12-13T19:20:49.032799 #851] INFO -- : [fde336ca-e704-47e4-9f1a-e400509be1a7] Started GET "/jobs/6865856" for 176.59.131.200 at 2019-12-13 19:20:49 +1100
I, [2019-12-13T19:20:49.033816 #851] INFO -- : [fde336ca-e704-47e4-9f1a-e400509be1a7] Processing by JobsController#show as HTML
I, [2019-12-13T19:20:49.033863 #851] INFO -- : [fde336ca-e704-47e4-9f1a-e400509be1a7] Parameters: {"id"=>"6865856"}
I, [2019-12-13T19:20:49.040195 #851] INFO -- : [fde336ca-e704-47e4-9f1a-e400509be1a7] Rendering jobs/show.html.slim within layouts/application
I, [2019-12-13T19:20:49.057853 #851] INFO -- : [fde336ca-e704-47e4-9f1a-e400509be1a7] Rendered inc/_summary.html.slim (Duration: 0.9ms | Allocations: 306)
I, [2019-12-13T19:20:49.058839 #851] INFO -- : [fde336ca-e704-47e4-9f1a-e400509be1a7] Rendered inc/btn/_btn_send.html.slim (Duration: 0.1ms | Allocations: 46)
I, [2019-12-13T19:20:49.058927 #851] INFO -- : [fde336ca-e704-47e4-9f1a-e400509be1a7] Rendered inc/_btn.html.slim (Duration: 0.4ms | Allocations: 168)
I, [2019-12-13T19:20:49.060076 #851] INFO -- : [fde336ca-e704-47e4-9f1a-e400509be1a7] Rendered jobs/show/_show_md.html.slim (Duration: 19.1ms | Allocations: 10401)
I, [2019-12-13T19:20:49.060249 #851] INFO -- : [fde336ca-e704-47e4-9f1a-e400509be1a7] Rendered jobs/show.html.slim within layouts/application (Duration: 20.0ms | Allocations: 11779)
I, [2019-12-13T19:20:49.061178 #851] INFO -- : [fde336ca-e704-47e4-9f1a-e400509be1a7] Rendered inc/_logo.html (Duration: 0.0ms | Allocations: 9)
I, [2019-12-13T19:20:49.061292 #851] INFO -- : [fde336ca-e704-47e4-9f1a-e400509be1a7] Rendered inc/header/inc/_print.html.slim (Duration: 0.2ms | Allocations: 69)
I, [2019-12-13T19:20:49.062594 #851] INFO -- : [fde336ca-e704-47e4-9f1a-e400509be1a7] Rendered inc/header/inc/_search.html.slim (Duration: 1.1ms | Allocations: 1530)
I, [2019-12-13T19:20:49.062906 #851] INFO -- : [fde336ca-e704-47e4-9f1a-e400509be1a7] Rendered inc/header/_client_drop_menu.html.slim (Duration: 0.2ms | Allocations: 114)
I, [2019-12-13T19:20:49.062985 #851] INFO -- : [fde336ca-e704-47e4-9f1a-e400509be1a7] Rendered inc/header/_header_md.html.slim (Duration: 2.0ms | Allocations: 1970)
I, [2019-12-13T19:20:49.063403 #851] INFO -- : [fde336ca-e704-47e4-9f1a-e400509be1a7] Rendered inc/_footer.html.erb (Duration: 0.2ms | Allocations: 179)
I, [2019-12-13T19:20:49.063589 #851] INFO -- : [fde336ca-e704-47e4-9f1a-e400509be1a7] Completed 200 OK in 30ms (Views: 16.5ms | ActiveRecord: 7.6ms | Allocations: 16912)
user www-user;
worker_processes auto;
pid /run/nginx.pid;
include /etc/nginx/modules-enabled/*.conf;
events {
multi_accept on;
use epoll;
}
http {
upstream puma {
server unix:///home/ubuntu/apps/JobsGalore/shared/tmp/sockets/JobsGalore-puma.sock;
}
server {
open_file_cache max=200000 inactive=20s;
open_file_cache_valid 30s;
open_file_cache_min_uses 2;
open_file_cache_errors on;
sendfile on;
tcp_nodelay on;
tcp_nopush on;
server_name jobsgalore.eu www.jobsgalore.eu;
if ($host ~* www.) {
return 301 https://$server_name$request_uri;
}
root /home/ubuntu/apps/JobsGalore/current/public;
access_log /home/ubuntu/apps/JobsGalore/current/log/nginx.access.log;
error_log /home/ubuntu/apps/JobsGalore/current/log/nginx.error.log info;
gzip on;
gzip_disable "msie6";
gzip_min_length 10240;
gzip_proxied expired no-cache no-store private auth;
gzip_types text/plain text/css application/json application/x-javascript text/xml application/xml application/xml+rss text/javascript application/javascript;
gzip_comp_level 4;
location ^~ /assets/ {
gzip_static on;
expires max;
add_header Cache-Control public;
}
try_files $uri/index.html $uri @puma;
location @puma {
if ($http_user_agent ~* AhrefsBot|MJ12bot|Detectify|dotbot|Riddler|SemrushBot|LinkpadBot|BLEXBot|FlipboardProxy|MauiBot|HubSpot|masscan|DotBot|Python|zgrab){ return 403; }
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_set_header Host $http_host;
proxy_redirect off;
proxy_pass http://puma;
}
error_page 500 502 503 504 /500.html;
client_body_buffer_size 10K;
client_header_buffer_size 8k;
client_max_body_size 8m;
large_client_header_buffers 8 32k;
reset_timedout_connection on;
listen 443 ssl http2; # managed by Certbot
ssl_certificate /etc/letsencrypt/live/jobsgalore.eu/fullchain.pem; # managed by Certbot
ssl_certificate_key /etc/letsencrypt/live/jobsgalore.eu/privkey.pem; # managed by Certbot
include /etc/letsencrypt/options-ssl-nginx.conf; # managed by Certbot
ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem; # managed by Certbot
keepalive_timeout 70;
keepalive_requests 1000;
}
server {
server_name jobsgalore.eu www.jobsgalore.eu;
listen 80 http2;
if ($host = www.jobsgalore.eu) {
return 301 https://jobsgalore.eu$request_uri;
} # managed by Certbot
if ($host = jobsgalore.eu) {
return 301 https://$host$request_uri;
} # managed by Certbot
}
server {
server_name jobsgalore.eu www.jobsgalore.eu;
listen 443 http2;
if ($host = www.jobsgalore.eu) {
return 301 https://jobsgalore.eu$request_uri;
} # managed by Certbot
}
}
Answer the question
In order to leave comments, you need to log in
between "Puma renders the page in 30ms, passes it to nginx" and "Nginx renders it to the browser in 300ms." there is also "Puma is busy transferring the page to nginx". I would add backend request execution time logging to nginx and dance further from this information.
https://docs.nginx.com/nginx/admin-guide/monitorin...
It is necessary to measure the time of issuing the page by the Puma server and dance further from this. If it is close to 30ms from RoR, then you need to find out about the nginx configuration.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question