Quote:
Originally Posted by nephish
The process that puts data into the database and the processes that manipulate that data is run by threads in a python program. About 12 threads in all, each one either reading from or writing to a particular table. We have two tables that are causing us trouble, and another that will be soon.
Our history table because it is very very large, and another table we have that is small, like 140 rows, this is just where we put configuration variables that are read from the threads.
|
Python has a Global Interpreter Lock (GIL) that allows only one thread at a time to "run" within Python. It's likely that you're deadlocking like this:
Thread-1: Has GIL, waiting for lock to release on database
Thread-2: Waiting for GIL to release, has lock on database
That's the first thought that comes to mind for me...and once two threads get deadlocked like this, the Python program would come to a halt (until the lock timeout on the database allowed one Python Thread to bomb...but it wouldn't be too long before the condition arose again). To work around this, you could potentially run the 12 or so Python threads in their own process so if one locks, it won't cause a wait on the other 11.
As for the history table, can you run a weekly or monthly process to partition the table into, say, "History-2008-08", "History-2008-07", "History-2008-06", etc...? Breaking the large history table into smaller monthly history tables would greatly speed accesses and writes to the history table(s).