Description of the "notes" Python SQLAlchemy database connection pooling principle

Source: Internet
Author: User
Tags connection pooling

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.