在节点 14 运行时上部署 Firebase 函数并增加内存

Cle*_*vos 6 firebase google-cloud-functions

我们目前正在使用 Firebase Functions 和 Node 14 公共预览版。

我们需要将函数的内存增加到 1Gb 以上。

Google Cloud 函数的文档指定必须为最新运行时设置 max_old_space_size,文档显示:

gcloud functions deploy envVarMemory \
--runtime nodejs12 \
--set-env-vars NODE_OPTIONS="--max_old_space_size=8Gi" \
--memory 8Gi \
--trigger-http
Run Code Online (Sandbox Code Playgroud)

但是,该set-env-vars选项不存在于firebase deploy

使用 firebase deploy --only functions:myFunction --set-env-vars NODE_OPTIONS="--max_old_space_size=4Gi"会产生error: unknown option '--set-env-vars'错误。

在部署繁重的功能时,我从逻辑上得到了堆内存不足错误:

[1:0x29c51e07b7a0]   120101 ms: Mark-sweep (reduce) 1017.1 (1028.5) -> 1016.2 (1028.7) MB, 928.7 / 0.1 ms  (average mu = 0.207, current mu = 0.209) allocation failure scavenge might not succeed 
[1:0x29c51e07b7a0]   119169 ms: Scavenge (reduce) 1016.9 (1025.2) -> 1016.2 (1026.5) MB, 3.6 / 0.0 ms  (average mu = 0.205, current mu = 0.191) allocation failure  
Run Code Online (Sandbox Code Playgroud)

我们可以看到该函数只有 1028Mb 的 ram,而不是 4。

我们确实要求它使用 4Gb 进行部署:

functions
    .runWith({ memory: '4GB', timeoutSeconds: 300 ,})
Run Code Online (Sandbox Code Playgroud)

这里的关键是什么?

Vin*_*tro 12

我们有完全相同的问题。当使用节点 12 或更多部署功能时似乎会发生这种情况。

这是解决这个问题的解决方案:

  1. 在 GCP 网络应用上查找您的函数
  2. 点击“编辑”
  3. 向下滚动并找到“运行时环境变量”
  4. 添加键 NODE_OPTIONS ,其值: --max_old_space_size=4096

这是设置的图片:

在此输入图像描述

这真的很烦人,我在命令行部署时没有找到任何解决方案来设置此设置。