nowol79 / data-processing

data processing tricks & tip
0 stars 0 forks source link

chapter4. #7

Open nowol79 opened 6 years ago

nowol79 commented 6 years ago

What Is MapReduce?

Now that we have spent quite a bit of time talking about how important YARN is to Hadoop, let us tell you a little secret: Hadoop did not begin with YARN. Hadoop began as HDFS and a very customized implementation of the first parallel processing framework, MapReduce.

That initial implementation was eventually refactored into the distributed management and scheduling part (YARN), and the processing part is still called MapReduce. That clean separation was introduced as part of the Hadoop 2 effort. 초기 MR 구현은 결국 분산 관리 및 스케줄링 부분(YARN)으로 리팩토링 되었으며, 처리 부분은 여전히 MapReduce라고 불린다.

image

This makes MapReduce the oldest parallel processing framework available on Hadoop. It is very simple to understand. MR은 Hadoop에서 사용할 수 있는 가장 오래된 병렬 처리 프레임 워크이다.

What Do Mappers and Reducers Do?

Mappers are the processes doing parallel computation of some sorts, just like your friends were counting quarters. Each Mapper produces a value or a stream of values that is then given to a Reducer (or Reducers), so that a Reducer can arrive at a final answer.

What Is A Mapper?

The Mapper reads data in the form of key-value pairs (KVPs), and it outputs zero or more KVPs. Mapper는 key-value 형태로 데이터를 읽고 0개 이상의 KVP를 출력한다. The Mapper may use or completely ignore the input key. Mapper는 입력키를 사용하거나 완전히 무시할 수 있다. For example, a standard pattern is to read a line of a file at a time: the key is the byte offset into the file at which the line starts; the value is the content of the line itself. Typically, the key is considered irrelevant with this pattern. 예를 들어, 표준 패턴은 한 번에 파일의 행을 읽는 것이다. key는 행이 시작되는 파일의 바이트 오프셋이다. 값은 행 자체의 내용이다.

If the Mapper writes anything out, it must do so in the form of KVPs. Mapper가 아무것도 쓰지 않는다면, KVP의 형태로 있게 된다. This stream of KVPs from a Mapper (intermediate data) is not stored in HDFS, but rather consumed over the network by one or more Reducers. Mapper의 KVP 스트림은 HDFS에 저장되지 않고 네트워크로 흘려서 하나 이상의 Reducers로 전달된다. The local attached storage on the nodes running Mappers is used to buffer data before it is being consumed by Reducers. Mappers를 실행하는 노드의 로컬 연결 스토리지는 Reducers가 데이터를 사용하지 전에 데이터를 버퍼링하는 데 사용된다.

MapReduce operates on a set of files (typically coming from HDFS) given to it as an input. MapReduce는 입력으로 주어진 일련의 파일(일반적으로 HDFS에서 제공)에서 작동한다. Based on the total number of blocks in that input data set, the MapReduce framework will calculate what is known as splits. MR 프레인 워크는 입력 데이터의 세트의 총 블록 수를 기반으로 스플릿이라고 알려진 것을 계산한다. Splits are contiguous slices of data given to a single Mapper to work on. Thus, the number of Mappers launched for a given MapReduce job equals the number of splits in the input data set. Splits는 하나의 Mapper가 작업할 인접한 데이터 조각이다. 따라서 주어진 MapReduce작업을 위해 시작된 매퍼의 수는 입력 데이터 세트의 스플릿 수와 같다.

The size of each split is typically the same as the HDFS block size. If you combine that with the "one Mapper per split" rule, you can see how MapReduce can ask YARN's scheduler to make sure that each Mapper is launched on the worker node where the block is physically stored. In fact, given that blocks are typically triple-replicated, there may be at least three worker nodes in a cluster where a Mapper for each split can be launched. 블럭이 실제로 3중 복제된다는 점을 감안할 때 각 분할에 대한 Mapper를 시작할 수 있는 클러스터에는 적어도 세 개의 작업자 노드가 있을 수 있다.

Keep in mind, though, that, while MapReduce tries very hard to make sure the processing happens on blocks stored on the same worker node where the Mapper is running, it is ok if a Mapper needs data that isn't locally available. MapReduce는 Mapper가 실행중인 동일한 작업자 노드에 저장된 블록에서 처리가 이루어 지도록 매우 열심히 노력하지만, Mapper가 로컬에서 사용할 수 없는 데이터를 필요로 하는 경우도 문제가 없습니다.

HDFS, being a distributed filesystem, makes that happen transparently to the Mapper. The only downside is the increased processing time, since the block has to travel over the network. 분산파일 시스템인 HDFS는 Mapper를 투명하게 동작시킵니다. (사용자는 블록이 로컬에 있는지 원격에 있는지 모릅니다.)하지만 블록이 네트워크를 통해 이동해야 하기 때문에 처리 시간이 증가한다는 단점은 있습니다.

Finally, even though the name of the framework is MapReduce, Mappers are the only mandatory part. 프레임워크 이림이 MapReduce이지만 Mappers가 유일한 필수 부분이다. To put it differently: it is very much possible to have a MapReduce job that only has Mappers and doesn't do any shuffling or use Reducers. This type of job is called a Map-only job, and is typically used to run long-lasting, distributed services on Hadoop clusters that have nothing to do with data processing or employ a data processing model that simply can't be expressed naturally in a MapReduce paradigm.

What Is A Reducer?

After the Map phase is over, all the intermediate values for a given intermediate key are combined together into a list. Map 단계가 끝나면 주어진 중간 키의 모든 값이 하나의 목록으로 결합된다. This list is given to a Reducer. 목록은 Reducer로 전달된다. We may have a single Reducer, or multiple Reducers. 하나 혹은 여러개의 Reducer가 있을 수 있다. Unlike the number of Mappers (which is based on the number of input splits), the number of Reducers is governed by a configuration option, and is 1 by default. Mapper수와 달리 Reducer수는 configuration option에 달려 있다. 기본값인 1이다. One thing to keep in mind here is that the number of Reducers will determine the number of the final output files for the MapReduce job. Reducer의 수가 MapReduce작업의 최종 출력 파일 수를 결정한다.

That is, if you have 10 Reducers, you will have 10 files in the output directory, each of which contain part of your results. Those 10 files will have to be concatenated in order to like an output of a single Reducer. In fact, this is such a common operation, that HDFS provides a command line option as a short hand to concatenate files in HDFS into the local destination file. We will use this option in Chapter 5.

All values associated with a particular intermediate key are guaranteed to go to the same Reducers. The intermediate keys, as well as their value lists, are passed in a sorted order. 특정 중간 key와 관련된 모든 값은 동일한 Reducer로 전달된다. 중간 값 Key-Value 목록은 정렬된 순서로 전달된다.

The invisible MapReduce phase that makes sure the Reducer gets the keys in a sorted order is called a Shuffle phase. Reducer가 정렬 된 순서로 Key를 가져오는 보이지 않는 MapReduce 단계를 Suffle 이라고 한다. The Reducer outputs zero or more KVPs. Reducer는 0개 이상의 KVP출력한다. KVP는 HDFS에 쓰인다. These KVPs are written to HDFS. In practice, the Reducer often emits a single KVP for each input key.