Opened 19 years ago

Closed 19 years ago

Last modified 18 years ago

#1237 closed enhancement (duplicate)

[patch]thread safety connection pool for all backend

Reported by: junzhang.jn@… Owned by: Adrian Holovaty
Component: Database layer (models, ORM) Version:
Severity: normal Keywords: connection pool db
Cc: Triage Stage: Unreviewed
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

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 (7)

__init__.py.diff (3.4 KB ) - added by junzhang.jn@… 19 years ago.
pool.py (5.6 KB ) - added by junzhang.jn@… 19 years ago.
__init__.py.2.diff (2.7 KB ) - added by junzhang.jn@… 19 years ago.
delete AutoReleaseCursor , it breaks transaction in multithread when 'threadsafety > 1'.
modpython.py.diff (1.0 KB ) - added by junzhang.jn@… 19 years ago.
wsgi.py.diff (906 bytes ) - added by junzhang.jn@… 19 years ago.
django.db.__init__.py.diff (2.9 KB ) - added by junzhang.jn@… 19 years ago.
pool.py.2 (6.0 KB ) - added by junzhang.jn@… 19 years ago.

Download all attachments as: .zip

Change History (10)

by junzhang.jn@…, 19 years ago

Attachment: __init__.py.diff added

by junzhang.jn@…, 19 years ago

Attachment: pool.py added

by junzhang.jn@…, 19 years ago

Attachment: __init__.py.2.diff added

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

by junzhang.jn@…, 19 years ago

Attachment: modpython.py.diff added

by junzhang.jn@…, 19 years ago

Attachment: wsgi.py.diff added

comment:1 by junzhang.jn@…, 19 years ago

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"

by junzhang.jn@…, 19 years ago

Attachment: django.db.__init__.py.diff added

by junzhang.jn@…, 19 years ago

Attachment: pool.py.2 added

comment:2 by eugene@…, 19 years ago

Resolution: duplicate
Status: newclosed

Superseded by #1442

comment:3 by (none), 18 years ago

milestone: Version 1.0

Milestone Version 1.0 deleted

Note: See TracTickets for help on using tickets.
Back to Top