我应该使用 Google Cloud Function 还是 App Engine 来连接 Azure 认知服务并快速获得结果?

Should I use a Google Cloud Function or App Engine for connecting with Azure Cognetive Services and get fast results?

简介

我在我的 Google 云函数中使用 Azure Face API(每次调用我的函数时我都会发出大约 3 或 4 个 https 请求)但是我的执行时间非常慢, 5 秒。

Function execution took 5395 ms, finished with status: 'ok'

Function execution took 3957 ms, finished with status: 'ok

Function execution took 2512 ms, finished with status: 'ok

基本上我在云函数中所做的是:

1. Detect a face using Azure
2. Save the face in the Azure LargeFaceList
3. Find 20 similar faces using Azure
4. Train the updated Azure LargeFaceList (if it is not being trained already)

我的 Google Cloud Function 位于 us-central1('near' 我的 Azure Sace 服务,它位于 north-central-us)。我给它分配了 2GB 的内存和 540 秒的超时时间。我在欧洲。

问题

正如我之前所说,函数完成执行的时间太长(从 3.5 到 5 秒)。我不知道这是因为“冷启动”还是因为 运行 算法需要时间。

Pd: LargeFaceList目前只包含10张人脸(1000张人脸训练时间为1秒,100万张人脸训练时间为30分钟)。

我的选择

运行代码在:

  1- Google Cloud Function (doing this now)
  2- Google Cloud App Engine

我最近 3 个月一直在试用云功能,但我从未使用过 App Engine 服务。

我的问题

是否可以在 App Engine 上使用 firestore 触发器?如果我将此代码移至 App Engine,我的执行时间会更快吗?

使用 Cloud Functions,您只能在 1 个函数实例上处理一个请求。如果您有 2 个请求,Cloud Functions 会创建 2 个实例,每个实例仅在一个实例上处理。

因此,如果您有 180 个并发请求,您将同时拥有 180 个函数实例。 (最多 1000 个实例,默认配额)

Cloud 运行 运行 与 Cloud Functions 在同一底层基础设施上,但 运行 个容器。在 1 个云实例 运行 上,您最多可以同时处理 80 个请求。

因此,对于 180 个并发请求,您应该有 3 或 4 个实例,而不是像 Cloud Functions 那样的 180。而且由于您支付处理时间(CPU + 内存),180 个 Cloud Functions 实例比 3 个 Cloud 运行 服务更昂贵。

wrote an article on this.

总而言之,无服务器架构具有高度可扩展性,可以并行处理请求。只考虑一个请求的处理时间,而不是最大并发请求数。 (所以,这样做要有成本的角度)