Python database connection Pooling Technology summary

Source: Internet
Author: User
If you are in the thread request database if you think the time spent is too long, you can use the Python database connection pool to improve the shortcomings in this area, the following is the specific introduction of the article, you can use our article on the Python database connection pool have a better understanding.

I tested it yesterday. Open 500 threads to request the database, but this time is not clear how much. That is, how efficient it is to launch so many threads at the same time. So the idea is not to use database connection pool technology can obviously improve such a connection operation. You're going to be finished. Test a data: the efficiency of frequent and close database connections is compared to the performance of connection pooling!

One, dbutils module learning

Dbutils is actually a Python package with two submodules, one for connecting the Db-api 2 module and the other for connecting a typical Pygresql module. Global DB-API 2 variables

steadydb.py

For stabilizing database connections

pooleddb.py

Connection pool

persistentdb.py

Maintain a continuous database connection (persistent connection)

simplepooleddb.py

Simple Connection Pool PS: First excerpt Db-api come out a bit

The two modules installed as top-level modules provide basic services, PERSISTENTDB and POOLEDDB.

Dbutils.persistentdb implements a tough, thread-safe, stubborn database connection using the Db-api 2 module. As shown in the connection layer step when using Persistentdb: Dbutils.pooleddb implements a strong, thread-safe, cached, reusable database connection using any DB-API 2 module. As shown in the workflow when using POOLEDDB:

Currently we have two modules to choose from: Persistentdb and POOLEDDB are all designed to reuse database connections to improve performance and maintain database stability.

Python setup.py Install

Specific Module Learning:

DBUTILS.SIMPLEPOOLEDDB is a very simple database connection pooling implementation. He lacks many features than the perfect POOLEDDB module. DBUTILS.SIMPLEPOOLEDDB is essentially similar to the miscutils.dbpool part of this webware. You can think of it as a demo program.

Dbutils.steadydb is a module that implements a "tough" database connection, based on the original connection established by Db-api 2. A "tough" connection means reconnecting when the connection is closed or when the usage limit is limited. A typical example is when the database restarts and your program is still running and requires access to the database, or when your program is connected to a remote database behind a firewall and the firewall is restarted with a status of missing.

In general, you don't need to use steadydb directly, it's just to pick up

  • 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.