1

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: Transaction Trace with createConnection hang

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.

whobutsb
  • 1,075
  • 4
  • 13
  • 28

1 Answers1

0

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.

Community
  • 1
  • 1
whobutsb
  • 1,075
  • 4
  • 13
  • 28