I just fixed an odd bug on the WonderProxy admin pages. Occasionally there would be an issue where the administrative dashboard would refuse to load. It would display an all too common message that the database was out of connections. This was quite odd as there’s generally almost no users on our site, so there’s no reason for MySQL to run out of connections. I had much larger issues to work on, and the issue was almost always temporary, so I didn’t really worry about it.

Last night while improving our admin dashboard I tweaked a few things, and was wondering about performance. Curious why the page was loading slowly I ran show processlist; from the MySQL console, and was astonished to see well over a hundred connections.

A few minutes of digging revealed that while the administrative dashboard was creating instances of the Contract object to display their traffic details, each Contract instance was also generating its own connection to the database! As the number of active contracts we’ve managed has increased over time, so has the number of connections to the database. The issue was intermittent, as the number of connections we’re allowing to MySQL still exceeds the number of contracts WonderProxy has. However hourly cron jobs handling billing, maintenance, etc. can create enough connections to put it over the edge.

I’ve corrected my code to properly share the database connection, the page loads faster, and doesn’t crash if something else is happening on the server. I don’t often make such fundamental mistakes (or so I’d like to think) so I thought I would share.


Comments »

No Trackbacks
No comments

Enclosing asterisks marks text as bold (*word*), underscore are made via _word_.
Standard emoticons like :-) and ;-) are converted to images.
 

Hi, I’m Paul Reinheimer, a developer working on the web.

I wrote a book titled Professional Web APIs with PHP back in 2006, and am currently working in Biomedical Informatics for a major public health company.

I’m working on a project to help developers called WonderProxy which has proxies all over the world. Working on GeoIP development? Now you can finally test properly! We've also released Global Ping Statistics for expected ping times between cities, as well as a Load Testing Tool to measure your site's ability to handle load. Our most recent site checking tool is Where's it Up? which checks your sites availability globally, returning HTTP, DNS, and Traceroute details

My hobbies are cycling, photography, travel, and engaging Allison Moore in intelligent discourse. I frequently write about PHP and other related technologies.

I co-founded:

WonderNetwork Logo

Search