带有二进制数据的 PubSub 主题到 BigQuery

PubSub topic with binary data to BigQuery

我希望有数千个传感器以 10FPS 的速度发送遥测数据,每帧大约 1KB 的 binary 数据,使用 IOT Core,这意味着我将通过 PubSub 获取它.我想将该数据传输到 BigQuery,不需要任何处理。

由于 Dataflow 没有能够处理二进制数据的模板,并且使用它似乎有点麻烦,我想尽量避免它并完全无服务器。

问题是,我最好的选择是什么?

我考虑过云 运行 服务 运行 一个快速应用程序来接受来自 PubSub 的数据,并使用全局变量在 ram 中累积大约 500 行,然后使用 BigQuery 的 insert() 方法(NodeJS 客户端)。

这有多合理?我会从积累中获益,还是应该将每个传入行插入到 bigquery?

流媒体摄取

如果您的要求是通过近乎实时的仪表板和查询来分析大量持续到达的数据,流式插入将是一个不错的选择。可以找到流式插入的配额和限制 here

由于您使用的是 Node.js 客户端库,因此请使用您已经提到的 BigQuery legacy streaming APIinsert() 方法。 insert() 方法一次流式传输一行,而不考虑行的累积。

对于新项目,建议使用 BigQuery Storage Write API,因为它比旧版 API 更便宜并且具有丰富的功能集。 BigQuery 存储写入 API 目前仅支持 JavaPythonGo(预览版)客户端库。

批量摄取

如果您的要求是加载不需要实时处理的大型、有界数据集,则更喜欢批量加载。 BigQuery 批量加载作业是免费的。您只需为存储和查询数据付费,无需为加载数据付费。请参阅批量加载作业的配额和限制 here. Some more key points on batch loading jobs have been quoted from this article

Load performance is best effort

  • Since the compute used for loading data is made available from a shared pool at no cost to the user, BigQuery does not make guarantees on performance and available capacity of this shared pool. This is governed by the fair scheduler allocating resources among load jobs that may be competing with loads from other users or projects. Quotas for load jobs are in place to minimize the impact.

Load jobs do not consume query capacity

  • Slots used for querying data are distinct from the slots used for ingestion. Hence, data ingestion does not impact query performance.

ACID semantics

  • For data loaded through the bq load command, queries will either reflect the presence of all or none of the data . Queries never scan partial data.