SQLAlchemy database connection Pooling is deferred initialization, which means you call Create_engine (...) at the beginning. After you create the database pool is empty, you are behind through session.connection () or Engine.connect () to start creating the connection,
Whenever you create a connection, you call Engine.pool.status () to see what state the database connection pool is in, and the following is a description of the output of the following status ():
' Pool size:16 Connections in pool:1 current overflow:1 current Checked out Connections:16 '
Pool size is the size of the database pool you specify
Connections in pool is the number of connections that can be used in the pool
Current Overflow This parameter indicates that the number of connections currently present exceeds the pool size, and when Overflow (a negative value of pool size) exceeds Max_overflow (default = 10), no new connections can be created, only wait, In other words: the size of your database connection pool is only
But you can create the number of connections is the pool Size+max_overflow, not create a connection overflow will add 1, to equal to Max_overflow when you can not create a connection
Current Checked out Connections is the number of connections that are occupied
Note: These are the various function calls and properties that look at the source code as well as view Engine/session/engine.pool in the Python terminal, the important place to see: __dict__, __class__; Pay attention to using variables to hold connections when creating connections in the terminal. Otherwise you will see the status of the database connection pool unchanged
Engine.pool.checkedin () shows the number of idle connections, size from 0 to pool size
Engine.pool.checkedout () shows the number of connections that are occupied, size from 0 to pool Size+max_overflow
Call Session.connection () or Engine.connect (), take the connection from the database pool, if there is a busy connection to return directly, no idle to see if you can create a connection (that is, the database pool is full), if you can create a new connection, if not, then wait for the connection , the time-out is configurable, please review the documentation
Call Connection.close () to release the connection, put the database connection back into the connection pool, and not actually close the connection
Description of the "notes" Python SQLAlchemy database connection pooling principle