Threads vs subprocesses

Prasad, Ramit ramit.prasad at jpmorgan.com
Fri Jun 15 14:22:40 EDT 2012


> > > My question is, on a single core machine, what are the pros and cons of
> > > threads vs subprocesses in a setup like this?
> > >
> [...]
> >
> > Two key phrases in your message;   CPU-intensive,
> > single-core-machine.  If these have the conventional meaning, you're
> > better off doing all the processing in your main executable, without
> > threads at all.
> >
> > Neither threads nor separate process speed up CPU-intensive execution on
> > a single-core machine.
> [...]
> 
> I should have made it clear that I'm not using threads to speed anything
> up;
> each thread produces an independently controlled, timed stream of musical
> events. I think it would be hard to achieve that in a single process. The
> streams need to run simultaneously without getting out of sync or dropping
> notes, which begins to happen if there are a lot of them, or they are run
> very
> fast or are very calculation-intensive to produce.
> 
> So I guess what I'm really asking is, given that I need to use threads or
> subprocesses, which approach slows the processing down the least?

Threads to do not really run simultaneously (in CPython) and without 
multiple CPUs/HT neither do subprocesses. Your machine might be fast 
enough to *look* like they are but they are not. Technically they might 
be running "simultaneously" but the CPU will have to keep switching from 
one calculation to another which just slows all of the calculations down. 
I would imagine the fastest way to proceed would be to iteratively do 
the calculations; thread and subprocess creation have their own 
memory/CPU overheads. 

In summary a single process/thread on a single core machine would 
be fastest.

Ramit


Ramit Prasad | JPMorgan Chase Investment Bank | Currencies Technology
712 Main Street | Houston, TX 77002
work phone: 713 - 216 - 5423

--

This email is confidential and subject to important disclaimers and
conditions including on offers for the purchase or sale of
securities, accuracy and completeness of information, viruses,
confidentiality, legal privilege, and legal entity disclaimers,
available at http://www.jpmorgan.com/pages/disclosures/email.  



More information about the Python-list mailing list