I've been facing an annoying issue when calling my firebase cloud functions. They seem to go through cold starts pretty frequently.
For context, my stack is the following:
- Mobile: Flutter
- Backend: Cloud Functions
I've configured every function to have the following parameters:
{
timeoutSeconds: 120,
memory: '512MB',
minInstances: 3
}
and the functions each live in their own file e.g. ./this-is-an-endpoint.ts
which then gets exported in a larger index.ts
like the following:
export const sampleEndpoint = functions
.runWith(PARAMS_ABOVE_GO_HERE)
.https.onCall(async (data) => {
return (await import('./this-is-an-endpoint')).default(data);
});
At the top of each function I have an init()
function that gets called at the beginning and looks like:
function init() {
if (initialized) {
log instanceIdForLogging as warm start;
return;
}
instanceIdForLogging = generate();
client = new ApiClient();
...more global inits
initialized = true;
}
After all this (and starting to log unique ids per instance), I'm seeing frequent cold starts. I was under the assumption with min instances, I'd only have 3 unique IDs at most after a deploy but I'm seeing way more than that. I'm only getting a couple requests an hour at most so it's definitely not scaling up to handle more requests.
Been stuck debugging for a while so any thoughts here would be amazing and helpful. Thanks!