Hadoop实例RandomWriter

RandomWriter(随机写)例子利用 Map/Reduce把 数据随机的写到dfs中。每个map输入单个文件名,然后随机写BytesWritable的键和值到DFS顺序文件。map没有产生任何输出,所以reduce没有执行。产生的数据是可以配置的。配置变量如下

 

名字

默认值

描述

test.randomwriter.maps_per_host

10

Number of maps/host

test.randomwrite.bytes_per_map

1073741824

Number of bytes written/map

test.randomwrite.min_key

10

minimum size of the key in bytes

test.randomwrite.max_key

1000

maximum size of the key in bytes

test.randomwrite.min_value

0

minimum size of the value

test.randomwrite.max_value

20000

maximum size of the value

 

test.randomwriter.maps_per_host表示每个slave节点上运行map的次数。默认情况下,即只有一个数据节点,那么就有10个map,每个map的数据量为1G,因此要将10G数据写入到hdfs中。不过我配置的试验环境中只有2个slave节点,因此有两个map。

test.randomwrite.bytes_per_map我原本以为是随机写输出的测试文件的大小,默认为1G=1*1024*1024*1024,但是我将这个数据改成1*1024*1024以后,输出的测试文件还是1G,这让我很不解。(?)

代码实例

其中test.randomwrite.bytes_per_map=1*1024*1024,test.randomwriter.maps_per_host=1。

  1. /** 
  2.  * Licensed to the Apache Software Foundation (ASF) under one 
  3.  * or more contributor license agreements.  See the NOTICE file 
  4.  * distributed with this work for additional information 
  5.  * regarding copyright ownership.  The ASF licenses this file 
  6.  * to you under the Apache License, Version 2.0 (the 
  7.  * "License"); you may not use this file except in compliance 
  8.  * with the License.  You may obtain a copy of the License at 
  9.  * 
  10.  *     http://www.apache.org/licenses/LICENSE-2.0 
  11.  * 
  12.  * Unless required by applicable law or agreed to in writing, software 
  13.  * distributed under the License is distributed on an "AS IS" BASIS, 
  14.  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 
  15.  * See the License for the specific language governing permissions and 
  16.  * limitations under the License. 
  17.  */  
  18.   
  19. package org.apache.hadoop.examples;  
  20.   
  21. import java.io.IOException;  
  22. import java.util.Date;  
  23. import java.util.Random;  
  24.   
  25. import org.apache.hadoop.conf.Configuration;  
  26. import org.apache.hadoop.conf.Configured;  
  27. import org.apache.hadoop.fs.Path;  
  28. import org.apache.hadoop.io.BytesWritable;  
  29. import org.apache.hadoop.io.Text;  
  30. import org.apache.hadoop.io.Writable;  
  31. import org.apache.hadoop.io.WritableComparable;  
  32. import org.apache.hadoop.mapred.ClusterStatus;  
  33. import org.apache.hadoop.mapred.FileOutputFormat;  
  34. import org.apache.hadoop.mapred.FileSplit;  
  35. import org.apache.hadoop.mapred.InputFormat;  
  36. import org.apache.hadoop.mapred.InputSplit;  
  37. import org.apache.hadoop.mapred.JobClient;  
  38. import org.apache.hadoop.mapred.JobConf;  
  39. import org.apache.hadoop.mapred.MapReduceBase;  
  40. import org.apache.hadoop.mapred.Mapper;  
  41. import org.apache.hadoop.mapred.OutputCollector;  
  42. import org.apache.hadoop.mapred.RecordReader;  
  43. import org.apache.hadoop.mapred.Reporter;  
  44. import org.apache.hadoop.mapred.SequenceFileOutputFormat;  
  45. import org.apache.hadoop.mapred.lib.IdentityReducer;  
  46. import org.apache.hadoop.util.GenericOptionsParser;  
  47. import org.apache.hadoop.util.Tool;  
  48. import org.apache.hadoop.util.ToolRunner;  
  49.   
  50. /** 
  51.  * This program uses map/reduce to just run a distributed job where there is 
  52.  * no interaction between the tasks and each task write a large unsorted 
  53.  * random binary sequence file of BytesWritable. 
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值