Just a very short post here as I wanted to share some finding on a problem I recently encountered.
On one of my websites I was implementing a Jcart Shopping cart instead of just the previous ‘buy now’ button to do some A/B testing to see what does better. When the implementation was done everything was working however I noticed the site was getting unresponsive and eventually the server even crashed.
So I started to investigate and I found that Mysql was suddenly using 80 – 150% of the CPU but with almost no memory being used (weird!) and this was putting the server on its knees. Coincidentally I did had a surge in visitors so I started to tune the Mysql config however that didn’t help. Then I noticed that a lot of php-fpm processes were active (using ‘top’ command) and stayed active. They weren’t being killed for some reason. So I tried tuning the php-fpm config. Again no results.
At this point I turned back to the code and I found that when I disabled the shopping cart class and restarted Mysql the problems were gone. Weird! Now after a lot of debugging I found that due to the config file setup of Jcart I had unknowingly created a circular inclusion in php like this:
— jcart.php (jcart class)
—- config-loader.php (part of jcart)
—– cartconfig.php (part of jcart)
—— config.php (back to the beginning)
I had to make some changes to solve this problem but when I did all was working correctly and no more high CPU Mysql problems.
Conclusion: creating a circular (in my case 4 steps) inclusion in php on Nginx + PHP-FPM + Mysql causes php-fpm worker processes not to be killed and Mysql CPU usage to go haywire.
PHP extension: mysqli
Server version: 5.5.31-1
MySQL client version: mysqlnd 5.0.8-dev – 20102224
Connection via: socket
php version: 5.3.27