Opened 14 years ago

Closed 14 years ago

#13351 closed (fixed)

The notes for Oracle in the django database documentation may need to draw attention to the "threaded" option

Reported by: Skaffen Owned by: nobody
Component: Documentation Version: 1.1
Severity: Keywords: Oracle
Cc: Triage Stage: Accepted
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no



While I do use Django for projects I only use it with PostgreSQL. However I do also maintain an in-house legacy ORM that itself uses cx_Oracle. I've just finished resolving a crashing fault and some other odd behaviour under windows 2003 for a web-app using it that cropped up under load when we moved to Oracle 11 from Oracle 10 when on a multi-CPU machine (the relevant bits of the stack involved are apache 2.2/mod_python/cx_Oracle 5/oracle instance client 11). The problem was resolved by passing in "threaded=True" to the connection string for cx_Oracle. Although apache under windows is multi-threaded I believe we didn't pass this argument in historically as connections weren't shared between threads (so why should the locking around connection use be needed) and there were never any problems.

My guess is that with the introduction of client query result cache and database resident connection pooling in OCI may mean that behind the scenes some memory structures that aren't per-connection are now used such that a multi-threaded app with multiple connections may run into issues if the threaded mode isn't enabled in OCI.

I'm not an expert on OCI, cx_Oracle and like I said I don't use django's oracle driver but I did feel it worth mentioning my experiences in a ticket so the maintainer could consider if it worth drawing attention to the threaded option for cx_Oracle in the django oracle notes, and if not then at the very least my experience is recorded in the bug tracker so if someone using django with oracle in a threaded environment hits crashing they have something to try :).

cx_Oracle says about the threaded option
"The threaded argument is expected to be a boolean expression which indicates whether or not Oracle should use the mode OCI_THREADED to wrap accesses to connections with a mutex. Doing so in single threaded applications imposes a performance penalty of about 10-15% which is why the default is False."

See for the oracle documentation about thread safety and OCI - my reading of that is that if using cx_Oracle in a multi-threaded programme (which using django under mod_python/apache on Windows certainly is as apache uses threads) then threaded=True is best passed into cx_Oracle.

Change History (3)

comment:1 by Russell Keith-Magee, 14 years ago

Triage Stage: UnreviewedAccepted

comment:2 by Erin Kelly, 14 years ago

Back in September Anthony made the statement to the cx-oracle-users mailing list that "You need to specify threaded = True if you have any intentions of using threads and the Oracle client at the same time."

This indicates to me that we should probably be altogether more paranoid and make threaded=True the default behavior, with a warning in the documentation about only disabling it if you know what you are doing.

comment:3 by Erin Kelly, 14 years ago

Resolution: fixed
Status: newclosed

(In [14632]) [1.2.X] Fixed #13351: Added documentation about the cx_Oracle 'threaded' option to the oracle backend notes.

Backport of r14630 from trunk.

Thanks to Skaffen for the suggestion.

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