我开始使用谷歌云数据流,试图启动一个批处理数据处理管道,解析谷歌云存储中的数亿条记录,并将结果保存到BigQuery。查看文档,这个用例有一个完美的数据流模板GCS_Text_to_BigQuery。我使用Google提供的最新模板编译(gs://dataflow templates/latest/GCS_Text_to_BigQuery)启动了一项任务,性能相当好(使用n1-standard-16机器处理10-15分钟)
然而,该模板的编译是使用BigQuery的WRITE_TRUNCATE
写处理生成的,而不是所需的WRITE_APPEND
(4月13日,该Java模板在其GitHub存储库中更新了此更改,但其更新的编译尚未在官方GCS存储桶中)。为了使用带有所需更改的模板,我使用文档后面的以下命令编译了更新的代码:
mvn compile exec:java \
-Dexec.mainClass=com.google.cloud.teleport.templates.TextIOToBigQuery \
-Dexec.cleanupDaemonThreads=false \
-Dexec.args=" \
--project=<gcp-project-id> \
--stagingLocation=gs://<gcs-bucket>/staging \
--tempLocation=gs://<gcs-bucket>/temp \
--templateLocation=gs://<gcs-bucket>/templates/text-io-to-bq.json \
--runner=DataflowRunner"
在使用我自己编译的修改过的模板启动任务后,结果与使用Google提供的结果有很大不同:自动缩放似乎没有以正确的方式工作(任务期间工作人员的增加非常少,而且过程永远不会结束,此外工作人员的CPU消耗百分比非常低)。我使用python API启动任务,使用官方Google模板和我自己的模板使用完全相同的参数:
from googleapiclient.discovery import build
dataflow = build('dataflow', 'v1b3', cache_discovery=False)
# Compilation of template provided by Google (OK)
# dataflow_template = 'gs://dataflow-templates/latest/GCS_Text_to_BigQuery'
# Compilation of template build by me (NOK)
dataflow_template = 'gs://<gcs-bucket>/templates/text-io-to-bq.json'
parameters = {
'javascriptTextTransformFunctionName': '<udf-function>',
'JSONPath': 'gs://<gcs-bucket>/resources/schemas/<bq-schema-file>',
'javascriptTextTransformGcsPath': 'gs://<gcs-bucket>/resources/UDF/<udf-file>',
'inputFilePattern': 'gs://<gcs-bucket>/data/*',
'outputTable': '<gcp-project>:<bq-dataset>.<bq-table>',
'bigQueryLoadingTemporaryDirectory': 'gs://<gcs-bucket>/bq_temp_location/'
}
environment = {
'tempLocation': 'gs://<gcs-bucket>/temp',
'machineType': 'n1-standard-16'
}
request = dataflow.projects().locations().templates().launch(
projectId='<gcp-project-id>',
gcsPath=dataflow_template,
location='<location>',
body={
'jobName': '<job-name>',
'parameters': parameters,
'environment': environment
}
)
response = request.execute()
关于造成这种差异的原因有什么想法吗?非常感谢您的支持。提前谢谢
正如评论中所讨论的,您需要使用特定的
Java
版本来编译您自己的模板在GitHub repository中,我们可以看到正确的版本是
Java 8
和Maven 3
相关问题 更多 >
编程相关推荐