Apache Beam管道未使用Python并行运行任务

我刚刚开始使用Python使用Apache Beam。我有一个希望并行运行的任务,但由于某种原因,它可以串行运行。有什么我完全误会的东西吗?

在下面的示例中,我希望RunInParallel同时执行。 DoFn需要2秒钟的处理时间,因此我希望下面的管道在2秒钟内完成。但是,这需要5秒钟2秒。

import apache_beam as beam
import time
from apache_beam.options.pipeline_options import PipelineOptions


class RunInParallel(beam.DoFn):

    def process(self,element,*args,**kwargs):
        time.sleep(2)
        return [int(time.time())]


p = beam.Pipeline(options=PipelineOptions())
(p
 | 'Create tasks' >> beam.Create([i for i in range(5)])
 | "Run task" >> beam.ParDo(RunInParallel())
 | "Print timestamp" >> beam.Map(print)
 )

# Run the pipeline
res = p.run()

上述管道的输出为

1573065709
1573065711
1573065713
1573065715
1573065717
canandasfu123 回答:Apache Beam管道未使用Python并行运行任务

暂时没有好的解决方案,如果你有好的解决方案,请发邮件至:iooj@foxmail.com
本文链接:https://www.f2er.com/3149663.html

大家都在问