Member-only story
Graphical exploration of concurrency in Python
Part 3: Threading API requests with Python
A series exploring concurrency in Python to speed up data retrieval from remote APIs.
This article is part of a series: Graphical exploration of concurrency in Python. Part 1: Defining and timing an API function in Python
Recap: Sequential vs. Multiprocessing

Sequential
Each request waited for the previous one to finish. The total time to complete 27 requests was 31.4 seconds and the CPU was only working ~2% of the time.

Multiprocessing
We retrieved the first set of query results. From there we constructed a list of tuples, corresponding to the arguments of jira_query
and passed that into multiprocessing.Pool().starmap()
. This spun up 12 processes that worked in parallel and collected the results at the end. It took about 2.1 seconds to start up 12 processes (the gap in the chart above), but even with that delay, we finished all 27 requests in 7.3 seconds, less than a quarter of the time it took…