Skip to main content

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

Project description

Python PgDatabase-Pool Module

1. Primary Scope

The pgdbpool Python Module is a tiny PostgreSQL Database Connection De-Multiplexer primarily scoped for Web- / Application Server.

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-Servers WSGI Python Script, the Pooling-Logic is quite simple.

  1. Check if a free connection in the pool exists
  2. Check if connection usable (SQL ping)
  3. Use connection and protect it from beeing used until querie(s) finished
  4. Release connection for usage again
  5. Try reconnecting to endpoint if connection has been lost

3. Thread Safety / Global Interpreter Lock

Currently Thread Safety is guaranteed by lock = threading.Lock() which implies a Kernel Mutex syscall().

The concept works, but the GIL (Python Global Interpreter Lock) thwarts our plans 😞.

In detail: if used in a threaded Web-Server setup, it does not really scale well on heavy loads.

[!IMPORTANT] Take a closer look at "6. Future", problem solved probably.

4. Dependencies / Installation

Python 3 and psycopg2 module is required.

# 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

DB-Pooling also should be usable in FalconAS Python Application Server (https://github.com/WEBcodeX1/http-1.2).

The model here: 1 Process == 1 Python Interpreter (threading-less), GIL Problem solved.

[!NOTE] Also a Pool should be configurable to use multiple (read-loadbalanced) PostgreSQL Endpoints.

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-0.98rc1.tar.gz (5.8 kB view details)

Uploaded Source

File details

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

File metadata

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

File hashes

Hashes for pgdbpool-0.98rc1.tar.gz
Algorithm Hash digest
SHA256 130df0d3da124f01a03e64ac40fd333d7e5dda9c29a3ffba8dff251471c428e0
MD5 81a9814f6d6e6c190d4f0c3d43ebebbf
BLAKE2b-256 77bc3346f17155283b80e4039bffd82743e08ae63d2478af400b89bb248357c9

See more details on using hashes here.

Supported by

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