Mysql + Bad Gateway Nginx php connections peak

Asked

Viewed 98 times

1

I have at AWS:

RDS M5.xlarge
Mysql 5.6

EC2 t2.small
NGINX + PHP 7.1

Intermittently, my Mysql is getting a peak of connections, 20 to be exact. And every time that happens, "Bad Gateway" appears on NGINX.

  1. According to the type of RDS, 20 connections would not be little for it to become inaccessible?

  2. How can I further investigate the reason for this peak of connections?

  • Be more specific in the question because with NGINX error 502 Bad Gateway are 7 variations:502 Bad Gateway, HTTP Error 502 - Bad Gateway, 502 Service Temporarily Overloaded, Error 502, 502 Proxy Error, HTTP 502, 502 Bad Gateway NGINX, Also the contents of the file /var/log/nginx/error.log.

  • @Augustovasques 502 Bad Gateway, [error] 18088#0: *7213182 upstream timed out (110: Connection timed out) while Reading Response header from upstream

  • has this other log minutes before: 18088#0: *7207485 connect() to Unix:/var/run/php-fpm/www.Sock failed (11: Resource temporarily unavailable) while Connecting to upstream,

  • This is because the upstream takes too long to fulfill the request. It may be that the feature in question takes a lot of processing time to be serviced in general longer than the server time out which triggers the 502 error. What you can do is increase the time out in the settings, for example proxy_read_timeout 900; makes the server wait 15 minutes before deciding that a resource is unavailable.

  • 1

    It is noteworthy that just increasing the timeout is just a workaround, the right would be for you to install some Profiling tool and find out what is causing the timeout and work on improving the performance of this point instead of just increasing the timeout.

  • @Does this log help at all? [05-Jul-2019 15:25:18] WARNING: [pool www] server reached pm.max_children Setting (8), consider Raising it. pm = Dynamic pm.max_children = 8 pm.start_servers = 3 pm.min_spare_servers = 3 pm.max_spare_servers = 6 pm.max_requests = 200 pm.status_path = /status ;ping.path = /ping ;ping.Response = pong pm.process_idle_timeout = 10s; request_terminate_timeout = 200s request_slowlog_timeout = 60s

  • It helps a lot. It says that PHP-FPM allows up to eight child processes and it hit that limit. Depending on the PHP-FPM version you have to find the file php-fpm.conf or www.conf and increase the pm.max_children recalling that for the maximum value for pm.max_children = RAM dedicada ao servidor / Tamanho máximo permitido a um processo. PS: If you increase memory and dedicated time and still continue to give the same error consider the possibility of your php program being in loop.

  • 1

    @Augustovasques show! changed pm.max_children from 8 to 16. only for knowledge is memory_limit = 128M. apparently no longer generated the log of this. only one other began to appear: NOTICE: [pool www] Child 9430 exited with code 0 after 673.434081 Seconds from start

  • @Claytinho, code 0 means it’s okay, but it’s probably logging in because it’s still close to the time limit, but it didn’t pass. Take it for the rest of your life, Log is your best friend and never forget him.

Show 4 more comments
No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.