MCPcopy Create free account
hub / github.com/BWbwchen/MapReduce / distributeWork

Method distributeWork

master/master.go:97–121  ·  view source on GitHub ↗
(files []string)

Source from the content-addressed store, hash-verified

95}
96
97func (ms *Master) distributeWork(files []string) {
98 log.Trace("[Master] Start distribute workload")
99 numWorkers := ms.totalWorkers
100 // Initialize MapTasks
101 ms.MapTasks = newMapTasks(numWorkers)
102
103 // Distribute work
104 // Count the total lines
105 for _, file := range files {
106 totalLine := lineNums(file)
107 baseWorkLoad := totalLine / numWorkers
108
109 from := 0
110 for i := 0; i < numWorkers; i++ {
111 workLoad := baseWorkLoad
112 if i < (totalLine % numWorkers) {
113 workLoad++
114 }
115
116 ms.MapTasks[i].addFile(file, from, from+workLoad)
117 from += workLoad
118 }
119 }
120 log.Trace("[Master] End distribute workload")
121}
122
123func (ms *Master) availableWorkers(num int) ([]*WorkerInfo, int) {
124 log.Info("[Master] Finding available workers to execute ", num, "/", len(ms.Workers))

Callers 1

StartMasterFunction · 0.80

Calls 3

newMapTasksFunction · 0.85
lineNumsFunction · 0.85
addFileMethod · 0.80

Tested by

no test coverage detected