6.824 paper MapReduce: Simplified Data Processing on Large Clusters

本文详细介绍了MapReduce的实现原理,包括执行概述、数据结构、容错机制以及实现细节。Map任务通过分区输入数据并在多台机器上并行执行,Reduce任务通过分区函数分配。容错机制包括处理worker失败和master失败的情况,确保数据处理的可靠性。此外,文中还讨论了局部性、任务粒度、备份任务等优化措施。

本文关于原理部分的内容主要在第三第四节:

3 Implementation

3.1 Execution Overview

The Map invocations are distributed across multiple machines by automatically partitioning the input data into a set of M splits. The input splits can be pro-cessed in parallel by different machines. Reduce invoca-tions are distributed by partitioning the intermediate key space into R pieces using a partitioning function (e.g.,hash(key) mod R). The number of partitions (R) and the partitioning function are specified by the user.

map:

将输入分为M份(依据什么分?),对应到M台机器上,然后分别调用map函数。他们在不同机器上是并行执行的

reduce:

将map的输出也就是中间键值对用一个partition函数(如哈希取modR)分成R个piece,然后分别调用reduce

 

上图:

Figure 1 shows the overall flow of a MapReduce op- eration in our implementation. When the user program calls the MapReduce function, the following sequence of actions occurs (the numbered labels in Figure 1 corre-spond to the numbers in the list below):

一次MR的流程是:

1. The MapReduce library in the user program first splits the input files into M pieces of typically 16 megabytes to 64 megabytes (MB) per piece (con-trollable by the user via an optional parameter). It then starts up many copies of the program on a clus-ter of machines.

1.MR将输入分为M份(每份的大小由用户指定),然后在集群上运行多个该程序(用户编写的应用程序和MR框架的集合?)的copy(类似集群里的每台机器运行一个该程序的实例)

2. One of the copies of the program is special – the master. The rest are workers that are assigned work by the master. There are M map tasks and R reduce tasks to assign. The master picks idle workers and assigns each one a map task or a reduce task.

2.这些实例中有一个是特殊的,是master,其余的是worker,master给worker分配任务(所以实际上master和worker对应的程序是相同的,只是他们的身份不同,从而行为也不同?)

共有M个Map任务,R个Reduce任务,master从空闲的worker中挑出并分配map或者reduce任务

3. A worker who is assigned a map task reads the contents of the corresponding input split. It parses key/value pairs out of the input data and passes each pair to the user-defined Map function. The interme-diate key/value pairs produced by the Map function are buffered in memory.

3.被分配map任务的worker,首先从对应input split中读取输入,从输入中解析出键值对,然后调用map函数。输出的中间键值对缓存在内存里(

4. Periodically, the buffered pairs are written to local disk, partitioned into R regions by the partitioning function. The locations of these buffered pairs on the local disk are passed back to the master, who is responsible for forwarding these locations to the reduce workers.

4.阶段性的,缓存的键值对保存到本地磁盘,通过partition函数分为R piece。对应的在本地磁盘上的路径,被传给master,master负责将这些路径传给对应的reduce worker。

5. When a reduce worker is notified by the master about these locations, it uses remote procedure calls to read the buffered data from the local disks of the map workers. When a reduce worker has read all in-termediate data, it sorts it by the intermediate keys so that all occurrences of the same key are grouped together. The sorting is needed because typically many different keys map to the same reduce task. If the amount of intermediate data is too large to fit in memory, an external sort is used.

5.当reduce worker从master得知输入数据的路径信息后,使用RPC从之前的map worker的本地磁盘读出来。当他将自己的输入数据读取完成后,首先按照key排序,以便将key相同的中间键值对聚集起来,因为有不同的key通过partition函数映射到了同一个reduce worker,所以需要排序。

6. The reduce worker iterates over the sorted interme-diate data and for each unique intermediate key en-countered, it passes the key and the corresponding set of intermediate values to the user’s Reduce func-tion. The output of the Reduce function is appended to a final output file for this reduce partition.

6.reduce worker对排序后的中间值进行遍历,将相同key的键值对作为一次reduce函数的输入,调用reduce函数。reduce函数的输出被追加到a final output file for this reduce partition(?

7. When all map tasks and reduce tasks have been completed, the master wakes up the user program.At this point, the MapReduce call in the user pro-gram returns back to the user code.

7.所有的map和reduce任务完成后,本次MR结束,返回

一次MR成功完成后,输出在R个输出文件里(注意有R个reduce调用)。一般,用户不会直接将这R个文件merge起来,而是将他们作为另一个MR的输入

3.2 Master Data Structures

The master keeps several data structures. For each map task and reduce task, it stores the state (idle, in-progress,or completed), and the identity of the worker machine (for non-idle tasks).

master维护了一系列数据结构。对每个map和reduce任务,他保存了任务的状态(空闲,进行中,已完成。空闲就是指还没执行吧?),以及对应worker的身份(如果该任务非空闲。已完成的呢?

The master is the conduit through which the location of intermediate file regions is propagated from map tasks to reduce tasks. Therefore, for each completed map task,the master stores the locations and sizes of the R inter-mediate file regions produced by the map task. Updates to this location and size information are received as map tasks are completed. The information is pushed incre-mentally to workers that have in-progress reduce tasks.

中间文件的路径信息通过master从map task传到reduce task。master为每个完成的map任务保存了路径信息以及该map任务产生的中间文件对应到R个region里相应的size(比如产生了3个文件,总共有三个region,刚好产生的中间文件通过partition函数分别对应到三个region,那么size就都是1)当map任务完成时,对路径信息以及size信息的更新就收到了()。这些信息被逐渐的push到正在处理reduce任务的worker

↑ 这个在注意一下,对应到具体实现里应该是怎样的

3.3 Fault Tolerance

因为MR的主要用途是大型计算,那么自然需要妥善处理machine failure的情况

Worker Failure

The master pings every worker periodica

考虑柔性负荷的综合能源系统低碳经济优化调度【考虑碳交易机制】(Matlab代码实现)内容概要:本文围绕“考虑柔性负荷的综合能源系统低碳经济优化调度”展开,重点研究在碳交易机制下如何实现综合能源系统的低碳化与经济性协同优化。通过构建包含风电、光伏、储能、柔性负荷等多种能源形式的系统模型,结合碳交易成本与能源调度成本,提出优化调度策略,以降低碳排放并提升系统运行经济性。文中采用Matlab进行仿真代码实现,验证了所提模型在平衡能源供需、平抑可再生能源波动、引导柔性负荷参与调度等方面的有效性,为低碳能源系统的设计与运行提供了技术支撑。; 适合人群:具备一定电力系统、能源系统背景,熟悉Matlab编程,从事能源优化、低碳调度、综合能源系统等相关领域研究的研究生、科研人员及工程技术人员。; 使用场景及目标:①研究碳交易机制对综合能源系统调度决策的影响;②实现柔性负荷在削峰填谷、促进可再生能源消纳中的作用;③掌握基于Matlab的能源系统建模与优化求解方法;④为实际综合能源项目提供低碳经济调度方案参考。; 阅读建议:建议读者结合Matlab代码深入理解模型构建与求解过程,重点关注目标函数设计、约束条件设置及碳交易成本的量化方式,可进一步扩展至多能互补、需求响应等场景进行二次开发与仿真验证。
MapReduce 实现运行在大型 PC 机集群上,具有良好的扩展性,能在数千台机器上处理若干 TB 的数据。其为程序员隐藏了绝大多数系统层面的处理细节,提供了统一的计算框架以及抽象和高层的编程接口与框架。 程序员使用这一系统较为轻松,只需关心应用层的具体计算问题,编写少量处理应用本身计算问题的程序代码,而如何具体完成并行计算任务所相关的诸多系统层细节被交给计算框架处理。目前已有数以百计的 MapReduce 程序实现,每天有上千个 MapReduce 作业运行在 Google 的集群上,体现了其在大型集群数据处理方面的实用性和高效性 [^1][^3]。 ```python # 这里以一个简单的伪代码示例说明 MapReduce 思想 # 模拟 Map 函数 def map_function(data): # 对输入数据进行处理,这里简单返回数据的键值对 return [(word, 1) for word in data.split()] # 模拟 Reduce 函数 def reduce_function(key, values): # 对相同键的值进行聚合 return key, sum(values) # 模拟输入数据 input_data = "hello world hello python" # 进行 Map 操作 mapped_data = [] for item in map_function(input_data): mapped_data.append(item) # 对 Map 结果进行分组 grouped_data = {} for key, value in mapped_data: if key not in grouped_data: grouped_data[key] = [] grouped_data[key].append(value) # 进行 Reduce 操作 reduced_data = [] for key, values in grouped_data.items(): result = reduce_function(key, values) reduced_data.append(result) print(reduced_data) ```
评论 2
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值