将任务队列迁移到 Cloud Functions

Migrating Task Queues to Cloud Functions

我们正在使用 Google App Engine Standard Environment for our application. The runtime we are using is Python 2.7。我们有一个服务使用多个版本来部署应用程序。
为此,我们的大部分 运行 长任务都是通过 Task Queues. Most of those tasks do a lot of Cloud Datastore CRUD operations. Whenever we have to send the results back to the front end, we use Firebase Cloud Messaging 完成的。

我想尝试 Cloud Functions 完成这些任务,主要是为了利用无服务器架构。
所以我的问题是,如果我将任务从任务队列迁移到 Cloud Functions,我可以获得什么样的好处?是否有任何指导说明何时使用哪个选项?还是我们应该继续使用任务队列?

PS: 我知道把Python写的代码迁移到Node.js会很麻烦,暂时先不管了

除了无服务器的优势之外,如果管理执行并发性对您很重要,Cloud Functions 响应特定 events "glueing" elements of your architecture in a logical way. They are elastic and scale automatically - spinning up and down depending on the current demand (therefore they incur costs only when they are actually used). On the other hand Task Queues 是更好的选择:

Push queues dispatch requests at a reliable, steady rate. They guarantee reliable task execution. Because you can control the rate at which tasks are sent from the queue, you can control the workers' scaling behavior and hence your costs.

这对于 Cloud Functions 来说是不可能的,它一次只处理一个请求并且 运行 并行。任务队列是更好选择的另一件事是处理未成功操作的重试逻辑。

您还可以将 Cloud Functions 与 App Engine Cron 作业一起使用,以 运行 基于时间间隔而不是事件触发器的函数。

顺便说一下,Google 也在努力实现 Python 到 Cloud Functions。不知道什么时候准备好,但肯定会在 Google Cloud Platform Blog 中宣布。