Skip to main content

A tiny database de-multiplexer primarily scoped for Web- / Application Server.

Project description

Python PgDatabase-Pool Module

push main PyPI version

1. Primary Scope

The pgdbpool Python module is a tiny PostgreSQL Database Connection De-Multiplexer, primarily designed for Web- / Application Servers.

2. Current Implementation

+----------------------+                         +---------------------
| WebServer Service.py | -- Handler Con #1 ----> | PostgreSQL
| Request / Thread #1  |                         | Backend
+----------------------+                         |
                                                 |
+----------------------+                         |
| WebServer Service.py | -- Handler Con #2 ----> |
| Request / Thread #2  |                         |
+----------------------+                         +---------------------

2.1. Concept / Simplicity

If configured in a Web Server's WSGI Python script, the pooling logic is straightforward:

  1. Check if a free connection in the pool exists.
  2. Verify if the connection is usable (SQL ping).
  3. Use the connection and protect it from being accessed until the query/queries are completed.
  4. Release the connection for reuse.
  5. Reconnect to the endpoint if the connection is lost.

3. Thread Safety / Global Interpreter Lock

Thread safety is currently ensured via lock = threading.Lock(), which relies on a kernel mutex syscall().

While this concept works, the GIL (Global Interpreter Lock) in Python thwarts scalability under heavy loads in a threaded Web Server setup.

[!IMPORTANT] Refer to Section 6: Future for a potential solution to this problem.

4. Dependencies / Installation

Python 3 and the psycopg2 module are required.

# install (debian)
apt-get install python3-psycopg2
pip install pgdbpool

5. Documentation / Examples

See documentation either at ./doc or https://pythondocs.webcodex.de/pgdbpool for detailed explanation / illustrative examples.

6. Future

The DB-pooling functionality should also be compatible with the FalconAS Python Application Server (https://github.com/WEBcodeX1/http-1.2).

The proposed model: 1 Process == 1 Python Interpreter (threading-less), effectively solving the GIL issue.

[!NOTE] The pool should also be configurable to use multiple (read-load-balanced) PostgreSQL endpoints.

linting: pylint

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pgdbpool-1.0rc1.tar.gz (18.3 kB view details)

Uploaded Source

File details

Details for the file pgdbpool-1.0rc1.tar.gz.

File metadata

  • Download URL: pgdbpool-1.0rc1.tar.gz
  • Upload date:
  • Size: 18.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.11.2

File hashes

Hashes for pgdbpool-1.0rc1.tar.gz
Algorithm Hash digest
SHA256 fb5ca4c054f66878e8a6cd1beec81ad5e2996a5e8f92227121620aa076b5cdaf
MD5 9155eda632def8f804cc8ce70a116b64
BLAKE2b-256 b4a9359dc05b666789fe3a06d91df68201d3fcc56acaafd78882718f9aecc0ce

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page