云端运行是否可以在每次出现504错误时重新启动我的容器?

huangapple go评论65阅读模式
英文:

Can cloud run restart my container every time it hit 504 error?

问题

I'm working with backend with nodejs project, and this is my first deployment project. I notice the "it work on my computer" kind of error, when I try my API in localhost it always work, but when I dockerize and deploy to Cloud Run, I found that it worked, and all my API returned pretty fast, the longest need about 10s, so I set 180s as timeout in Cloud Run. But a few hour later my team informed me that my API is down and I checked it and found that all the last request return with 504. I even tested it and it didn't worked. But soon I ran the same code in local and it worked.

I did some research and found that this can be happen if some process still running and block all the resources. But when I saw the metrics:

云端运行是否可以在每次出现504错误时重新启动我的容器?

云端运行是否可以在每次出现504错误时重新启动我的容器?

Seems like CPU and memory utilization weren't high at the time of error (9PM). I know this is not a good practice, but can I restart my container every time it hit 504 error? Not like re-deploy, I mean the container just need to run npm run start again.

英文:

I'm working with backend with nodejs project, and this is my first deployment project. I notice the "it work on my computer" kind of error, when I try my API in localhost it always work, but when I dockerize and deploy to Cloud Run, I found that it worked, and all my API returned pretty fast, the longest need about 10s, so I set 180s as timeout in Cloud Run. But a few hour later my team informed me that my API is down and I checked it and found that all the last request return with 504. I even tested it and it didn't worked. But soon I ran the same code in local and it worked.

I did some research and found that this can be happen if some process still running and block all the resources. But when I saw the metrics:

云端运行是否可以在每次出现504错误时重新启动我的容器?

云端运行是否可以在每次出现504错误时重新启动我的容器?

Seems like CPU and memory utilization weren't high at the time of error (9PM). I know this is not a good practice, but can I restart my container every time it hit 504 error? Not like re-deploy, I mean the container just need to run npm run start again

答案1

得分: 1

Cloud Run支持活性检查,您可以定期向特定端点发送请求,如果请求失败,它将终止实例,并在下次需要时启动新实例。

英文:

Cloud Run supports liveness checks, where you can have it send a request to a specific endpoint periodically and if that request fails, it'll terminate the instance and start a new instance the next time it needs one.

huangapple
  • 本文由 发表于 2023年6月12日 23:04:15
  • 转载请务必保留本文链接:https://go.coder-hub.com/76457953.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定