相关疑难解决方法(0)

以编程方式将数据批量加载到HBase的最快方法是什么?

我有一个纯文本文件,可能有数百万行需要自定义解析,我想尽快加载到HBase表中(使用Hadoop或HBase Java客户端).

我目前的解决方案是基于没有Reduce部分的MapReduce作业.我FileInputFormat用来读取文本文件,以便每行传递给map我的Mapper类的方法.此时,该行被解析以形成一个Put写入的对象context.然后,TableOutputFormat获取Put对象并将其插入表中.

该解决方案产生的平均插入速率为每秒1,000行,低于我的预期.我的HBase设置在单个服务器上处于伪分布式模式.

一个有趣的事情是,在插入1,000,000行时,会产生25个Mappers(任务),但它们会连续运行(一个接一个); 这是正常的吗?

这是我当前解决方案的代码:

public static class CustomMap extends Mapper<LongWritable, Text, ImmutableBytesWritable, Put> {

    protected void map(LongWritable key, Text value, Context context) throws IOException {
        Map<String, String> parsedLine = parseLine(value.toString());

        Put row = new Put(Bytes.toBytes(parsedLine.get(keys[1])));
        for (String currentKey : parsedLine.keySet()) {
            row.add(Bytes.toBytes(currentKey),Bytes.toBytes(currentKey),Bytes.toBytes(parsedLine.get(currentKey)));
        }

        try {
            context.write(new ImmutableBytesWritable(Bytes.toBytes(parsedLine.get(keys[1]))), row);
        } catch (InterruptedException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } …
Run Code Online (Sandbox Code Playgroud)

java hadoop hbase mapreduce

17
推荐指数
1
解决办法
2万
查看次数

标签 统计

hadoop ×1

hbase ×1

java ×1

mapreduce ×1