python threads on multi-CPU machines

Daniel Dittmar daniel at dittmar.net
Mon Aug 18 14:31:28 EDT 2003


Aahz wrote:
> Cool!  When you're done, I'd appreciate it if you could write up a short
> summary of the problems you ran into and post it here.  I'm interested
> in pushing computational threading in Python, but I haven't written
> enough C code to have any idea how it differs from other kinds of
> threading issues.

I've written a C extension to access a database and I came upon the 
following:
A multithreaded application on a 4 CPU machine would keep the database 
server less busy than the same application written in Java. The 
behaviour on the Python side got somewhat better when
  - I kept the GIL while sending the request to the database and
  - released it only while waiting for the reply.

I guess this had something to do with the fact that releasing the GIL 
triggers a thread switch (at least on Windows) and this introduced a lag 
  until the thread got control again and could actually send the 
requrest to the database.

I wasn't able to test this behaviour with other operating systems, as I 
hadn't them on multi-CPU machines.

Daniel





More information about the Python-list mailing list