Django

Code

Ticket #1237 (closed: duplicate)

Opened 2 years ago

Last modified 1 year ago

[patch]thread safety connection pool for all backend

Reported by: junzhang.jn@gmail.com Assigned to: adrian
Milestone: Component: Database wrapper
Version: Keywords: connection pool db
Cc: Triage Stage: Unreviewed
Has patch: 1 Needs documentation: 0
Needs tests: 0 Patch needs improvement: 0

Description

Django uses the same connection for all threads. It breaks any database when using transaction or in multithread web server. this patch is implemented to avoid it.

like ticket [463] but for all.

- use AutoReleaseCursor? return connection object to pool when cursor deleted.

- use connections dict protect threaded active connection.

- db backend must implement a get_check_sql function to provide a sql which can check a connection's health.

ado_mssql:

def get_check_sql():
    return "select top 1 1 from sysfiles"

oracle:

def get_check_sql():
    return "select 1 from dual";

other....

sorry for my very very poor english.

Attachments

__init__.py.diff (3.4 kB) - added by junzhang.jn@gmail.com on 01/17/06 03:26:53.
pool.py (5.6 kB) - added by junzhang.jn@gmail.com on 01/17/06 03:28:32.
__init__.py.2.diff (2.7 kB) - added by junzhang.jn@gmail.com on 01/17/06 19:30:14.
delete AutoReleaseCursor? , it breaks transaction in multithread when 'threadsafety > 1'.
modpython.py.diff (1.0 kB) - added by junzhang.jn@gmail.com on 01/17/06 19:31:01.
wsgi.py.diff (0.9 kB) - added by junzhang.jn@gmail.com on 01/17/06 19:31:29.
django.db.__init__.py.diff (2.9 kB) - added by junzhang.jn@gmail.com on 02/28/06 18:22:12.
pool.py.2 (6.0 kB) - added by junzhang.jn@gmail.com on 02/28/06 18:22:42.

Change History

01/17/06 03:26:53 changed by junzhang.jn@gmail.com

  • attachment __init__.py.diff added.

01/17/06 03:28:32 changed by junzhang.jn@gmail.com

  • attachment pool.py added.

01/17/06 19:30:14 changed by junzhang.jn@gmail.com

  • attachment __init__.py.2.diff added.

delete AutoReleaseCursor? , it breaks transaction in multithread when 'threadsafety > 1'.

01/17/06 19:31:01 changed by junzhang.jn@gmail.com

  • attachment modpython.py.diff added.

01/17/06 19:31:29 changed by junzhang.jn@gmail.com

  • attachment wsgi.py.diff added.

02/28/06 18:20:59 changed by junzhang.jn@gmail.com

update the connection pool in magic-removal branch. only the next two diffs needed.

pool.py.2:
  • fix check_thread close not thread safety connetion. now thread safety < 2 connection will not run check thread. so you must use zhe connection in the web server which has thread pool.
  • fix cannot stop the check_thread in manage.py shell. use atexit.register function for this problem.
django.db.__init__.py.diff:
  • add new setting USE_DBPOOL.

and now ,you must implement get_check_sql function in django.db.bachend.xxxx.base.

sqlite3:

def get_check_sql():
    return "SELECT name FROM sqlite_master WHERE type='table' limit 1"

ado_mssql:

def get_check_sql():
    return "select top 1 1 from sysfiles"

postgresql:

def get_check_sql():
    return "SELECT c.relname FROM pg_catalog.pg_class limit 1"

02/28/06 18:22:12 changed by junzhang.jn@gmail.com

  • attachment django.db.__init__.py.diff added.

02/28/06 18:22:42 changed by junzhang.jn@gmail.com

  • attachment pool.py.2 added.

03/10/06 11:56:08 changed by eugene@lazutkin.com

  • status changed from new to closed.
  • resolution set to duplicate.

Superseded by #1442

01/17/07 16:12:17 changed by

  • milestone deleted.

Milestone Version 1.0 deleted


Add/Change #1237 ([patch]thread safety connection pool for all backend)




Change Properties
Action