Firebase cloud function run out of memory

285 views
Skip to first unread message

林孟璋

unread,
Jan 28, 2022, 7:08:39 PM1/28/22
to Firebase Google Group

I use firebase's cloud function and got a problem. I know cloud functions can set memory like this runWith({ timeoutSeconds: 540, memory: '8GB' }).https.onCall

I've set the memory to 8g, but it's still not enough I need to get all players' docs and write something to another collection. My player number is about 30k+. and when I get all players' docs it always says run out of memory.


Do you know how to handle this? Many thanks.

Tracy Hall

unread,
Jan 29, 2022, 5:31:54 PM1/29/22
to Firebase Google Group
You will need to spawn it out, or batch it.  I very much doubt you actually need 30,000 documents in memory simultaneously to complete your actions.  You will also likely run out of *TIME* trying that even with batches.  You could use https.onRequest as a way to call/spawn the batched processes (calling a cloud function from a cloud function), but there is a loss of security so you'll have to be careful.

Quite honestly, that fact that you say you need all 30,000 documents at once has a lot of "code smell" about it...

Tracy Hall/LeadDreamer

林孟璋

unread,
Feb 1, 2022, 1:02:37 PM2/1/22
to fireba...@googlegroups.com
Thanks for your help!
I need 30,000+ docs cause I currently have 30000+ players and I need to get all players' ID and send in-game mails to them like this below
image.png
(I use where to make sure only get the players who already created their avatar)

but this line will run out of memory( not time out) I only get console log  "SetDBMailDatasForAllPlayers start"  but not   "SetDBMailDatasForAllPlayers success"
Do you have any suggestions? Many thanks.

Tracy Hall <leadd...@gmail.com> 於 2022年1月30日 週日 上午6:31寫道:
--
You received this message because you are subscribed to the Google Groups "Firebase Google Group" group.
To unsubscribe from this group and stop receiving emails from it, send an email to firebase-tal...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/firebase-talk/9a9cf28a-f0a2-4204-9af6-34d173840c32n%40googlegroups.com.

Tracy Hall

unread,
Feb 2, 2022, 12:53:38 PM2/2/22
to Firebase Google Group
You need to *PROCESS* 30,000+ documents - but you process each one *SEPARATELY* for each player, **ONE AT A TIME**.  You will AT LEAST need to paginate these (re-using an array or some such), but even with that you're likely to time out due to fetch lags.  Batch this into separate runs so no one run processes all 30,000.
Reply all
Reply to author
Forward
0 new messages