may*_*vat 7 node.js google-bigquery google-cloud-platform google-cloud-run
我正在从 BigQuery 读取 1000 万条记录并进行一些转换并创建 .csv 文件,与我使用 Node.JS 上传到 SFTP 服务器的 .csv 流数据相同。
此作业大约需要 5 到 6 小时才能在本地完成请求。
解决方案已在 GCP Cloud run 上部署,但在 2 到 3 秒后,cloud run 关闭容器并出现 503 错误。
请在下面找到 GCP Cloud Run 的配置。
自动缩放:最多 1 个容器实例 CPU 分配:默认内存分配:2Gi 并发:10 请求超时:900 秒
GCP Cloud Run 是长时间运行的后台进程的好选择吗?
您可以使用部署了容器的 VM 实例并在其上执行您的工作。最后杀死或停止你的虚拟机。
但是,就我个人而言,我更喜欢无服务器解决方案和方法,例如 Cloud Run。但是,Cloud Run 上的长期运行工作终有一天会到来!在此之前,您必须处理 60 分钟的限制或使用其他服务。
作为解决方法,我建议您使用 Cloud Build。是的,Cloud Build 用于在其中运行任何容器。我写了一篇关于这个的文章。我在 Cloud Build 上运行了一个 Terraform 容器,但实际上,您可以运行任何容器。
正确设置超时,注意默认服务帐户和分配的角色,以及 Cloud Run 上尚不可用的内容,选择CPU 数量(1、8 或 32)进行处理并加速您的进程。
想要奖金?您每天和每个结算帐户有120 分钟的免费时间(注意,不是每个项目!)
更新:2021 年 10 月
Cloudrun 支持后台活动。
Configure CPU to be always-allocated if you use background activities
Background activity is anything that happens after your HTTP response has been delivered. To determine whether there is background activity in your service that is not readily apparent, check your logs for anything that is logged after the entry for the HTTP request.
Configure CPU to be always-allocated
If you want to support background activities in your Cloud Run service, set your Cloud Run service CPU to be always allocated so you can run background activities outside of requests and still have CPU access.
Run Code Online (Sandbox Code Playgroud)
您可以尝试使用通过Cloud Dataflow部署的 Apache Beam管道。使用 Python,您可以通过以下步骤执行该任务:
第 1 阶段:从 BigQuery 表中读取数据。
beam.io.Read(beam.io.BigQuerySource(query=your_query,use_standard_sql=True))
Run Code Online (Sandbox Code Playgroud)
第 2 阶段。将第 1 阶段结果上传到 GCS 存储桶上的 CSV 文件中。
beam.io.WriteToText(file_path_prefix="", \
file_name_suffix='.csv', \
header='list of csv file headers')
Run Code Online (Sandbox Code Playgroud)
第 3 阶段:调用 ParDo 函数,该函数将获取第 2 阶段中创建的 CSV 文件并将其上传到 SFTP 服务器。你可以参考这个链接。
| 归档时间: |
|
| 查看次数: |
5137 次 |
| 最近记录: |