homepage Welcome to WebmasterWorld Guest from 54.227.11.45
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Pubcon Platinum Sponsor 2014
Home / Forums Index / Code, Content, and Presentation / Databases
Forum Library, Charter, Moderators: physics

Databases Forum

    
Mysql too many connections
One long mysql connect better than a number of short ones?
Elric99




msg:4436988
 8:36 am on Apr 4, 2012 (gmt 0)

Hello,

I've got a big problem on my websites at the moment.

At peak times I get too many connection errors on my websites which prevents some people from viewing.

- Dedicated server
- Optimized tables with indexes
- non-persistent connections.

What I do is make the mysql connect at the start of each page, run the queries and let the page auto disconnect at the end of each script.

Would it be better to do numerous connect and close after each query?

Any other ideas how I can beat this crippling problem?

Thank you

Tom

 

phranque




msg:4437020
 11:27 am on Apr 4, 2012 (gmt 0)

mod_dbd - Apache HTTP Server:
http://httpd.apache.org/docs/2.2/mod/mod_dbd.html [httpd.apache.org]

whoisgregg




msg:4437043
 1:01 pm on Apr 4, 2012 (gmt 0)

A good place to start debugging this is MySQL's "too many connections" page [dev.mysql.com].

Typically, most modern web servers can support many more than 150 connections. In fact, most web servers are still using default settings that were designed for hardware from 3 - 10 years ago. A little bit of tuning can go a long way towards avoiding problems.

If you've already tuned the settings and you're still getting this problem, then, well, it could just be that you have a very popular site and need to upgrade your hardware. :)

enigma1




msg:4437440
 11:41 am on Apr 5, 2012 (gmt 0)

You may want to reduce the wait_timeout variable so mysql processes don't wait too long. You should setup the log_slow_queries in the mysqld section of my.cnf so you can record queries that take too long eg:

# close the connection after 15secs inactivity
wait_timeout=15

# record queries which take longer than 3 secs.
log_slow_queries=/var/log/mysqld.slow.log
long_query_time=3

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / Databases
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved