Saturday, September 3, 2011

Large number of MYSQL connections get time out or time wait

Not sure how frequently people run to this issue. Sometime when you suddenly have a flood MYSQL connection request to MYSQL servers in a very short time. You might get connection timeout errors or see a lot of connection in time wait state. 
This is because MYSQL can't serve the connection fast enough and it's default listening queue size is rather small at 50.
You can set MYSQL variable back_log to lift this limit.
However this require a MYSQL server bounce.

back_log
 
Command-Line Format --back_log=#
Option-File Format back_log
Option Sets Variable Yes, back_log
Variable Name back_log
Variable Scope Global
Dynamic Variable No
Permitted Values
Type numeric
Default 50
Range 1 .. 65535

The number of outstanding connection requests MySQL can have. This comes into play when the main MySQL thread gets very many connection requests in a very short time. It then takes some time (although very little) for the main thread to check the connection and start a new thread. The back_log value indicates how many requests can be stacked during this short time before MySQL momentarily stops answering new requests. You need to increase this only if you expect a large number of connections in a short period of time.
In other words, this value is the size of the listen queue for incoming TCP/IP connections. Your operating system has its own limit on the size of this queue. The manual page for the Unix listen() system call should have more details. Check your OS documentation for the maximum value for this variable. back_log cannot be set higher than your operating system limit.

No comments: