MIT6.824食用过程

Lab1 MapReduce

一、介绍

本实验使用Go语言构建一个mapreduce库,以及一个容错的分布式系统。第一部分完成一个简单的mapreduce程序,第二部分写一个提交到mapreduce workers 的master 并且要能够处理workers 的错误。 库的接口和容错的方法跟mapreduce paper里面描述的类似。

二、环境搭建 vscode&&go

1. 安装golang

2. 安装git

3.安装cntlm

代理工具,用来给git 和 go 配置代理,下载文件。

git config --global http.proxy http:china\\username:password@proxy:8080

git config --global https.proxy https:china\\username:password@proxy:8080

测试: $ git clone https://github.com/dotcloud/docker.git 如果报错ssl certificate。。。

执行 $ git config --global http.sslVerify false

再执行git clone即可

4. 在vscode 里面下载go插件

三、实验说明

map/reduce实现支持两种操作模式:顺序执行、分布式执行。前者是指一次执行一个task,当所有的map task

执行完才轮到reduce task

程序源码在mapreduce 目录下

通过调用master.go来启动job,可以设置顺序执行和分布式执行

程序执行流程如下:

  • 输入包括:输入文件,map函数,reduce函数,reduce task的数量
  • 启动rpc server(master_rpc.go) 然后等待workers 注册 (master.go -> register)
  • schedule.go -> schedule()决定如何分配任务给workers 以及如何处理失败

3.1 第一部分 编写map/reduce 的输入和输出

$ cd src/mapreduce

$ go test -run Sequential

$ go test -v -run Sequential // debug mode (将common.go里面的debugEnabled改为true)

修改src/mapreduce 下的common_map.go 中的doMap() 函数和 common_reduce.go 中的doReduce() 函数

其中doMap() 函数实现:

  • 读取inputfile,根据reduce task 的个数(nReduce) 生成相应个数的中间文件
  • 命名格式为 mrtmp.[jobName]-[mapTasknum]-[reduceTasknum] 比如 mrtmp.test-0-0

duReduce()函数功能:

  • 读取doMap() 生成的中间文件
  • 并且将nMap个文件进行合并 排序 并且输出
  • 输出文件名为 mrtmp.[jobName]-res-[reduceTasknum] 比如: mrtmp.test-res-0

3.2 第二部分 实现MapFunc 和 ReduceFunc

实现src/main/wc.go 中的MapF() 和 ReduceF()

其中MapF(inputfile string, contents string) 功能:

  • inputfile 是输入的文件名 不用考虑

  • contents 为 inputfile 的内容,调用 strings.FieldsFunc 来完成分词功能

    • 代码如下:

    • words := strings.FieldsFunc(contents, func(c rune) bool {
      return !unicode.IsLetter(c)
      })
      var result = make([]mapreduce.KeyValue, 0)
      for _, w := range words {
      kv := mapreduce.KeyValue{w, "1"}
      result = append(result, kv)
      }
    • 示例

    • func main() {
      f := func(c rune) bool {
      return !unicode.IsLetter(c) && !unicode.IsNumber(c)
      }
      fmt.Printf("Fields are: %q", strings(" foo1;bar2,baz3...", f))
      }

ReduceF(key string, values []string)功能:

  • key 代表每一个键的内容

  • values 是key对应的 values列表

  • 实现:需要统计value的总数

  • count := strconv.Itoa(len(values))
    return count

3.3 分布式mapreduce任务

schedule() 函数通过读取registerChan 来获取workers集合

MIT6.824食用过程的更多相关文章

  1. Mit6.824 Lab1-MapReduce

    前言 Mit6.824 是我在学习一些分布式系统方面的知识的时候偶然看到的,然后就开始尝试跟课.不得不说,国外的课程难度是真的大,一周的时间居然要学一门 Go 语言,然后还要读论文,进而做MapRed ...

  2. MIT-6.824 MapReduce

    概述 MapReduce是由JeffreyDean提出的一种处理大数据的编程模型,用户定义map和reduce函数,map函数处理原始数据生成一系列键值对中间数据,reduce函数并合相同key的键值 ...

  3. 【MIT-6.824】Lab 1: MapReduce

    Lab 1链接:https://pdos.csail.mit.edu/6.824/labs/lab-1.html Part I: Map/Reduce input and output Part I需 ...

  4. MIT-6.824 Raft协议

    摘要 raft是一种比paxos容易理解的一致性算法,实现起来比paxos简单许多.本文前部分描述算法的细节,后部分尝试探讨下该算法的原理. 算法描述 raft算法之所以简单的原因之一是它将问题分解成 ...

  5. MIT-6.824 操作系统 汇总

    MIT-6.828-JOS-环境搭建 ELF文件格式 lab1:C, Assembly, Tools, and Bootstrapping lab2:Memory management lab3:Us ...

  6. MIT6.824 分布式系统实验

    LAB1 mapreduce mapreduce中包含了两个角色,coordinator和worker,其中,前者掌管任务的分发和回收,后者执行任务.mapreduce分为两个阶段,map阶段和red ...

  7. MIT-6.824 Lab 3: Fault-tolerant Key/Value Service

    概述 lab2中实现了raft协议,本lab将在raft之上实现一个可容错的k/v存储服务,第一部分是实现一个不带日志压缩的版本,第二部分是实现日志压缩.时间原因我只完成了第一部分. 设计思路 如上图 ...

  8. MIT 6.824 : Spring 2015 lab1 训练笔记

    源代码参见我的github: https://github.com/YaoZengzeng/MIT-6.824 Part I: Word count MapReduce操作实际上就是将一个输入文件拆分 ...

  9. MIT 6.824 : Spring 2015 lab3 训练笔记

    摘要: 源代码参见我的github:https://github.com/YaoZengzeng/MIT-6.824 Lab3: Paxos-based Key/Value Service Intro ...

随机推荐

  1. interior转换为interface

    在计算的过程中,我们想要将interior(内部面)转换为interface,操作如下:

  2. service mesh,linkerd,sidecar,apigateway

    对于大规模部署微服务(微服务数>1000).内部服务异构程度高(交互协议/开发语言类型>5)的场景,使用service mesh是合适的.但是,可能大部分开发者面临的微服务和内部架构异构复 ...

  3. Linux中的定时自动执行功能(at,crontab)

    Linux中的定时自动执行功能(at,crontab) 概念 在Linux系统中,提供了两种提前对工作进行安排的方式 at 只执行一次 crontab 周期性重复执行 通过对这两个工具的应用可以让我们 ...

  4. Windows平台上运行Tomcat

    从之前的学习中知道,可以调用Bootstrap类将Toomcat作为一个独立的应用程序来运行,在Windows平台上,可以调用startup.bat批处理文件来启动Tomcat,或运行shutdown ...

  5. JVM 初始化阶段例子 final常量

    1.创建FinalTest类,里面有一个final常量x class FinalTest{ public static final int x = 3; static { System.out.pri ...

  6. you are not allowed to push code to protected branches on this project(转)

    .. 图 1-1 报错:failed to push some refs to 'http://*******.git'. 一痛瞎踅摸之后,远程控制电脑,在H电脑上,重新建立了一个test项目,之后走 ...

  7. shell - 拉取代码部署执行

    #!/bin/bash nodejs_path=/data/myserver/yihao01-node-js cd /data/myserver if [ -d "$nodejs_path& ...

  8. Tosca user space 这是自己的空间,可以create module ,test case 等一大堆模块,五脏俱全

  9. Flutter -------- Http库 网络请求封装(HttpController)

    http库 再次封装的网络请求类 HttpController 1.添加依赖 dependencies: http: ^0.12.0 #latest version 2.导入库 import 'pac ...

  10. iptables 配置场景3

    iptables -I INPUT -i lo -j ACCEPT    #允许本地回环地址访问: iptables -I INPUT -m state --state ESTABLISHED,REL ...