【问题标题】:Bigtable bulkload using Dataflow is too slow使用 Dataflow 的 Bigtable 批量加载速度太慢
【发布时间】:2016-02-28 13:13:10
【问题描述】:

对于每 3 小时对 20GB 数据文件等模式进行批量加载到 Bigtable 的最佳方法是什么?数据流是正确的方式吗?

我们使用 Dataflow 批量加载 Bigtable 的问题是..

看起来 Dataflow QPS 与 Bigtable(5 个节点)的 QPS 不匹配。我正在尝试使用 Dataflow 将 20GB 文件加载到 bigtable。摄取到 bigtable 需要 4 小时。我也在运行过程中不断收到此警告..

{
  "code" : 429,
  "errors" : [ {
    "domain" : "global",
    "message" : "Request throttled due to project QPS limit being reached.",
    "reason" : "rateLimitExceeded"
  } ],
  "message" : "Request throttled due to project QPS limit being reached.",
  "status" : "RESOURCE_EXHAUSTED"
}.

代码:

// CloudBigtableOptions is one way to retrieve the options. It's not
// required.
CloudBigtableOptions options = PipelineOptionsFactory.fromArgs(btargs.toArray(new String[btargs.size()]))
    .withValidation().as(CloudBigtableOptions.class);

// CloudBigtableTableConfiguration contains the project, zone, cluster
// and table to connect to.
CloudBigtableTableConfiguration config = CloudBigtableTableConfiguration.fromCBTOptions(options);

Pipeline p = Pipeline.create(options);

// This sets up serialization for Puts and Deletes so that Dataflow can
// potentially move them through the network.
CloudBigtableIO.initializeForWrite(p);

p.apply(TextIO.Read.from(inpath)).apply(ParDo.of(new CreatePutsFn(columns, delim)))
    .apply(CloudBigtableIO.writeToTable(config));

p.run();

CreatePutsFn:

@Override
public void processElement(DoFn<String, Mutation>.ProcessContext c) throws Exception {
    String[] vals = c.element().split(this.delim);
    for (int i = 0; i < columns.length; i++) {
        if (i != keyPos && vals[i].trim() != "") {
            c.output(new Put(vals[keyPos].getBytes()).addColumn(FAMILY, Bytes.toBytes(columns[i].toLowerCase()),
                    Bytes.toBytes(vals[i])));
        }
    }
}

非常感谢这里的任何帮助。谢谢

【问题讨论】:

  • 欢迎来到 Stack Overflow!我正确地标记了一些你躺在那里并且不可读的代码。始终将代码放在代码标签内,以便正确格式化。
  • 感谢安德烈斯正确标记
  • 我认为情况正好相反——你使 Bigtable 集群饱和。您可以在导入期间临时增加 Bigtable 集群大小,然后在完成后减小大小。 (为了省钱)节点的数量是动态的。
  • 如果这不能解决问题,你有多少 Dataflow 节点/大小?
  • 下一个可能性 - 您的帐户/项目 ID 有多久了?您可能会遇到不同的限制 -- 看看:cloud.google.com/compute/docs/resource-quotas -- 您可能希望增加一些配额。

标签: google-cloud-dataflow google-cloud-bigtable


【解决方案1】:

我可以解决这个问题。我做了以下三件事来达到预期的结果。现在,该作业运行并在大约 15 分钟内为一个 (20 Gb) 文件提取数据......之前运行了 4-5 小时。

  1. 此作业使用 Data-flow 在 3 分钟内创建了 20 亿个 put 请求,现在通过批处理一行的所有列可以减少到 4000 万个请求。
    public void processElement(DoFn<String, Mutation>.ProcessContext c) throws Exception {
        String[] vals = c.element().split(this.delim);
        Put put = new Put(vals[keyPos].getBytes());
        for (int i = 0; i < columns.length; i++) {
            if (i != keyPos && vals[i].trim() != "") {
                put.addColumn(FAMILY, Bytes.toBytes(columns[i].toLowerCase()), Bytes.toBytes(vals[i]));

            }
        }
        c.output(put);
    }
  1. 我添加了客户端写入缓冲区的属性 config.toHBaseConfig().set("hbase.client.write.buffer", "200971520”);

  2. 关于 bigtable 达到 QPS 限制是对的。因此,在批量加载操作期间,我暂时将集群大小增加到 10 个节点(从 3 个节点)。

【讨论】:

  • 您可能也希望考虑使用 BufferedMutator。
  • @LesVogel-GoogleDevRel 不是 CloudBigtableIO.writeToTable(config) 在内部通过 CloudBigtableSingleTableWriteFn 执行 BufferedMutation 吗??
  • 你是对的——你所做的应该足够了。
  • @PraveenK — 听起来你已经解决了你的问题!您能否请accept your own answer 将此问题标记为已关闭?谢谢!
猜你喜欢
  • 1970-01-01
  • 2013-04-16
  • 1970-01-01
  • 2018-03-14
  • 2017-02-28
  • 2023-01-19
  • 1970-01-01
  • 2011-08-07
相关资源
最近更新 更多