#1237 closed enhancement (duplicate)
[patch]thread safety connection pool for all backend
Reported by: | 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)
Change History (10)
by , 19 years ago
Attachment: | __init__.py.diff added |
---|
by , 19 years ago
by , 19 years ago
Attachment: | __init__.py.2.diff added |
---|
by , 19 years ago
Attachment: | modpython.py.diff added |
---|
by , 19 years ago
Attachment: | wsgi.py.diff added |
---|
comment:1 by , 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 , 19 years ago
Attachment: | django.db.__init__.py.diff added |
---|
by , 19 years ago
Note:
See TracTickets
for help on using tickets.
delete AutoReleaseCursor , it breaks transaction in multithread when 'threadsafety > 1'.