Skip to main content
 首页 » 编程设计

python之使用 DirectRunner 时 Bigquery apache beam 管道 "hanging"

2024年08月16日36jackei

我很好奇这里是否还有其他人遇到过类似的 python apache beam 数据流运行器问题,如下所述。 (我现在还不能运送到 CloudRunner)

正在执行的查询返回不到 1800 万行。如果我添加一个 LIMIT 来查询(例如:10000),那么数据流会按预期工作。代码片段中未包含 WriteToBleve 接收器,它是支持写入 bleve 的自定义接收器。索引。

正在使用的 python sdk 是 2.2.0,但我正准备启动一些 java....

我在运行管道时看到的最后一条日志消息是:

WARNING:root:Dataset my-project:temp_dataset_7708fbe7e7694cd49b8b0de07af2470b does not exist so we will create it as temporary with location=None

数据集已正确创建并填充,当我调试到管道中时,我可以看到正在迭代的结果,但该管道本身似乎从未达到写入阶段。

    options = { 
        "project": "my-project", 
        "staging_location": "gs://my-project/staging", 
        "temp_location": "gs://my-project/temp", 
        "runner": "DirectRunner" 
    } 
    pipeline_options = beam.pipeline.PipelineOptions(flags=[], **options) 
    p = beam.Pipeline(options=pipeline_options) 
    p | 'Read From Bigquery' >> beam.io.Read(beam.io.BigQuerySource( 
        query=self.build_query(), 
        use_standard_sql=True, 
        validate=True, 
        flatten_results=False, 
    )) | 'Write to Bleve' >> WriteToBleve() 
 
    result = p.run() 
    result.wait_until_finish() 

请您参考如下方法:

直接运行器旨在用于本地调试和测试少量数据的管道。它没有针对性能进行特别优化,也不适合用于大量数据 - Python 和 Java 都是这种情况。

也就是说,目前对 Python 直接运行器进行了一些非常重要的改进 are in progress .

我建议您尝试在 Dataflow 上运行,看看性能是否仍然不尽如人意。

此外,如果您可以用 Java 编写 - 我建议这样做:它的性能通常比 Python 好几个数量级,尤其是在从 BigQuery 读取的情况下:读取 BigQuery 会通过 BigQuery 导出到 Avro 文件,并且性能用于读取 Avro 文件的标准 Python 库的名称是 notoriously horrible ,但不幸的是,目前没有性能良好且维护良好的替代品。