[MIT 6.824 Distributed System] Lab 1: MapReduce (2016)

这篇博客详细介绍了MIT分布式系统课程的Lab 1,涉及MapReduce的实现,包括Map/Reduce的输入输出、单个worker的单词计数、分布式任务分配及处理worker故障的方法。博主分享了自己的实现过程,并讨论了如何处理中间文件、使用哈希进行数据分布以及在遇到worker失败时的策略。
摘要由CSDN通过智能技术生成

MIT分布式系统课程实验1:Lab 1: MapReduce

以下是我自己实现的版本,与大家分享一下,有问题欢迎提出,也希望各位指出错误!

common.go里面可以打开调试:

// Debugging enabled?
const debugEnabled = true

Overview

这里写图片描述

Part I: Map/Reduce input and output

第一部分主要是实现文件读写,读写内容当然就是key/value了。

假设,

  • M:Map的数目,也就是将数据集split成M份,分配给M个 Mappers 处理。如上图(3)read。
  • R: Reduce的数目,也即有R个Reducers,最后有R个输出文件。每个 Mapper 会将读入的key/value 数据写到R份中间文件中,也就是分配给R个Reducers。

  1. common_map.go
    我用了一个数组存放输出文件的指针,一次过读入输入文件,用mapF函数生成key/value。遍历key/value,将每个key/value哈希到不同的输出文件中。
// doMap does the job of a map worker: it reads one of the input files
// (inFile), calls the user-defined map function (mapF) for that file's
// contents, and partitions the output into nReduce intermediate files.
func doMap(
    jobName string, // the name of the MapReduce job
    mapTaskNumber int, // which map task this is
    inFile string,
    nReduce int, // the number of reduce task that will be run ("R" in the paper)
    mapF func(file string, contents string) []KeyValue,
) {
    // TODO:
    // You will need to write this function.
    // You can find the filename for this map task's input to reduce task number
    // r using reduceName(jobName, mapTaskNumber, r). The ihash function (given
    // below doMap) should be used to decide which file a given key belongs into.
    //
    // The intermediate output of a map task is stored in the file
    // system as multiple files whose name indicates which map task produced
    // them, as well as which reduce task they are for. Coming up with a
    // scheme for how to store the key/value pairs on disk can be tricky,
    // especially when taking into account that both keys and values could
    // contain newlines, quotes, and any other character you can think of.
    //
    // One format often used for serializing data to a byte stream that the
    // other end can correctly reconstruct is JSON. You are not required to
    // use JSON, but as the output of the reduce tasks *must* be JSON,
    // familiarizing yourself with it here may prove useful. You can write
    // out a data structure as a JSON string to a file using the commented
    
MIT 6.824 是麻省理工学院的一门高级课程,全称为 "Distributed Systems"(分布式系统),它通常会在计算机科学和工程领域中教授。这门课程深入探讨了分布式计算环境中的核心概念和技术,包括: 1. **分布式计算模型**:学习如何设计和实现分布式系统,如客户端-服务器、对等网络、云计算等架构。 2. **通信协议**:理解像TCP/IP、HTTP、UDP等基础通信协议在分布式系统中的作用以及它们如何确保数据的可靠传输。 3. **一致性模型**:研究不同的一致性级别,如强一致性、最终一致性,以及如何在分布式环境中维护数据一致性。 4. **分布式算法**:涉及分布式任务调度、数据分片、共识算法(如 Paxos、 raft 等)等,这些算法对于分布式系统的高效运作至关重要。 5. **安全性与隐私**:讨论如何保护分布式系统免受恶意攻击,如身份验证、授权、加密等安全措施。 6. **容错与可靠性**:处理节点故障的恢复策略,以及冗余和备份技术的重要性。 7. **大规模分布式系统案例**:可能涵盖云计算平台的设计、大规模数据库系统、分布式文件系统(如Hadoop)或分布式计算框架(如Spark)。 如果你想深入了解这门课程,可以考虑查找相关的课程资料、观看讲座视频,或者阅读经典的分布式系统教材,如《分布式系统:概念与设计》( Distributed Systems: Concepts and Design)。
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值