worker_machine_type 标签在 Google Cloud Dataflow 和 python 中不起作用

worker_machine_type tag not working in Google Cloud Dataflow with python

我在 Python 中使用 Apache Beam 和 Google Cloud Dataflow (2.3.0)。当指定 worker_machine_type 参数时,例如n1-highmem-2custom-1-6656,Dataflow 运行作业,但始终为每个工作器使用标准机器类型 n1-standard-1

如果我做错了什么,有人知道吗?

其他主题( and )显示这应该是可能的,所以这可能是版本问题。

我指定 PipelineOptions 的代码(请注意,所有其他选项都可以正常工作,因此它应该识别 worker_machine_type 参数):

def get_cloud_pipeline_options(project):

  options = {
    'runner': 'DataflowRunner',
    'job_name': ('converter-ml6-{}'.format(
        datetime.now().strftime('%Y%m%d%H%M%S'))),
    'staging_location': os.path.join(BUCKET, 'staging'),
    'temp_location': os.path.join(BUCKET, 'tmp'),
    'project': project,
    'region': 'europe-west1',
    'zone': 'europe-west1-d',
    'autoscaling_algorithm': 'THROUGHPUT_BASED',
    'save_main_session': True,
    'setup_file': './setup.py',
    'worker_machine_type': 'custom-1-6656',
    'max_num_workers': 3,
  }

  return beam.pipeline.PipelineOptions(flags=[], **options)

def main(argv=None):
  args = parse_arguments(sys.argv if argv is None else argv)

  pipeline_options = get_cloud_pipeline_options(args.project_id

  pipeline = beam.Pipeline(options=pipeline_options)

这可以通过使用标志 machine_type 而不是 worker_machine_type 来解决。其余代码工作正常。

因此 documentation 提到了错误的字段名称。

PipelineOptions 在幕后使用 argparse 来解析其参数。在机器类型的情况下,参数名称是 machine_type,但标志名称是 worker_machine_type。这在以下两种情况下工作正常,其中 argparse 进行解析并知道此别名:

  1. 在命令行上传递参数。例如my_pipeline.py --worker_machine_type custom-1-6656
  2. 将参数作为命令行标志传递,例如flags['--worker_machine_type', 'worker_machine_type custom-1-6656', ...]

但是它不适用于 **kwargs。以这种方式传递的任何其他参数都用于替换已知的参数名称(但不是标志名称)。

简而言之,使用 machine_type 无处不在。我已提交 https://issues.apache.org/jira/browse/BEAM-4112 以便将来在 Beam 中修复此问题。

在 Apache Beam 2.8.0 中对我有用的是通过将 --worker_machine_type 更改为 --machine_type(然后使用 machine_type 作为参数的名称,如其他答案中所建议的那样)。