Cloud Functions 版本比较
使用集合让一切井井有条
根据您的偏好保存内容并对其进行分类。
Cloud Functions for Firebase 有两个版本:
- Cloud Functions(第 2 代):它会将您的函数作为服务部署到 Cloud Run 上,使您可以使用 Eventarc 和 Pub/Sub 触发它们。
- Cloud Functions(第 1 代):函数的原始版本,具有有限的事件触发器和可配置性。
我们建议您尽可能为新函数选择使用 Cloud Functions(第 2 代)。尽管如此,我们还是计划继续对 Cloud Functions(第 1 代)提供支持。
本页面介绍了 Cloud Functions 中引入的功能,并比较了两个产品版本。
Cloud Functions(第 2 代)
Cloud Functions 是 Firebase 中推出的新一代函数即服务产品。基于 Cloud Run 和 Eventarc 构建的 Cloud Functions(第 2 代),为 Cloud Functions 带来了增强的基础架构和更广泛的事件覆盖范围,包括:
- 基于 Cloud Run 构建:函数使用 Cloud Build 进行构建,并以默认的 Cloud Run 执行环境部署为 Cloud Run 服务。这样一来,您就可以像自定义 Cloud Run 服务一样自定义函数。请参阅 Cloud Run 文档,了解配置服务的选项,例如内存限制、环境变量等。
- 请求处理时间更长:可以运行请求时间更长的工作负载,例如处理来自 Cloud Storage 或 BigQuery 的大量数据流。
- 实例规模更大:可以运行更大规模的计算密集型内存中并行工作负载。
- 改进了并发性能:可以通过单个函数实例处理多个并发请求,最大限度地减少冷启动次数并缩短延迟时间。
- 流量管理:可以在不同的函数修订版本之间拆分流量,或将函数回滚到先前版本。
- Eventarc 集成:原生支持 Eventarc 触发器,将 Eventarc 支持的全部 90 多个事件源引入 Cloud Functions。
- CloudEvents 支持更广泛:所有语言运行时都支持业界标准 CloudEvents,从而提供一致的开发者体验。
如需了解详情,请参阅对照表。
由于 Cloud Functions 会将函数作为服务部署到 Cloud Run,因此 Cloud Functions 与 Cloud Run 共享资源配额和限制。请参阅配额。
对照表
功能 |
Cloud Functions(第 1 代) |
Cloud Functions |
映像注册表 |
Container Registry 或 Artifact Registry |
仅限 Artifact Registry |
请求超时 |
最长 9 分钟 |
- 对于 HTTP 触发的函数,最长 60 分钟
- 对于事件触发的函数,最长 9 分钟
|
服务账号* |
Google App Engine 服务账号 (PROJECT_ID@appspot.gserviceaccount.com) |
Google Cloud 默认计算服务账号 (PROJECT_NUMBER-compute@developer.gserviceaccount.com) |
实例大小 |
最多搭载 2 个 vCPU,提供最高 8GB 的 RAM |
最多搭载 4 个 vCPU,提供最高 16GiB 的 RAM |
并发 |
每个函数实例 1 个并发请求 |
每个函数实例最多 1000 个并发请求 |
* 这是从正在运行的函数访问 Firebase 或 Cloud API 所使用的默认服务账号。当您不带任何实参进行初始化时,Firebase Admin SDK 会使用该服务账号。
价格
如需了解价格信息,请参阅 Firebase 定价方案。
您可以按以下方式查看与 Cloud Functions 关联的费用:
- 前往 Google Cloud 控制台中的 Cloud Billing 报告页面。
- 如果出现提示,请选择与您的 Google Cloud 项目关联的结算账号。
- 在过滤条件面板的标签下,添加标签过滤条件,将键设为
goog-managed-by
,值设为 cloudfunctions
。
限制
Cloud Functions for Firebase(第 2 代)不支持 Analytics 事件。
虽然 Cloud Functions for Firebase(第 2 代)支持身份验证屏蔽事件,但它不支持与第 1 代相同的一组基本 Authentication 事件。
但是,由于第 1 代和第 2 代函数可以在同一源文件中共存,因此您仍然可以将第 1 代中的 Analytics 和基本 Authentication 触发器与第 2 代函数一起开发和部署。
如未另行说明,那么本页面中的内容已根据知识共享署名 4.0 许可获得了许可,并且代码示例已根据 Apache 2.0 许可获得了许可。有关详情,请参阅 Google 开发者网站政策。Java 是 Oracle 和/或其关联公司的注册商标。
最后更新时间 (UTC):2025-08-17。
[null,null,["最后更新时间 (UTC):2025-08-17。"],[],[],null,["\u003cbr /\u003e\n\nThere are two versions of Cloud Functions for Firebase:\n\n- **Cloud Functions (2nd gen)** , which deploys your functions as services on Cloud Run, allowing you to trigger them using Eventarc and Pub/Sub.\n- **Cloud Functions (1st gen)**, the original version of functions with limited event triggers and configurability.\n\nWe recommend that you choose Cloud Functions (2nd gen) for new functions\nwherever possible. However, we plan to continue supporting Cloud Functions\n(1st gen).\n\nThis page describes features introduced in Cloud Functions and\nprovides a comparison between the two product versions.\n\nCloud Functions (2nd gen)\n\nCloud Functions is Firebase's next-generation\nFunctions-as-a-Service offering. Built on Cloud Run and\nEventarc, Cloud Functions (2nd gen) brings enhanced\ninfrastructure and broader event coverage to Cloud Functions, including:\n\n- **Built on Cloud Run** : Functions are built with Cloud Build and deployed as Cloud Run services using the default [Cloud Run execution environment](//cloud.google.com/run/docs/about-execution-environments). This gives you the ability to customize your function as you would a Cloud Run service. Refer to Cloud Run documentation to explore options for configuring your service, such as [memory\n limits](//cloud.google.com/run/docs/configuring/services/memory-limits), [environment variables](//cloud.google.com/run/docs/configuring/services/environment-variables), and so forth.\n- **Longer request processing times** : Run longer-request workloads such as processing large streams of data from Cloud Storage or BigQuery.\n- **Larger instance sizes**: Run larger in-memory, compute-intensive, and parallel workloads.\n- **Improved concurrency**: Handle multiple concurrent requests with a single function instance to minimize cold starts and improve latency.\n- **Traffic management**: Split traffic between different function revisions or roll a function back to a prior version.\n- **Eventarc integration** : Native support for Eventarc triggers, bringing all 90+ event sources supported by Eventarc to Cloud Functions.\n- **Broader CloudEvents support** : Support for industry-standard [CloudEvents](https://cloudevents.io/) in all language runtimes, providing a consistent developer experience.\n\nSee the [comparison table](#comparison-table) for details.\n\nBecause Cloud Functions deploys functions as services on Cloud Run,\nCloud Functions shares resource quotas and limits with\nCloud Run. See [Quotas](/docs/functions/quotas).\n\nComparison table\n\n| Feature | Cloud Functions (1st gen) | Cloud Functions |\n|-------------------|------------------------------------------------------------------------------------------------------|-------------------------------------------------------------------------------------------------------------------------------|\n| Image registry | Container Registry or Artifact Registry | Artifact Registry only |\n| Request timeout | Up to 9 minutes | - Up to 60 minutes for HTTP-triggered functions - Up to 9 minutes for event-triggered functions |\n| Service account\\* | Google App Engine service account (\u003cvar translate=\"no\"\u003ePROJECT_ID\u003c/var\u003e@appspot.gserviceaccount.com) | Google Cloud default compute service account (\u003cvar translate=\"no\"\u003ePROJECT_NUMBER\u003c/var\u003e-compute@developer.gserviceaccount.com) |\n| Instance size | Up to 8GB RAM with 2 vCPU | Up to 16GiB RAM with 4 vCPU |\n| Concurrency | 1 concurrent request per function instance | Up to 1000 concurrent requests per function instance |\n\n\\* This is the default service account used to access Firebase or Cloud APIs\nfrom a running function. It is used by the Firebase Admin SDK when you\n[initialize without arguments](/docs/admin/setup#initialize-sdk).\n\nPricing\n\nFor pricing information, see [Firebase pricing plans](https://firebase.google.com/pricing#cloud-functions).\n\nYou can view your costs associated with Cloud Functions as follows:\n\n1. Go to the [Cloud Billing Reports page](https://console.cloud.google.com/billing/reports) in the Google Cloud console.\n2. If prompted, select the billing account associated with your Google Cloud project.\n3. In the **Filters** panel, under **Labels** , [add a label filter](//cloud.google.com//billing/docs/how-to/reports#filters) with the key `goog-managed-by` and the value `cloudfunctions`.\n\n| **Note:** If you are using Cloud Functions for Firebase (1st gen) and are interested in Cloud Functions, see [Upgrade 1st gen Node.js functions to 2nd gen](/docs/functions/2nd-gen-upgrade).\n\nLimitations\n\nCloud Functions for Firebase (2nd gen) does not provide support for Analytics\nevents.\n\nThough Cloud Functions for Firebase (2nd gen) supports authentication blocking\nevents, it does not support the same set of basic Authentication events as\n1st gen.\n\nHowever, because 1st gen and 2nd gen\nfunctions can coexist side-by-side in the same source file, you can still\ndevelop and deploy Analytics and basic Authentication triggers in 1st gen\ntogether with 2nd gen functions."]]