liveBook · Manning

MapReduce

As explained in Python Concurrency with asyncio

MapReduce is a distributed data-processing pattern that applies a mapping function to input partitions and combines the resulting intermediate values with a reduction function.

MapReduce processes a large dataset by partitioning it into smaller chunks, mapping each chunk to a partial result, then reducing those results into one answer. Parallel map operations can speed up sufficiently large CPU-bound workloads. section 6.4

A practical MapReduce workflow:

  • Partition the input into manageable chunks, such as individual lines of text. section 6.4.1
  • Map each chunk to a partial result, such as a dictionary of word frequencies. section 6.4.1
  • Reduce partial results by merging matching keys and combining their counts. section 6.4.1
  • Run independent map operations with multiprocessing and asyncio when the workload is CPU-bound. section 6.0

Counting words

For four text lines, mapping produces one frequency dictionary per line. Reducing merges those dictionaries into totals such as “I”: 5, “know”: 6, and “much”: 2. section 6.4.1

Figure 6.1 A large set of data is split into partitions, then a map function produces intermediate results. These intermediate results are combined into a result.
06-01

Visualizes partitions flowing through a map function into intermediate results and a combined result. section 6.4

How Python Concurrency with asyncio covers it

How deep it goes
Defines partitioning, mapping, and reduction through a word-count example, then applies the workflow to multiprocessing.
Examples
Uses customer feedback and literature word-frequency analysis, plus a four-line text example with dictionary merging.
What it assumes
Builds mapping and reduction from basic text processing while situating execution in multiprocessing and asyncio.
What you can do after
Apply it via multiprocessing and asyncio to split CPU-bound work into chunks and combine the results.
How it connects
Connects MapReduce with multiprocessing, process pools, asyncio, CPU-bound work, and parallel execution.

Also explained in

Compare how 6 books explain MapReduce →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Python Concurrency with asyncio. The section links point to the parts of the book it draws on.