A customer who used my Sendy Installation Service came to me with an error that makes their Sendy installation basically useless. Their Sendy was so slow that they couldn't even login. Sometime it gave a 502 Bad Gateway error after stuck at loading for few minutes.
The 502 Bad Gateway error means that a timeout is reaching in Nginx. Finding and increasing it might avoid the Bad Gateway error, but Sendy will still be so and hard to use.
After doing some digging, I found that MySQL is using all the CPU available on the server. This was a 8 vCPU server and all the CPUs are at 100% with MySQL. This leaves little to no processing power for other tasks.
After further digging in MySQL, I found that the problem is due to idle connections. PHP connections are getting pooled and reaching timeout setting in Nginx.
I fixed to issue by configuring MySQL to close unused connections. I added following values to mysqld.cnf
interactive_timeout=60 wait_timeout=60
Sendy started performing a lot better after the restart. This help was provided under my Server Error Troubleshooting service.