On Tue, Jul 20, 2010 at 8:47 AM, Victor Berdin <[email protected]> wrote:
>
> However, if you are dealing with clients wherein it becomes almost impossible 
> to manage
> their network connectivity (WiFi), you may have to play with your Kernel TCP 
> KEEPALIVE
> settings.

dont do that.. TCP KEEPALIVE  doesnt solve the problem...

it takes time to probe if the other end is still alive or not and to
terminate the connection if it is not... for busy server.. this is not
the solution... the problem here is not between the clients and
apache.. but between php to mysql server which causes its mysql
connection to max out...

the main suspect here is the connection between php and mysql
server... either php module is not closing the connection properly due
to bugs or problem with persistent connection, etc...

or perhaps its mysql port is open to outside and someone DOS attack
that port as the original poster didnt give more info on its
configuration...

> --- On Fri, 16/7/10, [email protected] 
> <[email protected]> wrote:
>> Message: 1
>> Date: Thu, 15 Jul 2010 10:14:53 -0700 (PDT)
>> From: Allen Umlas <[email protected]>
>> Subject: [plug] mysql max_connections
>> To: plug list <[email protected]>
>> Message-ID: <[email protected]>
>> Content-Type: text/plain; charset="iso-8859-1"
>>
>>
>> Hi Guys,
>>
>> ???????? I have some sort of problem with mysql server,
>> time_wait connections is reach too much high. It might be
>> some application not closing in certain time probably might
>> be a reason.

TCP TIME_WAIT means both sides closed their connection already...
below is an example how TCP terminate a connection...

1) A ---> FIN ---> B   (host A close the socket)
2) A <--- ACK <--- B (host B ack the fin of host A)
3) A <--- FIN <--- B   (host B close the socket)
4) A ---> ACK ---> B  (host A ack the fin of host B)

host A is either a server or a client...the one who sends the first
FIN or close the socket is doing the active close...

after line 4.. host A is now in TIME_WAIT state... it waits twice the
value of your maximum segment lifetime (MSL) before it release or
destroy the resources.. although the connection is already closed but
the socket pair cannot be reused (client IP:port and server IP:port)
during the wait time..

purpose of TIME_WAIT state in case the final ACK (line number 4) didnt
reach to host B.. host B timer times out and resend the FIN packet
again to host A...

lowering TIME_WAIT time still doesnt solve your problem... because it
already closed the connection as your problem is on the number of open
connections...

but you can take advantage of lowering TIME_WAIT time if you have a
very busy server so that  it will release and reuse the resources as
soon as possible.. this was what i did to our proxy servers when i was
still in an ISP in the philippines before...

> So i did set max_connections to 500 but still it
>> reach. How can i made a bash or any script that will send me
>> an email if that time_wait connection reaches certain define
>> number that i might be aware.I usually use this command to
>> monitor time_wait and counts for particular connection.
>>
>> netstat -ant |grep ":3306" |awk '/tcp/ &&
>> /TIME_WAIT/ {print $6,$4}'|sort|uniq -c

can you check what are the source IP addresses connecting to your mysql server?

eg.  netstat -ant | awk '$6 == "ESTABLISHED" && $4 ~ /:3306$/ {print $5}'

above will print the client IP and port number who established a
connection to your mysql server on port 3306...

this will guide you what to do next to solve your problem...

below is a sample script to watch your number of connections of your
msyql server...

#!/bin/bash

NMAX=400
[email protected]

NSLEEP=5
TEMPFILE=/tmp/netstat.txt
EMAILME=0
while [ 1 ]; do
        netstat -ant | awk '$6 == "ESTABLISHED" && $4 ~ /:3306$/
{print $5}' > $TEMPFILE
        NCOUNT=`wc -l < $TEMPFILE`
        if [ "$NCOUNT" -ge "$NMAX" ]; then
                if [ "$EMAILME" -eq "0" ]; then
                        EMAILME=1
                        mail $EMAILTO < $TEMPFILE
                fi
        else
                EMAILME=0
        fi
        sleep $NSLEEP
done

save it to a file with executable bit and run in the background (eg.
./filename.sh&)... since you set your max_connection to 500.. i set
NMAX to 400 so that it will email you once it reaches at that point so
that you have time to check before it hit your 500 connections..

replace EMAILTO to your valid email address and just make sure your
email system inside your mysql server is working properly (eg. echo
testing | mail [email protected])

fooler.
_________________________________________________
Philippine Linux Users' Group (PLUG) Mailing List
http://lists.linux.org.ph/mailman/listinfo/plug
Searchable Archives: http://archives.free.net.ph

Reply via email to