# Smarter than max\_connections?

**URL:** <https://forums.percona.com/t/smarter-than-max-connections/670>\
**Category:** Other MySQL® Questions\
**Created:** [March 12, 2008, 7:32pm UTC](https://forums.percona.com/t/smarter-than-max-connections/670 "2008-03-12T19:32:52Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![hamish9876](https://avatars.discourse-cdn.com/v4/letter/h/c67d28/32.png) [@hamish9876](https://forums.percona.com/u/hamish9876)\
**Post date:** [March 12, 2008, 7:32pm UTC](https://forums.percona.com/t/smarter-than-max-connections/670/1 "2008-03-12T19:32:52Z")

</div>

We have a MySQL server which handles queries for 4 web servers. On the server we have max\_connections set to 1600 (400 connections per web server). Anyway, this usually works great - and our app gracefully gives the users a ‘sorry’ message if the max\_connections has been exceeded.

The problem we have is that if for some reason the web servers are making a lot of expensive queries (this just happened when our sql cache mechanism failed - no queries were cached!) then the server gets really overloaded. And because the max\_connections has not been met - it takes on even more queries, even though it’s already really stressed.

So, my question is - is there any way to make MySQL refuse connections based on how high it’s load is (and not simply based on the number of current connections) ??

Or are there any clever tricks at the app level to do this? (we are using PHP).

Thanks!  
Hamish

---

<div class="post-metadata">

**Author:** ![debug](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.percona.com/debug/32/772_2.png) [@debug](https://forums.percona.com/u/debug)\
**Post date:** [March 15, 2008, 12:33am UTC](https://forums.percona.com/t/smarter-than-max-connections/670/2 "2008-03-15T00:33:19Z")

</div>

Hamish,  
Unfortunately there is no way to limit connections to MySQL server based on it’s load.

---

<div class="post-metadata">

**Author:** ![mancdaz](https://avatars.discourse-cdn.com/v4/letter/m/3bc359/32.png) [@mancdaz](https://forums.percona.com/u/mancdaz)\
**Post date:** [March 25, 2008, 4:03pm UTC](https://forums.percona.com/t/smarter-than-max-connections/670/3 "2008-03-25T16:03:29Z")

</div>

Not in mysql directly, but you could do this in application layer. If you maintain current load status of mysql server on the webservers, and then check this before issuing a connection attempt, you could prevent excessive connections causing higher load.

At the most basic level, something like a keyless ssh connection every minute (or more often) to the db server to pull the load and store it locally would do.  
Or you could use snmp polling or anything more sophisticated.

The point is this is all done outside mysql.

mancdaz
