NYCPHP Meetup

NYPHP.org

[nycphp-talk] Advice: Too many mysql connections.

Ian Forsyth ian at plusfour.org
Mon Nov 10 23:12:27 EST 2003


Hi,


On Friday, November 7, 2003, at 08:13 PM, Hans Zaunere wrote:

>
>
>> The developer uses a phplib based database class. On average each 
>> 'page' is using 3 instances of the database class. The connect method 
>> is using mysql_connect();. The developer is re-working the db class 
>> so a maximum of instance of the class will be initialized on any page 
>> load. The site is used book dealer, and relies heavily on the 
>> full_text indexing of about 100,00 records.
>
> Mostly as an FYI, keep in mind mysql_connect()'s behavior.  If a 
> connection already exists with the same host, user and password 
> information, the connection will be reused by default.  This means 
> that even if 3 objects are created, they should be using a single 
> MySQL connection (assuming they have the same connection information).

That makes sense. All connections are using the same login info.
>
>> The site gets a lot of traffic. According to webalizer, it gets been 
>> getting about 20,000 'Visits' a month. There are not any other sites 
>> running on the computer. It is just this site.
>> MyQuestions.
>> What are your opinions regarding 1. Hardware, is there enough ram on 
>> the box to handle increasing the 'max_connections' to 500. 2. Which 
>> my-*.cnf
>
> I would most likely say "yes."  Of course, use the standard utilities 
> to determine system state (top,free,memfree,mem,vmstate,/proc,etc, 
> depending on the platform).  Also keep in mind the limit on file 
> descriptions.  I don't remember off hand what default values are, but 
> MySQL is generally file descriptor heavy.
>
>> should we be using. Everything is basically the defaults.. Here is a 
>> link to the results of the show variables.
>> http://plusfour.org/mysqlVariables.txt
>
> I'm not seeing anything shockingly wrong here.  There are some 
> formulas to dig up and tweaks you could make, but since the issue 
> seems to be connections now, this should probably wait until the box 
> is humming along in a reliable state.
>
>> 2. At what point do i give the my-large.cnf a try.. how can I test 
>> it.. 3. What are the pear classes for load testing?
>
> 512mb is not a large RAM system, and I'd hesitate making a change like 
> that without first seeing how it responds to an increase in the max 
> connections.  Personally, I'd write a quick script for load testing so 
> I can't be much help there either.

Thanks very much, for the tips. I am going to make something to open up 
http connections till the connection results in a 'too-many mysql 
connections' error page late at night. I'll keep track of how many 
connections are opened. I'll trade in the different my-*.cnf config 
files and see what happens.

When we tried setting max-connection to 500 using our existing minimal 
my.cnf config, we could not access the server via http, ssh, etc.. I'll 
see what happens after load tests. That way I can have some concrete 
data. Maybe its time for more ram.

Again, thanks for the tips.

Ian




More information about the talk mailing list