如何在 Google Cloud Functions 和 Google App Engine 之间做出选择?

How to choose between Google Cloud Functions and Google App Engine?

Google Cloud Functions 似乎非常有趣,因为它是无服务器和零维护解决方案。但是,什么时候使用 Google Cloud Functions 而不是 Google App Engine 是合适的?

当您想要执行一个功能(某种逻辑)以响应源自云的事件并且您不想构建(并为此付费)一个完整的 Web 应用程序时那。

来自Product Overview

Cloud computing has made possible fully serverless models of computing where logic can be spun up on-demand in response to events originating from anywhere. Construct applications from bite-sized business logic billed to the nearest 100 milliseconds, only while your code is running. Serve users from zero to planet-scale, all without managing any infrastructure.

来自What are Google Cloud Functions?

Google Cloud Functions is a serverless execution environment for building and connecting cloud services. With Cloud Functions you write simple, single-purpose functions that are attached to events emitted from your cloud infrastructure and services. Your Cloud Function is triggered when an event being watched is fired. Your code executes in a fully managed environment. There is no need to provision any infrastructure or worry about managing any servers.

如果您已经有一个与要实现的逻辑相关的 GAE 应用程序,那么在应用程序中执行它可能会更简单:)

Update:
As of June 12, 2018, Node.js 8.x is supported in Google App Engine Standard environment along with the Flexible Environment.

简答:这取决于您的需要。

长答案:这是清单

运行时间
Cloud Functions 目前仅支持 Node.js,据我所知,没有任何计划在那里引入新的运行时。如果您擅长于此,则可以将 Cloud Functions 添加到您的选项中。

App Engine 确实支持 Node.js、,尽管它仅在灵活环境中可用。App Engine 标准环境支持 Python 2.7、Java 8、Java 7、PHP 5.5、Go 1.8 和 1.6,而 App Engine 柔性环境支持 Python、Java、Node.js、Go、Ruby、PHP 或 .NET。您还可以在 Flexible 环境中使用 dockerfile 提供自己的运行时。 因此,如果您想在 Node.js 以外的任何地方开发您的应用程序,App Engine 是更好的选择。

无服务器架构
您在寻找无服务器架构吗?您对管理实例并让它们按比例放大或缩小感到沮丧吗?您不想花时间管理您的服务器吗?如果您对所有这些问题的回答都是肯定的,请选择云功能。
您是否正在寻找 no 上的精细颗粒控制?实例和这些实例的计费。您想要单独的版本并希望更好地控制这些版本吗?在这种情况下寻找 App Engine。

微服务
你能把你的代码分解成更小的独立函数吗?使用云功能。
App Engine 确实支持使用相同代码库的微服务架构,但使用不同的 yaml 文件来拆分服务,但是是否要将它们分解为服务取决于您。在过去的几年里,我们 运行 将我们所有的代码都集成到一个单一的应用程序中,并且它在 App Engine 上仍然运行良好。

数据库
您的应用数据是否存储在 Firebase 中?然后可以在那里轻松使用云功能。如果没有,App Engine 是更好的选择。如果您想知道,App Engine 也可以连接到 Firebase。

还有其他一些事情需要考虑,例如定价,以及您是否希望迁移现有应用程序或是否要从头开始编写内容。事实上,您可以同时使用这两个选项。我们正在为我们的应用程序使用 App Engine (Python) 标准环境,但我们最近将一些长期 运行 任务迁移到云功能上,它们运行得非常好。

在我看来,App Engine 是大多数问题的答案,而 Cloud Functions 是针对特定需求而设计的。