GCP Cloud Run VS Cloud Function Cold Starts

Andrew Hayes
5 min readMay 13, 2019
Source: Google Cloud Platform

I’m working on a small side project, for which I’m using Firebase and Google Cloud Functions. So far it’s been great however one of the use cases requires a response from the Cloud Function within a certain time limit. Occasionally, usually after the weekend, the Cloud Function will need to cold start and will take just too long. ‘Cold Starts’ are when a ‘serverless’ service is not cached by the cloud provider and the execution environment needs to be initialized from scratch.

I followed all the tips and tricks recommended by Google in their documentation, however it was never quite quick enough. So I decided to give Google’s new “Cloud Run” a look to see if it could deal with cold starts any better. Cloud Run is Googles new ‘serverless’ container offering. To test this I created a basic Cloud Function and two basic Cloud Run containers, then sent a few requests to them and timed the response.

Cloud Function

For the Cloud Function I simply created a brand new Cloud Function, removed the code that read the request and simply got it to output ‘hello world’. The code looks like this:

exports.helloWorld = (req, res) => {
let message = 'Hello World!';
res.status(200).send(message);
};

Cloud Run

--

--

Andrew Hayes
Andrew Hayes

Written by Andrew Hayes

Staff Software Engineer @ Harness Belfast

Responses (2)