Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

GCP Cloud Functions - Memory Consumption

How does Cloud Functions compute memory consumption?

Is it the total amount memory of all the functions that are currently running at the moment?

Let's say:

Total Memory assigned 512 MB.

3 running functions with 60MB each.

Does it mean we use 180MB in total? Or does each function gets it's own memory consumption?

I'm getting a graph that looks like this for memory consumption:

enter image description here

Objects are not persistant, and I don't write to local files, so I'm wondering if there's an issue somewhere.

Everytime I deploy a new function, the memory consumption goes down, but then with more invocations the memory consumption increases until I see memory exceeded limit error.

like image 591
user1157751 Avatar asked Jan 26 '23 20:01

user1157751


1 Answers

Each function invocation runs in its own server instance. The duration and memory usage over that time of that function invocation are used for billing.

An individual Cloud Function server instance does not handle invocations in parallel. Only in serial. Each function invocation is billed individually. Functions can be invoked in parallel only when Cloud Functions determines that multiple instances are best to handle the load on the function.

If you store anything at all in global memory space without deallocating it, that memory allocation will count against future invocations of that function, in that server instance, until that instance is shut down for whatever reason. To minimize memory usage, only allocate objects locally that will get cleaned up when the function is complete. Memory leaks are often difficult to detect.

Without seeing the code for your function, and understanding its usage behavior, it's not really possible to fully explain the graph that you're seeing.

like image 83
Doug Stevenson Avatar answered Feb 11 '23 22:02

Doug Stevenson