使用 withTemplateCompatibility 的 BigQueryIO 读取性能

Ken*_*Ken 4 google-cloud-dataflow apache-beam

Apache Beam 2.1.0 存在从 BigQuery 读取的模板管道的错误,这意味着它们只能执行一次。更多详细信息请参见https://issues.apache.org/jira/browse/BEAM-2058

Beam 2.2.0 的发布已修复此问题,您现在可以使用withTemplateCompatibility选项从 BigQuery 读取数据,您的模板管道现在可以多次运行。

  pipeline
    .apply("Read rows from table."
         , BigQueryIO.readTableRows()
                     .withTemplateCompatibility()
                     .from("<your-table>")
                     .withoutValidation())
Run Code Online (Sandbox Code Playgroud)

这种实现似乎给 BigQueryIO 读取操作带来了巨大的性能成本,我现在的批处理管道在8-11 分钟内运行,现在始终需要45-50 分钟才能完成。两个管道之间的唯一区别是.withTemplateCompatibility()

我试图了解性能大幅下降的原因以及是否有任何方法可以改进它们。

谢谢。

解决方案:基于jkff的输入。

  pipeline
    .apply("Read rows from table."
         , BigQueryIO.readTableRows()
                     .withTemplateCompatibility()
                     .from("<your-table>")
                     .withoutValidation())
    .apply("Reshuffle",  Reshuffle.viaRandomKey())
Run Code Online (Sandbox Code Playgroud)

jkf*_*kff 6

我怀疑这是因为这样withTemplateCompatibility做的代价是禁用此读取步骤的动态重新平衡。

我预计只有当您读取少量或中等量的数据,但对其执行非常繁重的处理时,它才会产生重大影响。在这种情况下,请尝试Reshuffle.viaRandomKey()在您的BigQueryIO.read(). 它将实现数据的临时副本,但会更好地并行化下游处理。