Estou tendo problemas diariamente com a lentidão do meu servidor. Acredito que seja um problema com o nginx ou o php-fpm desistindo em algum momento e não se recuperando normalmente. Incluirei qualquer informação que possa ajudar. Começarei com minhas configurações de nginx e php-fpm. Por favor, deixe-me saber se há mais alguma coisa que seria útil postar aqui. Eu uso cloudflare se isso puder ajudar no diagnóstico.
Eu também aceitaria sugestões sobre como descobrir por que as informações abaixo não são suficientes.
O site éaqui
Editar:
Parece que cada solicitação começa a usar a quantidade definida de recursos que o nigx ou o php podem usar, mas não os libera. Meu monitoramento e top
não mostra pico de CPU ou memória quando o servidor começa a responder lentamente. Em algum momento a lentidão atinge o tempo limite e retorna um erro 5XX.
Eu tenho um servidor hospedado no linode. Suas especificações são:
8 GB RAM
6 CPU Cores
192 GB SSD Storage
8 TB Transfer
40 Gbps Network In
1000 Mbps Network Out
nginx.conf
user www-data www-data;
worker_processes 6;
pid /run/nginx.pid;
events {
worker_connections 768;
# multi_accept on;
}
http {
##
# Basic Settings
##
# set client body size to 2M #
client_max_body_size 50M;
sendfile on;
tcp_nopush on;
tcp_nodelay on;
# added cbt, cht, st -- kt was there
keepalive_timeout 5;
types_hash_max_size 2048;
server_tokens off;
# server_names_hash_bucket_size 64;
# server_name_in_redirect off;
default_type application/octet-stream;
include /etc/nginx/mime.types;
##
# Logging Settings
##
log_format cf_custom '$remote_addr - $remote_user [$time_local] '
'"$request" $status $body_bytes_sent '
'"$http_referer" "$http_user_agent" '
'$http_cf_ray';
#access_log /var/log/nginx/access.log;
#error_log /var/log/nginx/error.log;
##
# Gzip Settings
##
gzip on;
gzip_disable "msie6";
gzip_vary on;
gzip_proxied any;
gzip_comp_level 5;
# gzip_buffers 16 8k;
gzip_http_version 1.0;
# Gzip the following types of requests/files
gzip_types application/atom+xml application/javascript application/json application/rss+xml application/vnd.ms-fontobject application/x-font-ttf application/x-web-app-manifest+json application/xhtml+xml application/xml font/opentype image/svg+xml image/x-icon text/css text/plain text/x-component;
##
# nginx-naxsi config
##
# Uncomment it if you installed nginx-naxsi
##
#include /etc/nginx/naxsi_core.rules;
##
# nginx-passenger config
##
# Uncomment it if you installed nginx-passenger
##
#passenger_root /usr;
#passenger_ruby /usr/bin/ruby;
##
# Virtual Host Configs
##
include /etc/nginx/conf.d/*.conf;
include /etc/nginx/sites-enabled/*;
# Cloudflare
set_real_ip_from 199.27.128.0/21;
set_real_ip_from 173.245.48.0/20;
set_real_ip_from 103.21.244.0/22;
set_real_ip_from 103.22.200.0/22;
set_real_ip_from 103.31.4.0/22;
set_real_ip_from 141.101.64.0/18;
set_real_ip_from 108.162.192.0/18;
set_real_ip_from 190.93.240.0/20;
set_real_ip_from 188.114.96.0/20;
set_real_ip_from 197.234.240.0/22;
set_real_ip_from 198.41.128.0/17;
set_real_ip_from 162.158.0.0/15;
set_real_ip_from 104.16.0.0/12;
set_real_ip_from 172.64.0.0/13;
set_real_ip_from 2400:cb00::/32;
set_real_ip_from 2606:4700::/32;
set_real_ip_from 2803:f800::/32;
set_real_ip_from 2405:b500::/32;
set_real_ip_from 2405:8100::/32;
real_ip_header CF-Connecting-IP;
}
php-fpm.conf
[global]
pid = /var/run/php5-fpm.pid
error_log = /var/log/php5/fpm.log
log_level = debug
emergency_restart_threshold = 10
emergency_restart_interval = 1m
process_control_timeout = 10
process.max = 128
include=/etc/php5/fpm/pool.d/*.conf
www.conf
[www]
user = www-data
group = www-data
listen = /var/run/php5-fpm.sock
listen.owner = www-data
listen.group = www-data
listen.mode = 0660
pm = ondemand
pm.max_children = 26
pm.start_servers = 8
pm.min_spare_servers = 5
pm.max_spare_servers = 11
pm.process_idle_timeout = 10s;
pm.max_requests = 50
slowlog = /var/log/php5/slow.log
request_slowlog_timeout = 10s
request_terminate_timeout = 360s
;rlimit_files = 1024
rlimit_core = unlimited
chdir = /
principal
top - 14:39:10 up 1:04, 2 users, load average: 1.47, 1.28, 1.28
Tasks: 187 total, 3 running, 183 sleeping, 1 stopped, 0 zombie
%Cpu(s): 16.0 us, 4.8 sy, 0.0 ni, 79.1 id, 0.0 wa, 0.0 hi, 0.1 si, 0.1 st
KiB Mem: 8206476 total, 7661580 used, 544896 free, 2386564 buffers
KiB Swap: 524284 total, 1328 used, 522956 free. 680268 cached Mem
PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND
1653 root 20 0 284736 41136 15176 S 6.3 0.5 0:00.19 php5
1659 root 20 0 285048 42040 15672 S 6.3 0.5 0:00.19 php5
1668 root 20 0 285048 42076 15704 S 6.3 0.5 0:00.19 php5
1676 root 20 0 285048 41956 15588 S 6.3 0.5 0:00.19 php5
1645 root 20 0 284732 41060 15108 S 6.0 0.5 0:00.18 php5
1649 root 20 0 284732 41480 15520 S 6.0 0.5 0:00.18 php5
1656 root 20 0 284736 41336 15376 S 6.0 0.5 0:00.18 php5
1664 root 20 0 284736 41320 15360 S 6.0 0.5 0:00.18 php5
1680 root 20 0 284736 41332 15368 S 6.0 0.5 0:00.18 php5
1684 root 20 0 280172 38288 14816 R 5.3 0.5 0:00.16 php5
1222 www-data 20 0 351712 80236 64044 S 4.3 1.0 0:00.64 php5-fpm
1065 www-data 20 0 351680 79912 63768 S 3.7 1.0 0:00.79 php5-fpm
1215 www-data 20 0 351548 68972 52844 S 3.7 0.8 0:00.58 php5-fpm
1484 www-data 20 0 349536 65116 49748 S 3.7 0.8 0:00.23 php5-fpm
502 www-data 20 0 351604 69484 53932 S 2.7 0.8 0:01.26 php5-fpm
1496 www-data 20 0 349532 65248 49748 S 2.7 0.8 0:00.23 php5-fpm
31105 www-data 20 0 351776 81428 65260 S 2.7 1.0 0:02.92 php5-fpm
3194 www-data 20 0 88216 7788 4440 S 2.3 0.1 0:09.70 nginx
31652 www-data 20 0 352180 82120 65644 S 2.3 1.0 0:02.73 php5-fpm
512 www-data 20 0 347204 71160 57300 S 2.0 0.9 0:01.14 php5-fpm
980 www-data 20 0 351712 80484 64300 S 2.0 1.0 0:00.82 php5-fpm
1639 root 20 0 285048 41864 15492 S 2.0 0.5 0:00.19 php5
31275 www-data 20 0 349020 78496 64812 S 2.0 1.0 0:03.20 php5-fpm
32114 www-data 20 0 351628 78468 62316 S 2.0 1.0 0:01.93 php5-fpm
588 www-data 20 0 352940 82800 66476 S 1.7 1.0 0:01.64 php5-fpm
30959 www-data 20 0 351816 83404 67180 S 1.7 1.0 0:03.43 php5-fpm
31736 www-data 20 0 349788 68604 54188 S 1.7 0.8 0:02.50 php5-fpm
3129 mysql 20 0 3441720 208516 11144 S 1.3 2.5 1:23.69 mysqld
840 www-data 20 0 349788 76684 62444 R 1.0 0.9 0:00.84 php5-fpm
3617 root 20 0 560496 12724 5328 S 0.7 0.2 0:21.73 fail2ban-server
7 root 20 0 0 0 0 S 0.3 0.0 0:04.87 rcu_sched
1462 root 20 0 0 0 0 S 0.3 0.0 0:03.17 kworker/4:1
1635 root 20 0 285048 41928 15556 S 0.3 0.5 0:00.19 php5
3299 root 20 0 279628 37576 14760 S 0.3 0.5 0:11.20 php
3301 root 20 0 279628 37616 14800 S 0.3 0.5 0:11.24 php
3304 root 20 0 279628 37652 14840 S 0.3 0.5 0:11.16 php
3305 root 20 0 279628 37528 14712 S 0.3 0.5 0:11.04 php
3307 root 20 0 279628 37620 14804 S 0.3 0.5 0:11.06 php
3309 root 20 0 279628 37696 14880 S 0.3 0.5 0:11.27 php
3313 root 20 0 278344 36640 15032 S 0.3 0.4 0:10.60 php
3314 root 20 0 278344 36560 14952 S 0.3 0.4 0:10.57 php
3319 root 20 0 278344 36632 15024 S 0.3 0.4 0:10.63 php
3333 root 20 0 278344 36672 15068 S 0.3 0.4 0:10.41 php
1 root 20 0 33652 4196 2724 S 0.0 0.1 0:03.96 init
2 root 20 0 0 0 0 S 0.0 0.0 0:00.00 kthreadd
3 root 20 0 0 0 0 S 0.0 0.0 0:00.17 ksoftirqd/0
4 root 20 0 0 0 0 S 0.0 0.0 0:00.00 kworker/0:0
5 root 0 -20 0 0 0 S 0.0 0.0 0:00.00 kworker/0:0H
6 root 20 0 0 0 0 S 0.0 0.0 0:01.13 kworker/u12:0
8 root 20 0 0 0 0 S 0.0 0.0 0:00.00 rcu_bh
9 root rt 0 0 0 0 S 0.0 0.0 0:00.05 migration/0
10 root rt 0 0 0 0 S 0.0 0.0 0:00.05 migration/1
11 root 20 0 0 0 0 S 0.0 0.0 0:00.07 ksoftirqd/1
12 root 20 0 0 0 0 S 0.0 0.0 0:00.00 kworker/1:0
13 root 0 -20 0
iostat
Linux 4.1.5-x86_64-linode61 (localhost) 09/29/2015 _x86_64_ (6 CPU)
avg-cpu: %user %nice %system %iowait %steal %idle
16.05 0.00 5.52 0.12 0.12 78.19
Device: tps kB_read/s kB_wrtn/s kB_read kB_wrtn
xvda 74.76 321.33 285.55 3117199 2770120
xvdb 0.02 0.06 0.14 572 1336
iostat -x 1 – quando lento
Device: rrqm/s wrqm/s r/s w/s rkB/s wkB/s avgrq-sz avgqu-sz await r_await w_await svctm %util
xvda 0.00 0.00 0.00 7.00 0.00 28.00 8.00 0.00 0.43 0.00 0.43 0.57 0.40
xvdb 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00
avg-cpu: %user %nice %system %iowait %steal %idle
25.84 0.00 8.22 0.00 0.17 65.77
Device: rrqm/s wrqm/s r/s w/s rkB/s wkB/s avgrq-sz avgqu-sz await r_await w_await svctm %util
xvda 0.00 55.00 0.00 10.00 0.00 264.00 52.80 0.00 0.40 0.00 0.40 0.30 0.30
xvdb 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00
avg-cpu: %user %nice %system %iowait %steal %idle
8.68 0.00 4.17 0.00 0.00 87.15
Device: rrqm/s wrqm/s r/s w/s rkB/s wkB/s avgrq-sz avgqu-sz await r_await w_await svctm %util
xvda 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00
xvdb 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00
avg-cpu: %user %nice %system %iowait %steal %idle
10.18 0.00 5.01 0.00 0.00 84.81
Device: rrqm/s wrqm/s r/s w/s rkB/s wkB/s avgrq-sz avgqu-sz await r_await w_await svctm %util
xvda 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00
xvdb 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00
avg-cpu: %user %nice %system %iowait %steal %idle
18.06 0.00 5.52 0.00 0.00 76.42
Device: rrqm/s wrqm/s r/s w/s rkB/s wkB/s avgrq-sz avgqu-sz await r_await w_await svctm %util
xvda 0.00 0.00 0.00 3.00 0.00 12.00 8.00 0.00 0.00 0.00 0.00 0.00 0.00
xvdb 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00
avg-cpu: %user %nice %system %iowait %steal %idle
17.47 0.00 6.82 0.00 0.17 75.54
Device: rrqm/s wrqm/s r/s w/s rkB/s wkB/s avgrq-sz avgqu-sz await r_await w_await svctm %util
xvda 0.00 0.00 0.00 7.00 0.00 28.00 8.00 0.00 0.43 0.00 0.43 0.43 0.30
xvdb 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00
avg-cpu: %user %nice %system %iowait %steal %idle
15.55 0.00 3.34 0.00 0.00 81.10
Device: rrqm/s wrqm/s r/s w/s rkB/s wkB/s avgrq-sz avgqu-sz await r_await w_await svctm %util
xvda 0.00 105.00 0.00 21.00 0.00 696.00 66.29 0.00 0.14 0.00 0.14 0.19 0.40
xvdb 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00