Background: Mariadb,mycat middleware.
Problem: The number of DB connections is too large; development uses the connection pool to connect the Mycat;
DB to optimize: Interactive_timeout,wait_timeout are 8-hour default values.
Mycat Configuration: 100 shard Libraries, and other business libraries. The Shard library now uses 16 shards, which are not yet in use.
Current DB maximum number of connections: 3000
Mycat version: The Mycat version on the current line is version 1.5.8, it is recommended to use the most stable version of mycat1.6.5 on the line.
After DB and development meet to understand that these two timeout time can not be shortened, so the conventional optimization means can not be used:
The number of normal DB connections is 1000, the database two timeout is 300--500, and the parameters can be dynamically applied globally.
The company online DB before the time of the total number of connection problems, the normal connection number 1000, has been able to meet most of the requirements.
When normal means cannot be used, then find out why DB has too many connections.
1. Audit log
Audit log deployed on DB, audit log deployment please visit: Audit log deployment, audit log can see the bad boy who is doing bad!
Not saved because of a time relationship. However, a large number of access connections found in the audit log are ' Select 1 ' and are mycat connections to MySQL.
And the link is a large number of unused physical libraries.
The audit log can only be judged here.
2. DB level
MARIADB Physical Library Information_schema processlist Table records connection related information, such as Db,host,info,status. And you can count the number of connections for a particular library.
After the query, found that many unused DB connections are not released, probably accounted for about 60% of the total number of connections, using the script "kill ID; " after the connection is still reconnected.
The situation was awkward and there was no reason to find it.
3. Audit log
Combined with the audit log, to see where the connection from, or Mycat sent over the One of these is about the unused DB connection algorithm: If the current DB has been accessed, then the heartbeat that linked to the DB is temporarily not executed, and the DB link is reconnected for 300 seconds.
This algorithm is a personal understanding, because of limited capacity, code reading ability is low, can only understand a general, can now judge a general direction.
4. Change the Mycat configuration
- Current MYCAT configuration: <schema><table datanode ></table></schema>datanode
The unused datanode need to be reduced and the number of connections is not reduced.
Kill ID; or the number of connections will grow again. The decision to change Datanode alone is not the way to solve the problem.
- Change <datanode></datanode>:
Delete unused <datanode></datanode>, kill ID again; Operation. Unused <datanode></datanode> connections no longer appear.
At this point, the problem solved, the experimental text narrative more, less description, only for the reader's reference.
Mycat consume too many MySQL connections