2

In a load test of our PHP based web application we can easily reach our DBs hard limit of 150 max connections. We run Kohana with ORM to manage the DB connections.

This causes connection exceptions (and thus failed transactions), mysql_pconnect seems to perform even worse.

We're looking for a solution to have graceful degradation under load. Options considered:

  1. A DB connection pool (uh, that's not possible with PHP right?)
  2. Re-try a failed connection when the failure was due to max connections reached

2 seems logical, but Kohana/ORM manages the DB connection process. Can we configure this somehow?

Is there something I'm not thinking of?


EDIT

This is an Amazon AWS RDS database instance, Amazon sets the 150 limit for me, and the server is most certainly configured correctly. I just want to ensure graceful degradation under load with whichever database I'm using. Clearly I can always upgrade the DB and have a higher connection limit, but I want to guard against a failure situation in case we do hit our limit unexpectedly. Graceful degradation under load.

David Parks
  • 30,789
  • 47
  • 185
  • 328

2 Answers2

2

When you say load testing, I am assuming you are pushing roughly 150 concurrent requests and not that you are hitting the connection limit because you make multiple connections within the same request. If so, check out mysql_pconnect. To enable it in Kohana, simply enable persistent = true in the config/database file for your connections.

If that doesn't work, then you'll have to find an Amazon product that allows more connections since PHP does not share resources between threads.

This answers your question about PHP database connection pooling.

Community
  • 1
  • 1
gspatel
  • 1,128
  • 8
  • 12
0

If the limit is 150 for connections (default for max_connections is 151), you are most likely running mysql without a config file

You will need to create a config file to raise that number

Create /etc/my.cnf and put in these two lines

[mysqld]
max_connections=300

You do not have to restart mysql (you could if you wish)

You could just run this MySQL command to raise it dynamically

SET GLOBAL max_connections = 300;

UPDATE 2012-04-06 12:39 EDT

Try using mysql_pconnect instead of mysql_connect. If Kohana can be configured to use mysql_pconnect, you are good to go.

RolandoMySQLDBA
  • 43,883
  • 16
  • 91
  • 132
  • MySQL is running as an AWS RDS instance, I don't believe I even have an option to configure this, it's a limit set by them. I can only upgrade to a bigger server. – David Parks Apr 06 '12 at 04:33