是否可以根据文件数告诉使用的映射器/缩减器的数量?

Lea*_*ner 2 hadoop mapreduce cloudera

我想知道是否可以根据文件数告诉使用的映射器/缩减器的数量(默认情况下)?

我知道映射器的数量取决于块大小而不是实际文件大小,但是要确保我是否遗漏了任何东西.

例如:

如果hdfs中有4个目录,其中包含4个文件.

dir1/file1 - contains (testing file 1, testing again)
dir2/file2 - contains (testing file 2, testing again)
dir3/file3 - contains (testing file 3, testing again)
dir4/file4 - contains (testing file 4, testing again)
Run Code Online (Sandbox Code Playgroud)

有没有办法告诉我们将使用多少映射器和缩减器来处理上述四个文件?

dps*_*dce 6

Mapper的数量取决于拆分的数量,但是如果文件小于拆分大小,那么每个文件将对应一个映射器.这就是不推荐大量小文件的原因

确定属性以决定分割大小,默认值如下

  mapred.min.split.size=1 (in bytes)
  mapred.max.split.size=Long.MAX_VALUE
  dfs.block.size=64 MB
Run Code Online (Sandbox Code Playgroud)

分割大小计算为

   inputSplitSize=max(minimumSize, min(maximumSize, blockSize))

  # of mappers= totalInputSize/inputSplitSize
Run Code Online (Sandbox Code Playgroud)

减速器的数量取决于-D mapred.reduce.tasks =减速器参数的数量.Java API将尝试导出您需要的reducers数量,但同样您也可以显式设置它.在这两种情况下,每个节点可以运行的reducer数量有一个硬限制,并且使用mapred.tasktracker.reduce.tasks.maximum在mapred-site.xml配置文件中设置.

默认值

  mapred.reduce.tasks=1
  mapred.tasktracker.reduce.tasks.maximum=2
Run Code Online (Sandbox Code Playgroud)

这里有关于apache wiki上Mappers和reducers数量的一个很好的参考http://wiki.apache.org/hadoop/HowManyMapsAndReduces