I am aware that I can set the minimum number of instances for a cloud function. However, I have some functions that are called infrequently so this is not practical from a cost standpoint.
I do know beforehand when a user is going to call a cloud function from the UI as it is the next step in a series of steps. Is there a way to warm the function up before the actual call so it is faster or is it the only way to actually call it?
If the only way is to call it then I could make the function so that it can be called with a warmUp parameter which just starts and then exits the function 5-10 seconds before it is called by the user. Could this approach work?
CodePudding user response:
As @John Hanley mentioned you can call the function asynchronously. That will cold start an instance. You can checkout the recommendations mentioned in Document to optimize your deployed function which will reduce the cold start time. Please checkout the video minimize cold start time for details.
You can refer to the document for another workaround Cold start workaround.
To avoid the cold start you may want to consider running your own server instances using something like App Engine to have warm up requests.
CodePudding user response:
With Firebase cloud functions you can now set a "Minimum Instance". Setting this to 1 would keep the cloud function alive, making it so you don't experience any slow cold starts.
You can change this default behavior by setting a minimum number of instances that Cloud Functions must keep ready to serve requests. Setting a minimum number of instances reduces cold starts of your application. https://firebase.google.com/docs/functions/tips#min