Read how to solve the MySQL database timeout configuration problem

Now that it has entered the end of October, there is not much time for the Double Eleven, and major e-commerce companies are preparing for war. In the process we found a lot of timeout configuration in the MySQL database, then what timeout configuration does it have, what effect will it have? Today's article let me come to analyze it.

1. JDBC timeout settings

connectTImeout: indicates the timeout period for waiting for a socket connection with the MySQL database. The default value is 0, indicating that the timeout is not set, in milliseconds, it is recommended to 30000.

socketTImeout: indicates the timeout period for the client and the MySQL database to wait for the socket to read and write after the socket is created. The default socketTImeout of the Linux system is 30 minutes.

2. Connection pool timeout setting

maxWait: indicates the waiting time from the database connection pool, the connection pool has no available connection, the default value of 0, indicating unlimited waiting, in milliseconds, recommended 60000

Read how to solve the MySQL database timeout configuration problem

3. MyBaTIs query timed out

defaultStatementTimeout: indicates that the default query time in the MyBatis configuration file is in seconds. If not set, the wireless waits.

Read how to solve the MySQL database timeout configuration problem

If some sql needs to execute more than defaultStatementTimeout, it can be configured through the Mapper file's separate sql timeout.

Read how to solve the MySQL database timeout configuration problem

4. Transaction timeout

The transaction timeout is used to control the timeout of transaction execution. The execution time is the sum of all code executions in the transaction, in seconds.

Read how to solve the MySQL database timeout configuration problem

to sum up

The high-level timeout relies on low-level timeouts, and high-level timeouts are guaranteed to be normal only when low-level timeouts are correct. For example, when there is a problem with socket timeout, both the high-level statement timeout and the transaction timeout will fail.

Transaction Timeout

The transaction timeout configuration provided by Spring is very simple. It records the start time and consumption time of each transaction. When a specific event occurs, it will check the consumption time. When the timeout value is exceeded, an exception will be thrown.

Suppose a transaction contains 5 statements, each statement has an execution time of 200ms, and other business logics have an execution time of 100ms. Then the transaction timeout should be set to at least 1,100ms (200 * 5 + 100).

2. Statement Timeout

The statement timeout is used to limit the execution time of the statement. The value of timeout is set by calling the JDBC java.sql.Statement.setQueryTimeout(int timeout) API. However, developers are now rarely set directly in the code, but mostly through the framework.

In iBatis, the default value of the statement timeout can be set via the defaultStatementTimeout property in sql-map-config.xml. At the same time, you can also set the timeout property of the select, insert, and update tags in sqlmap to configure the timeout of different sql statements independently.

3. Socket timeout

JDBC socket timeout is very important when the database is suddenly stopped or a network error occurs (due to device failures, etc.). Due to the structure of TCP/IP, there is no way for the socket to detect a network error, so the application cannot actively discover that the database connection is broken. If socket timeout is not set, the application waits indefinitely before the database returns the result. This connection is called dead connection.

In order to avoid dead connections, the socket must have a timeout configuration. Socket timeout can be set by JDBC, socket timeout can avoid the application to endless waiting in the event of network errors, shortening the service failure time.

It is not recommended to use socket timeout to limit the execution time of the statement. Therefore, the value of socket timeout must be higher than the statement timeout. Otherwise, the socket timeout will be effective, so the statement timeout becomes meaningless and cannot take effect.

Ceramic Capacitor

Ceramic capacitor (ceramic capacitor);Ceramic condenser) is also known as porcelain capacitor or monolithic capacitors.As the name implies, ceramic dielectric vessel is a ceramic capacitor with dielectric material.According to different ceramic materials, this kind of capacitor can be divided into low-frequency porcelain dielectric vessel with capacity of 1-300 pF and high-frequency porcelain dielectric vessel with capacity of 300-22 000 pF.According to the structure type classification, can be divided into picture capacitor, tubular capacitor, rectangular capacitor, chip capacitor, piercing capacitor and so on.

Ceramic Capacitor,White Ceramic Capacitor,Smd Ceramic Capacitor,Multilayer Chip Ceramic Capacitor

YANGZHOU POSITIONING TECH CO., LTD. , https://www.cndingweitech.com