3 ms·
I'm getting ready to deploy a Cloud Functions service. I wonder what I'd gain by making it a Cloud Run service instead? I imagine cold starts for Cloud Function
by dstaley 8y ago
I'm getting ready to deploy a Cloud Functions service. I wonder what I'd gain by making it a Cloud Run service instead? I imagine cold starts for Cloud Functions are highly optimized (since they're runtime-specific).
- reilly3000 8y agoYou gain complete flexibility over the language, environment, and running time, whereas cloud functions have a fixed set of runtimes and hard execution timeouts. When it’s ‘I just want to run my container’ this seems a lot more appealing than K8s and arguably requires less cognitive overhead to fit your app into the Function as a service paradigm. If you already have Cloud Functions working then run with that!
- hn_throwaway_99 8y agoI don't fully understand how cold starts would manifest in Cloud Run, but in any case they should be MUCH less of an issue than in Cold Functions. Cloud Run has a default (and max) concurrency threshold of 80 requests per container. Thus, for example, if you are running Node, you could conceivably be handling 80 concurrent requests before needing to start another container. Cloud Functions have no concurrent requests (each instance can only handle 1 request at a time) so every concurrent request results in a cold start if additional instances are needed to scale up. Note, though, that this means you can't put per-request state in the global scope in Cloud Run, but this is safe to do in Cloud Functions because you know there that each instance is only handling one request at a time.
- reaktivo 8y agoI'm not sure this is actually the case, Cloud Functions instances might be handling one request at a time, but they call also share a global scope, as you can see in their Tips & Tricks document[1] [1] https://cloud.google.com/functions/docs/bestpractices/tips#use_global_variables_to_reuse_objects_in_future_invocations https://cloud.google.com/functions/docs/bestpractices/tips#u...
- hn_throwaway_99 8y agoNo, what I meant was that it is safe to keep request-scoped data in global scope without needing to worry that a concurrently running request will interfere with the state there. Normally in a Node server you cannot do this. Cloud Functions will reuse instances for subsequent invocations (that's what "being warm" means), but separate instances do not share global scope.