Nginx + PHP FPM + MYSQL servers going down when too much traffic

November 24, 2017 215 views
Nginx MySQL PHP Linux Basics Ubuntu

We currently have some servers hosting a e-commerce platform in Digital Ocean, we tried to optimize how much we could, but was not enough, site is going down when too much traffic, like 800~1000 users. We currently think its the API that is going down. The error is:

2017/11/23 14:20:51 [error] 26784#26784: *126599 connect() to unix:/var/run/php/php7.0-fpm.sock failed (11: Resource temporarily unavailable) while connecting to upstream, client: {ip...}, server: www.....com.br, request: "GET /....", upstream: "fastcgi://unix:/var/run/php/php7.0-fpm.sock:", host: "www......com.br"

We currently have:

Front-end server:

4 cores, 8gb ram - running nginx 1.10.3 and php fpm 7.0

API server:

8 cores, 16gb ram - running nginx 1.10.3 and php fpm 5.5.9

MYSQL server

MASTER + 8 SLAVES (We don't think thats the problem), We had some problem before with connection numbers tcp/ip ports (I dont know exactly), but we could't solve and created slaves for load balance. Servers are running linux ubuntu 14.04

If more information is needed, please ask. We are struggling with this.

Nginx conf:

workerprocesses auto;
worker
rlimitnofile 65536;
worker
connections 2048;
use epoll;
multiaccept on;
sendfile on;
tcp
nopush on;
tcpnodelay on;
keepalive
timeout 15;
typeshashmaxsize 2048;
server
nameshashmaxsize 4112;
access
log off;
gzip on;
gzipdisable "msie6";
gzip
vary on;
gzipproxied any;
gzip
complevel 2;
gzip
buffers 16 8k;
gziphttpversion 1.1;
gziptypes text/plain text/css application/json application/javascript text/xml application/xml application/xml+rss text/javascript;]
fastcgi
buffers 8 16k;
fastcgibuffersize 32k;
fastcgiconnecttimeout 360;
fastcgisendtimeout 360;
fastcgireadtimeout 360;
fastcgipass unix:/var/run/php/php7.0-fpm.sock;
client
bodybuffersize 128k;
clientmaxbodysize 10m;
client
headerbuffersize 1k;
largeclientheaderbuffers 4 4k;
output
buffers 1 32k;
postponeoutput 1460;
client
headertimeout 3m;
client
bodytimeout 3m;
send
timeout 3m;

PHP FPM conf:

pm = on demand;
pm.maxchildren = 200;
pm.process
idletimeout = 10s;
pm.max
requests = 500;

/etc/sysctl.conf configs:

net.ipv4.iplocalportrange = 2000 65535;
net.ipv4.tcp
rfc1337 = 1;
net.ipv4.tcpfintimeout = 15;
net.ipv4.tcpkeepalivetime = 300;
net.ipv4.tcpkeepaliveprobes = 5;
net.ipv4.tcpkeepaliveintvl = 15;
net.core.rmemdefault = 31457280;
net.core.rmem
max = 12582912;
net.core.wmemdefault = 31457280;
net.core.wmem
max = 12582912;
net.core.somaxconn = 65535;
net.core.netdevmaxbacklog = 65535;
net.core.optmemmax = 25165824;
net.ipv4.tcp
mem = 65535 131072 262144;
net.ipv4.udpmem = 65535 131072 262144;
net.ipv4.tcp
rmem = 8192 87380 16777216;
net.ipv4.udprmemmin = 16384;
net.ipv4.tcpwmem = 8192 65535 16777216;
net.ipv4.udp
wmemmin = 16384;
net.ipv4.tcp
maxtwbuckets = 1440000;
net.ipv4.tcptwrecycle = 1;
net.ipv4.tcptwreuse = 1;

Be the first one to answer this question.