Question

As far as I know, in Python, if you used normal threading in a multi-core environment, GIL normally gets on the way and affects the performance in a negative way(because threads would be trying to acquire and release GIL constantly and doing a lot of context-switching between threads/processors).

That's why a lot of people starts using green threads, e.g. eventlet. The eventlet library allows you to have multiple green threads working together cooperatively and works perfectly in a single processor(less synchronisation issue, quick spawning/efficiency etc etc).

My question is that if I had a multi-core OS and were to design my python application, what's the best practice or design pattern I should follow to take advantages of both cooperative threading(green threads) and multi-core processors.

Was it helpful?

Solution

The very general approach, which I first saw in tech talk on Youtube growth [1] is this: identify and fix your bottlenecks, drink, sleep, etc, continue with bottlenecks again.

So, when you've got too much work and cores sit idle, well, run more processes. Using the same approach you'll know when to stop or even shrink process pool.

[1] https://www.youtube.com/watch?v=ZW5_eEKEC28

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top