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:
Ideas and thoughts are much appreciated.
After a lot of experimenting I came to the conclusion that turning on Persistent Connections in our MySQL PDO connection was the answer. I had a alot of reservations about turning them on based upon what I had read. But after reading this post: Persistent DB Connections - Yea or Nay? and Steve Corona's book "Scaling PHP Applications", that turning on persistent connections was the way to go.