【发布时间】:2021-04-19 08:19:41
【问题描述】:
我们目前在 node 14 公共预览版中使用 Firebase Functions。
我们需要将函数的内存增加到 1Gb 以上。
documentation of Google Cloud functions 指定必须为最新的运行时设置 max_old_space_size,文档显示:
gcloud functions deploy envVarMemory \
--runtime nodejs12 \
--set-env-vars NODE_OPTIONS="--max_old_space_size=8Gi" \
--memory 8Gi \
--trigger-http
但是,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
我们可以看到该函数只有 1028Mb 的内存,而不是 4。
我们确实要求它使用 4Gb 进行部署:
functions
.runWith({ memory: '4GB', timeoutSeconds: 300 ,})
这里的关键是什么?
【问题讨论】:
标签: firebase google-cloud-functions