Multiprocessor Python vs Eventlet

Based on my understanding, threads cannot be executed in parallel (they are executed depending on availability and randomness), and it is for this reason that Eventlet is used.

If Eventlets are more for parallelism, why can't we just use the Python multiprocessing module.

I thought about executing several process modules and use the join () method to check if the whole process is complete.

Can someone explain if I understood correctly?

+5
source share
1 answer

Based on my understanding, threads cannot run in parallel (performed depending on availability and randomness)

Correct

and it is for this reason that Eventlet is used.

Not so right. The Eventlet library is used to simplify non-blocking I / O programming. This does not actually add parallelism. Threading is still limited to one thread at a time due to the GIL. But it is used because it greatly simplifies the process of starting, planning, and managing IO-bound flows, especially those that do not need to interact with each other.

If Eventlets are more for parallelism

As I mentioned, this is not what they exist for.

why can't we just use the multiprocessor module of Python. I thought about executing several process modules and use the join () method to check if the whole process is complete.

Of course you can! And you will get the actual parallel execution with this approach. But you cannot achieve the same acceleration. The multiprocessing library is better suited for parallel tasks related to the processor, because these are those that require more frequent access to the interpreter. You can see an increase in runtime when using multiprocessing with tasks tied to IO, due to the overhead of running and managing multiple processes.


As with most optimization and runtime issues, trying and profiling is the surest way to ensure that you are using the β€œbest” option for your application. Although you may find that if you first write code to use Eventlets, try changing it to use regular threads or multiprocessing, you will need to write more boilerplate code just to control threads or processes, and the value of Eventlets should become more obvious.

0
source

Source: https://habr.com/ru/post/1232487/


All Articles