Kir*_*ill 31 memory-management firebase google-cloud-functions
转换相对较小的图像(2mb)时,我不断从Cloud Functions for Firebase中得到零星的错误.如果成功,该功能只需要大约2000ms或更短的时间来完成,根据Image Magick文档,我不应该看到任何问题.
我尝试增加命令的缓冲区大小,这是Firebase中不允许的,我试图找到替代方案,.spawn()因为它可能会因为垃圾和速度慢而过载.什么都行不通.
p3s*_*3sn 43
我迷失在用户界面,找不到任何更改内存的选项,但终于找到了它:
问候,彼得
Mic*_*umo 23
您可以在Firebase上的Cloud Function文件中进行设置.
const runtimeOpts = {
timeoutSeconds: 300,
memory: '1GB'
}
exports.myStorageFunction = functions
.runWith(runtimeOpts)
.storage
.object()
.onFinalize((object) = > {
// do some complicated things that take a lot of memory and time
});
Run Code Online (Sandbox Code Playgroud)
从这里的文档中获取: https ://firebase.google.com/docs/functions/manage-functions#set_timeout_and_memory_allocation
不要忘记然后firebase deploy从您的终端运行.
Kir*_*ill 22
[更新]正如一位评论者建议的那样,这应该不再是一个问题,因为firebase功能现在可以在重新部署时保持其设置.谢谢firebase!
事实证明,这并不明显或记录在案,您可以在Google Functions Console中增加功能的内存分配.您还可以增加长时间运行功能的超时.它解决了内存过载的问题,现在一切都很好.
编辑:请注意,Firebase将在部署时重置您的默认值,因此您应该记得登录控制台并立即更新它们.我仍然在寻找通过CLI更新这些设置的方法,当我找到它时会更新.
小智 10
最新的firebase deploy命令会将内存分配覆盖为默认的256MB,超时最长为60秒.
或者,要指定所需的内存分配和最大超时,我使用gcloud命令,例如:
gcloud beta函数部署YourFunctionName --memory = 2048MB --timeout = 540s
其他选择,请参阅:
https://cloud.google.com/sdk/gcloud/reference/beta/functions/deploy
从 UI 中弄清楚有点棘手,所以这里有一些指导屏幕截图:
转到 url https://console.cloud.google.com/functions/list
您可以在 firebase 函数定义中添加配置,例如:
functions.runWith({memory: '2GB', timeoutSeconds: '360'})
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
13538 次 |
| 最近记录: |