Reputation: 9956
We have a Docker container that packages a Java Spring Boot application. The application sometimes takes about 40 seconds to start.
Is Google Cloud Run suitable to run such a "heavyweight" application?
Let's say it'd be scaled down to 0 replicas, then the following would take 40 seconds upwards to be processed. Or is there some logic on Cloud Run's side to avoid such a case.
Upvotes: 7
Views: 4435
Reputation: 1
You can avoid cold starts by setting the minimum number instances higher than 0 in cloud run. It'll cost a lot more but your last instance won't shut down when idle.
I haven't run spring boot in cloud run myself but you can scale both cpu and ram pretty high, and with a minimum of 5 instances it should be able to auto scale fast enough even with 40 s cold start.
Upvotes: 0
Reputation: 4811
You can definitely improve Spring Boot startup time by doing a few things. The easiest being the increase of CPU resource. Spring Boot startup time scales significantly based on CPU available.
We were running Spring Boot with lots of dependencies on Kubernetes. It took 10 minutes to startup with 0.1
vcpu. In a world where we need to scale up and down quickly, this was not acceptable. But once we increased it to 1
vcpu, it dropped to 1 minute. It would appear that it scales fairly linearly to the amount of CPU provided. This obviously costs more money, so it depends on what your budget will allow.
You could also use some more complex configuration to reduce the startup time. There are several benchmarks comparing different JVM options, dependencies, and Spring configuration in a lot of detail. I'll link them below for you to have a look and assess what is worth the time.
Benchmarks for Spring Boot Start Up
Let's make SpringBoot app start faster
If you are open to using TypeScript, there is a very similar framework you can use called Loopback. The patterns used reminds me a lot of Spring and being in TypeScript, it boots up incredibly quickly. My time-to-first-request to the closest region (about 2000 km away) was just 2 seconds.
Upvotes: 2
Reputation: 126
You can't avoid that 40 second spin up time. So it really depends on how often you're calling it.
We use spring boot + gke, cloud run would make no sense unless the code was used like once a week. (That's maybe dramatic, but you get it).
If you have end users interacting with that, it's probably unacceptable. If it's just an API endpoint for some automation then you're only annoying skynet.
Upvotes: 1
Reputation: 317467
You can't avoid the cold start cost when Cloud Run starts a new virtual server instance. If 40 seconds is unacceptable overhead to handle an incoming "cold" request, then you might want to pay for a servers that stay running 24/7.
Upvotes: 9