MIT 6.5840 MapReduce — Distributed MapReduce Implementation (IMPORTANT - Readme file created with the help of CHATGPT, so it may contain mistakes)
This repository contains my implementation of the MapReduce lab from MIT 6.5840 (Distributed Systems).
The implementation consists of:
coordinator.go
worker.go
rpc.go
These files implement the distributed MapReduce Coordinator, Workers, and RPC communication.
The code is intended to be copied into the official MIT 6.5840 lab repository and tested using the provided MapReduce test suite.
The MIT lab asks us to implement a distributed MapReduce system consisting of:
- One Coordinator
- One or more Workers
- RPC communication between Workers and the Coordinator
- Map task scheduling
- Reduce task scheduling
- Worker failure detection and task re-assignment
The official lab specifies that the implementation should be placed in:
src/mr/coordinator.go
src/mr/worker.go
src/mr/rpc.go
The provided files:
src/main/mrcoordinator.go
src/main/mrworker.go
contain the main programs used to start the Coordinator and Workers and should not be modified.
Clone the official MIT 6.5840 2026 lab repository:
git clone git://g.csail.mit.edu/6.5840-golabs-2026 6.5840
cd 6.5840The repository has the following basic structure:
6.5840/
├── Makefile
└── src/
├── main/
├── mr/
└── mrapps/
This is the repository structure specified by the MIT lab.
This repository contains:
coordinator.go
worker.go
rpc.go
Copy these three files into the MIT repository's src/mr/ directory.
For example, if this repository is cloned alongside the MIT repository:
cd 6.5840/src/mr
cp /path/to/this/repository/coordinator.go .
cp /path/to/this/repository/worker.go .
cp /path/to/this/repository/rpc.go .Alternatively, clone this repository and copy the files directly:
cp /path/to/mapreduce-implementation/coordinator.go 6.5840/src/mr/
cp /path/to/mapreduce-implementation/worker.go 6.5840/src/mr/
cp /path/to/mapreduce-implementation/rpc.go 6.5840/src/mr/After copying, the relevant directory should look like:
6.5840/
└── src/
├── main/
│ ├── mrcoordinator.go
│ ├── mrworker.go
│ ├── mrsequential.go
│ └── ...
│
├── mr/
│ ├── coordinator.go <-- implementation
│ ├── worker.go <-- implementation
│ ├── rpc.go <-- implementation
│ ├── mr_test.go
│ └── ...
│
└── mrapps/
├── wc.go
├── indexer.go
├── crash.go
└── ...
Do not replace or modify src/main/mrcoordinator.go or src/main/mrworker.go.
The MIT lab provides a Word Count MapReduce application in:
src/mrapps/wc.go
Build it as a Go plugin:
cd 6.5840/src/main
go build -buildmode=plugin ../mrapps/wc.goThis generates:
wc.so
The official lab uses the same command to build the Word Count plugin.
From:
cd 6.5840/src/mainremove any previous output files:
rm mr-out*Then start the Coordinator:
go run mrcoordinator.go sock123 pg-*.txtHere:
sock123is the Unix socket used for Coordinator/Worker RPC.pg-*.txtare the input files.- Each input file corresponds to one Map task.
This is the execution flow specified by the MIT lab.
Open one or more additional terminals.
From:
cd 6.5840/src/mainstart a Worker:
go run mrworker.go wc.so sock123You can run multiple workers simultaneously.
For example:
cd 6.5840/src/main
go run mrcoordinator.go sock123 pg-*.txtcd 6.5840/src/main
go run mrworker.go wc.so sock123cd 6.5840/src/main
go run mrworker.go wc.so sock123cd 6.5840/src/main
go run mrworker.go wc.so sock123The MIT lab specifies that one or more Workers can run in parallel and communicate with the Coordinator through RPC.
After the Coordinator and Workers finish, the Reduce tasks produce:
mr-out-0
mr-out-1
mr-out-2
...
Check the generated files:
ls mr-out-*To inspect the complete result:
cat mr-out-* | sort | moreThe output should contain Word Count results such as:
A 509
ABOUT 2
ACT 8
ACTRESS 1
...
The official lab uses the sorted union of the mr-out-* files to verify the result.
The most important way to verify the implementation is to run the official tests.
From the src directory:
cd 6.5840/src
make mrThe MIT test suite is located in:
src/mr/mr_test.go
and tests:
- Word Count
- Indexer
- Map parallelism
- Reduce parallelism
- Job completion
- Early exit
- Worker crash recovery
These are the tests specified by the MIT lab.
A successful implementation should produce output similar to:
$ make mr
...
=== RUN TestWc
--- PASS: TestWc (...)
=== RUN TestIndexer
--- PASS: TestIndexer (...)
=== RUN TestMapParallel
--- PASS: TestMapParallel (...)
=== RUN TestReduceParallel
--- PASS: TestReduceParallel (...)
=== RUN TestJobCount
--- PASS: TestJobCount (...)
=== RUN TestEarlyExit
--- PASS: TestEarlyExit (...)
=== RUN TestCrashWorker
--- PASS: TestCrashWorker (...)
PASS
ok 6.5840/mr ...
The exact execution times and crash-recovery messages will vary between runs. The MIT-provided example shows all of these tests passing, including TestCrashWorker.
You can run an individual test using:
make RUN="-run Wc" mrFor example:
make RUN="-run TestWc" mrThis is useful when debugging a particular part of the implementation.
The MIT lab also notes that modifying files in src/mr/ may require rebuilding the MapReduce plugins.
The overall execution is:
+----------------+
| Coordinator |
+-------+--------+
|
RPC calls
|
+-------------+-------------+
| | |
v v v
+-------+ +-------+ +-------+
|Worker1| |Worker2| |Worker3|
+---+---+ +---+---+ +---+---+
| | |
v v v
Map Tasks Map Tasks Map Tasks
| | |
+-------------+-------------+
|
Intermediate Files
mr-X-Y
|
v
+---------------+
| Reduce Tasks |
+-------+-------+
|
v
mr-out-X
The Coordinator first schedules Map tasks. Reduce tasks can start after the Map phase has completed.
The Coordinator is expected to detect Workers that do not complete their tasks within a reasonable amount of time.
For this lab, the timeout is:
10 seconds
If a Worker fails while processing a task, the Coordinator should make that task available to another Worker.
The official tests specifically include:
TestCrashWorker
to verify this behavior.
The MIT lab also provides:
mrapps/crash.go
which can be used to test Worker crash recovery.
Map Workers create intermediate files using the convention:
mr-X-Y
where:
X= Map task numberY= Reduce task number
For example:
mr-0-0
mr-0-1
mr-1-0
mr-1-1
The Reduce Worker reads these intermediate files and produces:
mr-out-0
mr-out-1
...
The MIT lab specifies these naming conventions and requires each Reduce task to produce its corresponding mr-out-X file.
% make mr
go build -race -o main/mrsequential main/mrsequential.go
go build -race -o main/mrcoordinator main/mrcoordinator.go
go build -race -o main/mrworker main/mrworker.go&
(cd mrapps && go build -race -buildmode=plugin wc.go) || exit 1
(cd mrapps && go build -race -buildmode=plugin indexer.go) || exit 1
(cd mrapps && go build -race -buildmode=plugin mtiming.go) || exit 1
(cd mrapps && go build -race -buildmode=plugin rtiming.go) || exit 1
(cd mrapps && go build -race -buildmode=plugin jobcount.go) || exit 1
(cd mrapps && go build -race -buildmode=plugin early_exit.go) || exit 1
(cd mrapps && go build -race -buildmode=plugin crash.go) || exit 1
(cd mrapps && go build -race -buildmode=plugin nocrash.go) || exit 1
cd mr; go test -v -race
=== RUN TestWc
--- PASS: TestWc (6.97s)
=== RUN TestIndexer
--- PASS: TestIndexer (5.57s)
=== RUN TestMapParallel
--- PASS: TestMapParallel (8.09s)
=== RUN TestReduceParallel
--- PASS: TestReduceParallel (9.09s)
=== RUN TestJobCount
--- PASS: TestJobCount (11.11s)
=== RUN TestEarlyExit
--- PASS: TestEarlyExit (11.27s)
=== RUN TestCrashWorker
--- PASS: TestCrashWorker (27.32s)
PASS
ok 6.5840/mr 81.046s
Only these three files contain the implementation from this repository:
src/mr/coordinator.go
src/mr/worker.go
src/mr/rpc.go
The MIT repository provides the following components around the implementation:
src/main/mrcoordinator.go
src/main/mrworker.go
src/main/mrsequential.go
src/mrapps/wc.go
src/mrapps/indexer.go
src/mrapps/crash.go
src/mr/mr_test.go
The lab instructions specifically state that mrcoordinator.go and mrworker.go should not be changed.
The lab runs all Workers on the same machine and relies on them sharing the filesystem for intermediate Map output.
For someone who just wants to reproduce the result:
# 1. Clone MIT repository
git clone git://g.csail.mit.edu/6.5840-golabs-2026 6.5840
# 2. Copy implementation
cp coordinator.go 6.5840/src/mr/
cp worker.go 6.5840/src/mr/
cp rpc.go 6.5840/src/mr/
# 3. Build Word Count plugin
cd 6.5840/src/main
go build -buildmode=plugin ../mrapps/wc.go
# 4. Run Coordinator
rm mr-out*
go run mrcoordinator.go sock123 pg-*.txt
# 5. In another terminal, run Worker
go run mrworker.go wc.so sock123
# 6. Run official tests
cd ..
make mrFor the complete evaluation, use:
cd 6.5840/src
make mrThis implementation follows the structure and requirements of the MIT 6.5840 Distributed Systems MapReduce Lab.
The lab specification covers the Coordinator/Worker architecture, RPC communication, task scheduling, output conventions, testing, parallelism, and crash recovery.