0

I have login API developed in spring boot and deployed on cloud run with min instance 1. But for some request it is taking 20s to process which is not desirable. When I checked logs, I found that application is starting again and it is taking time and most of request are processed within 100ms .Please suggest where Im going wrong.

I found that it was a cold start problem so kept min instance to 1. But still for some request it is taking more time than expected.

  • What's the other parameters? Concurrency for instance. In addition, how many request do you have in the same time? Do you have traffic spikes? – guillaume blaquiere Dec 31 '22 at 15:49
  • Please provide enough code so others can better understand or reproduce the problem. – Community Dec 31 '22 at 18:52
  • Maximun request per container I have setted to 100. Using 4gb and 4 cup. Execution environment is setted to default. I want to process 10000 request within 10 min. – Ravi Mishra Jan 01 '23 at 10:04
  • Kindly suggest what config can I add to cloud run – Ravi Mishra Jan 01 '23 at 10:05
  • @guillaumeblaquiere Maximun request per container I have setted to 100. Using 4gb and 4 cup. Execution environment is setted to default. I want to process 10000 request within 10 min. – Ravi Mishra Jan 01 '23 at 10:09
  • What's the traffic flow? Does it start slowly? Is it stable or spiky? When did you have your issue: at the first request, or sometimes with you have a traffic spike? – guillaume blaquiere Jan 01 '23 at 22:12
  • @guillaumeblaquiere After every 30min response time is around 8s and When I deploy keeping min instance to 0, I am getting high response time after 15s. I checked logs and found that application is starting again i.e tomcat initialization is taking time. – Ravi Mishra Jan 02 '23 at 05:44
  • @guillaumeblaquiere It starts slowly. – Ravi Mishra Jan 02 '23 at 05:49
  • DockerFile:FROM openjdk:8 EXPOSE 9001 ADD target/spring-boot-login-auth-docker.jar spring-boot-login-auth-docker.jar ENTRYPOINT ["java", "-jar","/spring-boot-login-auth-docker.jar"] – Ravi Mishra Jan 02 '23 at 06:27
  • Yes, it's normal, Spring Boot is terribly slow when it starts. The min instance should solve the issue if the traffic is "smooth". I mean, if there is a sudden high volume of request, the Cloud Run autoscaler will automatically overprovision several new instances to absorb the traffic (it doesn't know what will be the future). That's why, if you have a min-instance and only 1 request, it should work. If you have 10 requests in the same time (same 10ms), the autoscaler should autoscale and you should see high latency. The traffic pattern is very important to investigate! – guillaume blaquiere Jan 02 '23 at 09:49
  • @guillaumeblaquiere I dont want to keep min instance to 1 and want request to be processed within 5 sec is there is any other way to achieve it on gcp. Can, I achieve this by deploying on GKE or something else if such scenario is not achievable using cloud run. Please suggest. – Ravi Mishra Jan 03 '23 at 15:07
  • 1
    The problem of Spring Boot is the slowness of it. I wrote an [article on that issue](https://medium.com/google-cloud/java-frameworks-performances-on-cloud-run-eb243fd84a5c) and that's why I tried Python and finally always work in Golang. I also write an [article to mitigate the cold start without using the min instance](https://medium.com/google-cloud/3-solutions-to-mitigate-the-cold-starts-on-cloud-run-8c60f0ae7894). You can also try the [Boost option](https://cloud.google.com/run/docs/configuring/cpu#startup-boost) because SpringBoot startup is optimal when 3 or more CPUs are available – guillaume blaquiere Jan 03 '23 at 20:29

0 Answers0