Python Thread Question
Aahz
aahz at pythoncraft.com
Thu Apr 17 10:46:48 EDT 2003
[Mostly good answers from Jp, but one correction is needed]
In article <mailman.1050587609.6119.python-list at python.org>,
Jp Calderone <exarkun at intarweb.us> wrote:
>On Thu, Apr 17, 2003 at 06:34:11AM -0700, Anand B Pillai wrote:
>>
>> 4. Can I safely say that multithreading will improve my application
>> performance if it has similar work to do on many resources at the
>> same time ? (egs: a web parser/ spider/ a disk-to-disk file copier/
>> directory synchronizer) Or does it depend upon the nature of the
>> task at hand ?
>
> Nope. Threading costs you context switches. A multi-threaded app
>using blocking IO will appear "faster" than a single-thread app doing
>the same, but both take longer to run than a single written app using
>non-blocking IO.
>
> Context switches are usually relatively cheap compared to what your
>app is actually doing, though, so the difference between doing blocking
>IO in a multi-thread app and non-blocking IO in a single-thread app
>isn't always obvious. (Other things associated with multi-threaded
>apps, such as deadlocks and race conditions are, though ;)
This isn't quite true on a multi-CPU box. Because I/O releases the GIL,
the OS can schedule threads to run on all available CPUs. So it's
certainly possible for a threaded app to outrun non-blocking I/O.
--
Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/
Why is this newsgroup different from all other newsgroups?
More information about the Python-list
mailing list