threading

Chris Angelico rosuav at gmail.com
Mon Apr 7 10:27:04 EDT 2014


On Mon, Apr 7, 2014 at 11:49 PM, Marko Rauhamaa <marko at pacujo.net> wrote:
> Roy Smith <roy at panix.com>:
>
>> The idea that we should continue to use threading just because Windows
>> makes process creation hideously expensive compared to thread creation
>> doesn't impress me as an argument in favor of threading. It impresses
>> me as an argument in favor of ditching Windows.
>
> There are many reasons to start processes or threads. One of them is
> performance (you have more than one CPU core). When performance is the
> objective, my rough guidelines would be:
>
>  * Start your processes during initialization.
>
>  * Start about twice as many processes as there are CPUs.
>
> IOW, the processes are there to exercise the CPUs and should not
> represent individual connections or other dynamic entities.

That's potentially brutal on a shared system! I hope it's controlled
by an option, or that you do this only in something you're writing for
yourself alone.

There are other reasons for forking per connection, though, such as
state cleanup. You can guarantee that each job is done in a consistent
state if it's spawned from the exact same point in the master process
every time. That can help enormously if you're allowing any sort of
foreign code, even from a trusted programmer.

ChrisA



More information about the Python-list mailing list