News for hackers. Stuff that matters.
Re:Cloud Run – Newest member of our serverless compute stack by asciimike on Tuesday April 09, 2019 @01:00PM (#19616688)
Hey folks, one of the Cloud Run PMs (along with @steren, @ryangregg, @lindydonna, @stewart27, and others).

We're super excited to announce Cloud Run and Cloud Run on GKE, both implementing the Knative Serving API. Please let us know if you've got any questions!

Re:Cloud Run – Newest member of our serverless compute stack by dstaley on Tuesday April 09, 2019 @01:22PM (#19616951)
I'm about to launch an API that uses Cloud Functions for the entire app (it's a pretty simple API anyway). I know that Cloud Run gives me more features (being based on containers and all), but given that my API already runs on Cloud Functions, would I get any performance benefits by moving to Cloud Run?
Re:Cloud Run – Newest member of our serverless compute stack by asciimike on Tuesday April 09, 2019 @01:25PM (#19616980)
Does the Cloud Functions solution meet your current performance requirements? If so, don't worry about moving it.

The main benefits you'd see immediately are toolchain (e.g. Docker containers, existing build systems, etc.).

Re:Cloud Run – Newest member of our serverless compute stack by dstaley on Tuesday April 09, 2019 @01:28PM (#19617022)
I haven't launched it, so I'm not sure about performance. My main concerns are cold starts and concurrency. It's my understanding that Cloud Run has higher concurrency per container instance, so my guess would be that Cloud Run would give me fewer cold starts than Cloud Functions. However, since Cloud Run is a generic runtime, I'd imagine that cold starts there would be on the scale of seconds compared to milliseconds for Cloud Functions.
Re:Cloud Run – Newest member of our serverless compute stack by stewart27 on Tuesday April 09, 2019 @01:40PM (#19617145)
Cloud Functions PM here.

Your intuition around concurrency is correct: Cloud Functions has "per instance concurrency" of 1. Cloud Run lets you go significantly higher than that (default 80). This means that our infrastructure will generally create more instances to handle a request spike when using Cloud Functions vs. Cloud Run.

Creating an instance incurs a cold start. Part of that cold start is due to our infrastructure (generally this is small) but the other part is in your control. For example: if you create a client that takes X seconds to you initialize, your cold start will be at least X seconds. The initialization time will manifest as part of your cold start.

This has a few practical implications:

* writing code for Cloud Functions is generally more straightforward as single concurrency solves many problems regarding shared variables. You may also see some benefits in terms of monitoring/metrics/logging since you only need to think about one request at a time.

* you will likely see a higher incidence of cold starts on Cloud Functions during rapid scale-up, such as in response to a sudden traffic spike

* the impact of a given cold start will depend heavily on what you're doing in your container

* though I haven't validated this experimentally, I would expect that the magnitude of any given cold start (i.e., total latency contribution) would be roughly the same on Cloud Run as Cloud Functions IF you're running the same code

Re:Cloud Run – Newest member of our serverless compute stack by dstaley on Tuesday April 09, 2019 @01:51PM (#19617268)
Ah, thanks for the details there! So, given that my Cloud Functions project is a Go app (and would be the exact same code between Functions and Run), if I were to run that in a very minimal container (something like Alpine), I could get roughly the same cold start time as Cloud Functions, but fewer of them since I can respond to multiple requests using the same instance.

I'll probably do some experimentation on my end as well to test. Any suggestion how long I should wait between tests to ensure a cold start on both Cloud Functions and Cloud Run?

Re:Cloud Run – Newest member of our serverless compute stack by stewart27 on Tuesday April 09, 2019 @01:54PM (#19617296)
I think you can force cold starts between your tests by re-deploying your function/container. You could (optionally) leave a small buffer (<1 minute) after the deployment to ensure that traffic has fully migrated.
Re:Cloud Run – Newest member of our serverless compute stack by d_w_b on Tuesday April 09, 2019 @05:02PM (#19618895)
I spoke too soon. The deploy will bring up an instance instead of your first request. To force a cold start, you could set concurrency to '1' and send two concurrent requests. You should see a log entry such as the following when a new instance starts up: "This request caused a new container instance to be started and may thus take longer and use more CPU than a typical request." Alternatively, you could set up an endpoint that shuts down the server (which will shut down the instance - not advised for production code).

As an aside, the "K_REVISION" environment variable is set to the current revision. You can log or return this value to test whether traffic has migrated to a new version (instead of waiting a minute).

Re:Cloud Run – Newest member of our serverless compute stack by d_w_b on Tuesday April 09, 2019 @02:04PM (#19617395)
Yes on both accounts.
Re:Cloud Run – Newest member of our serverless compute stack by d_w_b on Tuesday April 09, 2019 @01:45PM (#19617205)
Disclosure: Cloud Run Engineer

I'd encourage you to test your particular app, but you should expect similar cold start times in Cloud Run.

You can set "Maximum Requests per Container" on container deployment so you are in control whether a container has single concurrency (i.e. "Maximum Requests per Container = 1"). If your app is not CPU-bound and you allow multiple concurrent requests (the default) you should see fewer cold starts.

Re:Cloud Run – Newest member of our serverless compute stack by hn_throwaway_99 on Tuesday April 09, 2019 @04:45PM (#19618781)
Thanks very much! Could you answer the following questions about cold start times in Cloud Run or point me to a good resource:

1. I think I have a pretty good understanding of what's going on with the lifecycle of Cloud Functions that leads to the cold start times. What happens with Cloud Run? Does it need to download the whole Docker image to a machine to run it? Seems like that would take longer. 2. App Engine has 'warmup requests', which I think are great. Is there any equivalent on Cloud Run, or plan to add? 3. Is the time that an instance is kept warm during idle similar between Cloud Functions and Cloud Run?

Thanks!

Re:Cloud Run – Newest member of our serverless compute stack by asciimike on Tuesday April 09, 2019 @09:02PM (#19620698)
1. Both cases grab the image and run it. Better per-layer caching (including very aggressive caching of common layers) is coming soon, so stay tuned. 2. No current equivalent, though there are thoughts on exposing more scaling control knobs (e.g. max-instances, min-instances). Max is easy, min is harder because of the cost implications. GAE was billed on "instance hours" but Run is CPU time, so if you go "min-instances=1" you're paying for a VM. Something like Run on GKE (where you're already paying for the compute) probably makes more sense to expose these controls. 3. Yes, though since Run can be multi-concurrent, for certain (most?) load profiles, you're going to have way fewer cold starts because the instance is already handling requests.
Re:Cloud Run – Newest member of our serverless compute stack by hn_throwaway_99 on Tuesday April 09, 2019 @09:14PM (#19620790)
Just wanted to say thanks to you and the rest of the GCP crew for being all over this thread. Most appreciated!
Re:Cloud Run – Newest member of our serverless compute stack by mikehelmick on Tuesday April 09, 2019 @01:26PM (#19616997)
Cloud Functions only supports single concurrency, one request per instance at a time.

Cloud Run supports multi concurrency by default. You might see some benefit due to that difference (fewer cold starts, less CPU time allocated)

Re:Cloud Run – Newest member of our serverless compute stack by lxxvii on Tuesday April 09, 2019 @02:03PM (#19617388)
Just tried creating a service with the sample image and love the quick deployment time compared to AppEngine Flex.

I noticed that the console shows a traffic percentage for each revision, but no apparent way to change it. Any plans to support traffic splitting, or at least a one-click way to re-activate (or re-deploy) an older revision?

Re:Cloud Run – Newest member of our serverless compute stack by asciimike on Tuesday April 09, 2019 @02:15PM (#19617489)
Yes, there are plans for traffic splitting.

Currently Cloud Run only supports the `runLatest` mode of the Knative Serving spec (https://github.com/knative/serving/blob/master/docs/spec/spe...) but we're working on other modes (e.g. `release`) which would allow for traffic splits.

Re:Cloud Run – Newest member of our serverless compute stack by crisscrosscrash on Tuesday April 09, 2019 @03:04PM (#19617917)
When would you use Cloud Run vs App Engine Flex?

Doesn't App Engine Flex essentially help you run an app in a container and handle scaling too?

For example, what if you're running a stateless JVM app like something on Play Framework. Could you run it on either App Engine Flex or Cloud Run, and if so, what considerations would there be for choosing one over the other?

Re:Cloud Run – Newest member of our serverless compute stack by asciimike on Tuesday April 09, 2019 @09:06PM (#19620733)
0. Flex doesn't scale to zero, Run does.

1. Flex runs directly on VMs (sharing some GCE networking, access to GPUs, etc.), Run doesn't.

Those are the two that come up top of mind. We're working on a more comprehensive "choose your compute product" walkthrough in the near future.

Re:Cloud Run – Newest member of our serverless compute stack by crisscrosscrash on Tuesday April 09, 2019 @10:07PM (#19621123)
Comparison doc in the future would be great!

It sounds like there's a bit of overlap. If I'm not up and running yet and just want the most managed solution (least work to run, with the most powerful high level features), is one of these a clear choice?

In my case, I don't care as much about low level access, but I just want my app to run quickly and efficiently. App Engine Flex's ability to run multiple services within an application, get load balancing set up, have versions of the app for testing and rollbacks, etc seems great. However, overall I just want to the easiest way to run my stateless set of services.

Re:Cloud Run – Newest member of our serverless compute stack by ivanr on Tuesday April 09, 2019 @02:41PM (#19617727)
Can you provide some information about when you might be adding support for IPv6? It's a deal-breaker for our particular use cases.
Re:Cloud Run – Newest member of our serverless compute stack by mrwilliamchang on Tuesday April 09, 2019 @04:05PM (#19618427)
Can you clarify what is not working for you? IPv6 should work. (I work on Cloud Run).
Re:Cloud Run – Newest member of our serverless compute stack by ivanr on Tuesday April 09, 2019 @04:14PM (#19618501)
Sorry, my question was about outbound IPv6. At the backend, we need full IPv4 and IPv6 network connectivity to the outside world. (I haven't tried Cloud Run, but I read through the docs and there are no indications [that I could find] that IPv6 is supported, as with other GCP services.)
Re:Cloud Run – Newest member of our serverless compute stack by mrwilliamchang on Tuesday April 09, 2019 @04:15PM (#19618506)
IPv6 TCP and UDP outbound works. :)
Re:Cloud Run – Newest member of our serverless compute stack by ivanr on Tuesday April 09, 2019 @04:21PM (#19618561)
That's great to hear, thanks! Is there a page in the docs where this is documented? I'd also like to know if there are any restrictions (e.g., are all outbound ports open, etc)?

If you could comment on when/whether compute instances will get IPv6, that would be great also :)

Re:Cloud Run – Newest member of our serverless compute stack by rcconf on Tuesday April 09, 2019 @01:10PM (#19616800)
Hello, I had a question about how Cloud Run handles security between containers being run on the cloud.

I assume my container runs alongside other containers on the same host, how do you prevent privilege escalation exploits?

Re:Cloud Run – Newest member of our serverless compute stack by mikehelmick on Tuesday April 09, 2019 @01:12PM (#19616832)
Cloud Run engineer here.

Containers are run in gVisor https://github.com/google/gvisor as the container sandbox.

Re:Cloud Run – Newest member of our serverless compute stack by wlhee on Tuesday April 09, 2019 @01:15PM (#19616876)
Cloud Run prevents privilege escalation by using gVisor as sandbox technology. Each container has its own isolated user-space kernel from the host.

(Disclaimer: I am Cloud Run dev)

Re:Cloud Run – Newest member of our serverless compute stack by wgoodall01 on Tuesday April 09, 2019 @05:30PM (#19619136)
I'm a student, mainly using GCP for hobby/hackathon projects, and to teach myself.

I am massively excited about Cloud Run's free tier---for someone with a budget of zero, being able to get a project off the ground and functional without paying through the nose if you forget to turn down some service is incredibly useful. Getting an unexpected $40 App Engine bill at the end of the month isn't fun.

I'm definitely going to check Cloud Run out as a go-to for future projects--it looks like a really good fit for my use case.

Re:Cloud Run – Newest member of our serverless compute stack by asciimike on Tuesday April 09, 2019 @09:03PM (#19620709)
We're super excited to see what you build :D

Even silly things like https://howdelayedissfo.com (built over the weekend with Cloud Run and Firebase Hosting) are great ways to improve your skills without breaking the bank (projected costs are well within the free tier on both products).

Re:Cloud Run – Newest member of our serverless compute stack by hamandcheese on Tuesday April 09, 2019 @01:35PM (#19617093)
Does cloud run have the same, better, or worse cold start latency compared to cloud functions?
Re:Cloud Run – Newest member of our serverless compute stack by asciimike on Tuesday April 09, 2019 @01:42PM (#19617166)
Cloud Functions is single concurrency, meaning every new request causes a cold start (generally speaking).

Cloud Run can be single or multi-concurrency (defaults to 80), meaning one in 80 requests globally causes a cold start (again, generally speaking, assuming the container isn't CPU bound below that, etc.).

So, if both are running in single concurrency mode, you'll likely see similar cold start time; however, since you can go multi-concurrent in Run, you'll likely see better performance, especially when scaling up.

A nice side effect of this is that your costs will also drop, since you can pack more requests into your instance.

Edit: as noted in the other thread, because you control the container image, you can optimize that (e.g. use Alpine instead of Ubuntu) to reduce weight and decrease cold start time. But if you're using a language like Java, it's possible that starting the JVM and framework is going to be more expensive than the OS load time, so it might be a wash.

Re:Cloud Run – Newest member of our serverless compute stack by hn_throwaway_99 on Tuesday April 09, 2019 @04:48PM (#19618800)
Sorry, just asked a similar question in response to a different comment, but just saw this detailed response. Do you know if there are any plans to add 'warmup requests' to Cloud Run like in App Engine?
Re:Cloud Run – Newest member of our serverless compute stack by asciimike on Tuesday April 09, 2019 @09:06PM (#19620735)
Replied there!
Re:Cloud Run – Newest member of our serverless compute stack by cagenut on Tuesday April 09, 2019 @03:28PM (#19618136)
can your running container instances mount a filestore nfs endpoint?
Re:Cloud Run – Newest member of our serverless compute stack by asciimike on Tuesday April 09, 2019 @04:07PM (#19618445)
Not yet, though I'm looking into both Filestore as well as GCSFuse.

The short answer is that read-only mounts are going to be super easy, but read-write is going to get really interesting (especially since there can be N instances all trying to write).

Re:Cloud Run – Newest member of our serverless compute stack by meeks on Tuesday April 09, 2019 @01:41PM (#19617154)
Any chance there will be cron jobs for functions? Right now, I'm using AppEngine just to schedule a function to run.
Re:Cloud Run – Newest member of our serverless compute stack by asciimike on Tuesday April 09, 2019 @01:46PM (#19617212)
Check out Cloud Scheduler (https://cloud.google.com/scheduler/) which can target an arbitrary HTTP URL, and will support authenticated push to securely target Cloud Functions and Cloud Run (I think this is going to public beta this week).
Re:Cloud Run – Newest member of our serverless compute stack by stewart27 on Tuesday April 09, 2019 @01:49PM (#19617241)
+1

You can also set up Cloud Scheduler to push to Pub/Sub, which can trigger your function. This is helpful if you don't want your function to be available via a public HTTPS endpoint.

Re:Cloud Run – Newest member of our serverless compute stack by hn_throwaway_99 on Tuesday April 09, 2019 @04:52PM (#19618825)
Note to Firebase team: I use exactly this (a Cloud Scheduler job that pushes to a pub/sub topic, and then set a Firebase function that runs on a topic trigger) to schedule functions, but would be really nice if I could just create a triggered cron function like this:

functions.cron.schedule('0 0 * * *').onSchedule(...)

or something like that. Even if it behind the scenes it just did exactly what I'm doing manually now, I see so many questions about cron-triggered functions that it would save a ton of people time searching for what the best route is to take.

Re:Cloud Run – Newest member of our serverless compute stack by asciimike on Tuesday April 09, 2019 @07:56PM (#19620262)
We are working on this right now, so stay tuned :)
Re:Cloud Run – Newest member of our serverless compute stack by jganetsk on Tuesday April 09, 2019 @09:41PM (#19620949)
Re:Cloud Run – Newest member of our serverless compute stack by twa927 on Tuesday April 09, 2019 @01:22PM (#19616958)
Does max. RAM usage need to be specified upfront, or what's billed is the live-allocated amount?
Re:Cloud Run – Newest member of our serverless compute stack by asciimike on Tuesday April 09, 2019 @01:27PM (#19617010)
"You are billed only for the CPU and memory allocated while a request is active on a container instance, rounded up to the nearest 100 milliseconds."

https://cloud.google.com/run/pricing

You can configure the amount allocated: https://cloud.google.com/run/docs/configuring/memory-limits

Re:Cloud Run – Newest member of our serverless compute stack by twa927 on Tuesday April 09, 2019 @01:37PM (#19617112)
Ok thanks. I'm looking for a way to run a service with memory peaks - 50pct is 200MB and 99pct is 2GB. It looks like no current serverless solution would handle it without overpaying by allocating 2GB for all executions.
Re:Cloud Run – Newest member of our serverless compute stack by crashedsnow on Tuesday April 09, 2019 @02:40PM (#19617719)
Memory is a difficult one, especially in garbage-collected languages which have a habit of filling up the heap even when it's not used, so it's not always obvious how much memory is actually being used without having language/runtime specific signals. The mitigation in Cloud Run is both concurrency, and that you're only billed while a request is active.

(Disclosure: Google Cloud PM)

Re:Cloud Run – Newest member of our serverless compute stack by twa927 on Tuesday April 09, 2019 @03:13PM (#19618020)
> Memory is a difficult one, especially in garbage-collected languages which have a habit of filling up the heap even when it's not used, so it's not always obvious how much memory is actually being used without having language/runtime specific signals.

I'm not sure what do you mean here, Cloud Run uses Docker which runs regular processes in a cgroup, so it's sufficient to check the cgroup memory usage, right? Yes, Java can always use large heaps but we're running Python and C++ where a process' memory usage directly relates to what a program allocates (even PyPy with GC has this property).

> The mitigation in Cloud Run is both concurrency, and that you're only billed while a request is active.

When there are memory peaks, larger deployments without container-level concurreny look better. For my example 16GB of RAM allows running 8 containers to get a chance for a 2GB task to complete, but on average 90% of the memory will be wasted. On a single 16GB server I can run 48 tasks with 40% wasted and a high chance of the 2GB tasks finishing. Yes, in this scenario I must handle tasks killed due to OOM but the difference in throughput is so large that it's worth it.

Re:Cloud Run – Newest member of our serverless compute stack by chrisbroadfoot on Wednesday April 10, 2019 @06:37AM (#19623377)
> Cloud Run uses Docker which runs regular processes in a cgroup, so it's sufficient to check the cgroup memory usage, right?

Cloud Run uses gVisor as its container runtime.

Disclaimer: I work on GCP but not much on/with Cloud Run.

Re:Cloud Run – Newest member of our serverless compute stack by chupasaurus on Tuesday April 09, 2019 @06:18PM (#19619543)
Cloud Run is built upon Knative so it runs inside k8s (which uses CRI API of a backend, Docker or any other alternative) which handles OOM by inner resource manager, not cgroups.
Re:Cloud Run – Newest member of our serverless compute stack by chrisbroadfoot on Wednesday April 10, 2019 @06:38AM (#19623380)
You can use Cloud Run with GCP-managed infrastructure, and also inside your own GKE cluster.

The GCP-managed infrastructure exposes the Knative API, but doesn't actually run in GKE/k8s.

(I work on GCP but not much/on Cloud Run. Above is correct to my knowledge, but I'm not an expert.)

Re:Cloud Run – Newest member of our serverless compute stack by chupasaurus on Wednesday April 10, 2019 @07:14AM (#19623533)
Good to know, thank you.
Re:Cloud Run – Newest member of our serverless compute stack by mikehelmick on Tuesday April 09, 2019 @01:24PM (#19616975)
Yes, it needs to be specified upfront.

The default is 128M and you can specify up to 2G

Re:Cloud Run – Newest member of our serverless compute stack by alexellisuk on Tuesday April 09, 2019 @02:00PM (#19617356)
Hi Mike, this looks great. I took it for a test-drive with some OpenFaaS functions. https://www.openfaas.com/blog/openfaas-cloudrun/
Re:Cloud Run – Newest member of our serverless compute stack by bgray on Tuesday April 09, 2019 @11:34PM (#19621600)
Can you compare Google Run to App Engine Flex? They sound similar.
Re:Cloud Run – Newest member of our serverless compute stack by chrisbroadfoot on Wednesday April 10, 2019 @06:35AM (#19623364)
Cloud Run uses gVisor for its sandbox, Flex runs your container in a dedicated VM.

Cloud Run has a limit of 80 concurrent requests to a copy of your app. Cloud Run has a limit of 2 GiB for memory.

Flex gives you more flexibility over VM shape (CPU, mem), so is suited better to apps that have a higher load. Flex does not scale to zero.

Cloud Run deployments should be faster (Flex provisions a load balancer for each deployment, which can be slow).

Both support deploying directly from container image.

Disclaimer: I work on GCP but have only worked a tiny bit on/with Cloud Run.

Re:Cloud Run – Newest member of our serverless compute stack by panabee on Tuesday April 09, 2019 @04:07PM (#19618443)
thanks for all the helpful comments here! we run a rails app. if we want to replace heroku with a google cloud service, would cloud run be the best one?
Re:Cloud Run – Newest member of our serverless compute stack by mattsoldo on Tuesday April 09, 2019 @04:23PM (#19618583)
I'm doing a talk at Next tomorrow about just that. For now you are probably better of using Ruby on App Engine, assuming you need to use redis as a cache. Another new feature that we launched today is VPC Connectors, which allow Cloud Functions and App Engine to connect to servers/services in a VPC.

Cloud Run will have support VPC Connectors soon (it is supported, we just haven't wired up the API/UI). After that, its your choice, they run on similar infrastructure so you just need to decide if you want to live in containerland or source code land.

Re:Cloud Run – Newest member of our serverless compute stack by mattsoldo on Tuesday April 09, 2019 @04:25PM (#19618607)
I'll post the example source code here tomorrow after the talk (still tweaking it).
Re:Cloud Run – Newest member of our serverless compute stack by panabee on Tuesday April 09, 2019 @07:09PM (#19619923)
OK thanks! How about persisting files (which actually isn't possible on Heroku but we would like to persist files on disk for simplicity so are debating about just using AWS)?
Re:Cloud Run – Newest member of our serverless compute stack by asciimike on Tuesday April 09, 2019 @07:36PM (#19620123)
We provide an in-memory writable filesystem (e.g. you want to do file transformations) but it's not persistent across all instances. We're looking into Filestore integration for a mountable NFS product, though as mentioned in another comment about that, reading is easy but writing is hard.
Re:Cloud Run – Newest member of our serverless compute stack by boundlessdreamz on Tuesday April 09, 2019 @11:41PM (#19621630)
Why is writing hard? We already use Filestore across multiple VMs in read-write mode. We ensure that writes are unique i.e no two machines will use the same filename. There are also no file modifications.
Re:Cloud Run – Newest member of our serverless compute stack by jpdb on Tuesday April 09, 2019 @01:11PM (#19616817)
Is knative build api supported as well?
Re:Cloud Run – Newest member of our serverless compute stack by asciimike on Tuesday April 09, 2019 @01:17PM (#19616899)
My understanding is that we're working on having Cloud Build support Tekton [1,2] (which is where the Knative Build API now lives)

[1] https://tekton.dev/ [2] https://cloud.google.com/tekton/