Advantages of the database connection pool technology in the python database connection pool

Source: Internet
Author: User

If you think it takes too long to open a thread to request a database, you can use the python database connection pool to improve the shortcomings. The following is a detailed introduction of the article, you can use our article to have a better understanding of the python database connection pool.

Yesterday I tested how much it will take to open 500 threads to request the database. That is, the efficiency of initiating so many threads at the same time. So I thought whether using the database connection pool technology can significantly improve such connection operations. After you finish the sorting, You need to test the data: the efficiency of frequently establishing and disabling database connections and the Performance Comparison Between the connection pool!

1. DBUtils module Learning

DBUtils is actually a Python package containing two sub-modules, one for connecting DB-API 2 modules, and the other for connecting typical PyGreSQL modules. Global DB-API 2 variable

 
 
  1. SteadyDB.py 

Used for stable database connection

 
 
  1. PooledDB.py 

Connection Pool

 
 
  1. PersistentDB.py 

Maintain continuous database connections)

 
 
  1. SimplePooledDB.py 

Simple connection pool PS: extract the DB-API out of it

 
 
  1. <!--[if !vml]--><!--[endif]--> 

The installation provides basic services for the two modules of the top-level module, PersistentDB and PooledDB.

DBUtils. PersistentDB achieves a strong, thread-safe, stubborn database connection, using the DB-API 2 module. As shown in the use of PersistentDB connection layer steps: DBUtils. PooledDB implements a strong, thread-safe, cached, reusable database connection, using any DB-API 2 module. For example, the workflow for using PooledDB is shown as follows:

Currently, we have two modules to choose from: PersistentDB and PooledDB. They are designed to reuse database connections to improve performance and maintain database stability.

 
 
  1. python setup.py install 

Specific module learning:

DBUtils. SimplePooledDB is a very simple database connection pool implementation. He lacks many functions than the perfect PooledDB module. DBUtils. SimplePooledDB is essentially similar to the component of the MiscUtils. DBPool Webware. You can think of it as a demo program.

DBUtils. SteadyDB is a module that achieves "strong" database connection, based on the original connection established in DB-API 2. A "strong" connection means that the connection will be reconnected after the connection is closed or when the operation limit is applied. A typical example is when the database is restarted, and your program is still running and needs to access the database, or when your program connects to the remote database behind a firewall, the firewall is lost when it is restarted.

Generally, you do not need to use SteadyDB directly.

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.