Recently I started using New Relic to profile my application and I came across something peculiar. Every once and a while my application would hang for 15-20 seconds and then fail. Digging in I found that the createConnection method to the percona mysql was timing out in my Laravel5 application.
Here is the offending method in the Laravel5 source: https://github.com/laravel/framework/blob/master/src/Illuminate/Database/Connectors/Connector.php#L48-L63
Here is a picture of the transaction trace that is failing:
There are two instances running the same application in my stack. Each one does about 100-400 calls per minute to the database depending on if the load balancer is pointing to that particulatr instance.
I'm wondering if there is a way to stop this from happening. Some ideas that I had:
- Turn on persistent connections for the PDO connection.
- Change a MySQL setting, not sure which. (Let me know if you want to see the current options).
- Set PHP to timeout after 5 seconds to stop the current connection.
Ideas and thoughts are much appreciated.