As we know that python threads can't
explore the true parallel processing because of GIL. So to achieve the
same we often use multiprocessing.
While using multiprocessing, one of the best practices is to pass the cpu affinity. It will be useful in below scenarios:
Example:
There
is a four core processor and we are running 4 python processes. So here
we can utilise all the four core available. Down side of not using cpu
affinity is that processor will keep scheduling the processes among
available core causing additional context switching overhead. Suppose we
have allocated different core to all the four processes resulting no
context switching and leading a better throughput.
Please be thoughtful when using the same, otherwise you could end up restricting the core for a given process.
Python code sample to demonstrate the cpu affinity
------------------------------ ------------------------------ ---------------
------------------------------
No comments:
Post a Comment