All Articles

When is concurrency useful ?

Here follows what I wanted to highlight from the following article. Please give huge props to Jim Anderson for his wonderful work.

Anderson Jim, (2021), Speed Up Your Python Program With Concurrency. Real Python.

What is concurrency ?

The dictionary definition of concurrency is simultaneous occurrence. In Python, the things that are occurring simultaneously are called by different names (thread, task, process).

Python uses different words for the same concept. It turns out that threads, tasks, and processes are only the same if you view them from a high level. Once you start digging into the details, they all represent slightly different things.

When is Concurrency useful ?

Concurrency can make a big difference for two types of problems. These are generally called CPU-bound and I/O-bound.

I/O bound problems

I/O-bound problems cause your program to slow down because it frequently must wait for input/output (I/O) from some external resource. They arise frequently when your program is working with things that are much slower than your CPU.

io-bound

In the diagram above, the blue boxes show time when your program is doing work, and the red boxes are time spent waiting for an I/O operation to complete.

CPU bound problems

There are classes of programs that do significant computation without talking to the network or accessing a file. These are the CPU-bound programs, because the resource limiting the speed of your program is the CPU, not the network or the file system.

cpu-bound