如何将对象存储在Firebase云功能RAM中? [英] How can I keep objects stored in firebase cloud function RAM?

查看:142
本文介绍了如何将对象存储在Firebase云功能RAM中?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的应用程序需要在处理用户的请求之前建立几个大的hashmaps。理想情况下,我想将这些hashmaps存储在机器的内存中,这意味着它不需要进行任何昂贵的处理,并且可以快速处理任何传入的请求。 b
$ b

但是这对于firebase不起作用,因为用户触发一个新的实例会引发非常耗时的预处理步骤。所以,我试着设计我的应用程序来使用firebase数据库,并且每次只从数据库中获取所需的数据,而不是将所有数据保存在内存中。但是,由于云计算功能正在从数据库中下载大量数据,现在我已经在本月下载了超过1.7 GB的下载数据,仅仅通过测试即可。这超过了配额。



必须有我遗失的东西;所有我想要的是一些hashmaps的永久记忆存储。我想要的只是在函数调用请求的时候,那些hashmaps已经准备好了。这似乎是这样一个简单的要求;怎么没有办法做到这一点?如果您想要将数据存储在运行您的云端函数的容器中,您可以使用 //stackoverflow.com/questions/42719793/write-temporary-files-from-google-cloud-function\">本地tempfs ,这实际上保存在内存中。但是,当容器被回收时,这将消失,当你的函数暂时不能访问时,会发生这种情况。因此,只要容器启动,就必须重新构建本地文件系统。



如果要永久存储您生成的值,请考虑使用Google云端存储。这可能是一个更具成本效益的选择,而且是最具扩展性的选择。

My application needs to build a couple of large hashmaps before processing a user's request. Ideally I want to store these hashmaps in-memory on the machine, which means it never has to do any expensive processing and can process any incoming requests quickly.

But this doesn't work for firebase because there's a chance a user triggers a new instance which sets off the very time-consuming preprocessing step.

So, I tried designing my application to use the firebase database, and get only the data it needs from the database each time instead of holding all the data in-memory. But, since the cloud functions are downloading loads of data from the database, I have now triggered over 1.7 GB in download for this month, just by myself from testing. This goes over the quota.

There must be something I'm missing; all I want is a permanent memory storage of some hashmaps. All I want is for those hashmaps to be ready by the time the function is called with a request. It seems like such a simple requirement; how come there is no way to do this?

解决方案

If you want to store data in the container that runs your Cloud Functions, you can use its local tempfs, which is actually kept in memory. But this will disappear when the container is recycled, which happens when your function hasn't been access for a while. So this local file system will have to be rebuilt whenever the container spins up.

If you want permanent storage of values you generate, consider using Google Cloud Storage. It is probably a more cost effective option, and definitively the most scalable one.

这篇关于如何将对象存储在Firebase云功能RAM中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆