Django model layer (database) connection processing logic:
CONN_MAX_AGE
configuration to limit the DB connection lifeCONN_MAX_AGE
is 0
Disadvantages of the default database connection
How to avoid django over-optimization
Store database connection location: thread local variables (when django is deployed, each thread processed has a database connection, because this connection is saved in thread local variables and is not affected by other threads)
The maximum number of connections supported by the mysql database, (if the number of deployment threads exceeds the maximum number of connections to the database, it will cause other services to connect to mysql incorrectly, resulting in failure to connect to the database)
How to view the maximum number of mysql connections:
Use Navicat, find the corresponding database, right click, find the command line interface, enter the command:
mysql> show variables like '%max_connections%';
+-----------------+-------+
| Variable_name | Value |
+-----------------+-------+
| max_connections | 151 |
+-----------------+-------+
1 row in set
mysql>
You can know that the maximum number of connections to the mysql database is 151
.
Modify the maximum number of mysql connections:
mysql> set global max_connections =1000;
Query OK, 0 rows affected
mysql> show variables like '%max_connections%';
+-----------------+-------+
| Variable_name | Value |
+-----------------+-------+
| max_connections | 1000 |
+-----------------+-------+
1 row in set
mysql>