[英]Concurrency in Java applications - Cloud Run
I am using Cloud Run to run a java application and the concurrency for this cloud run service is set to 1. Whenever it receives a message through a http end point, applications get triggered runs for X amount of time and returns the result.我正在使用 Cloud Run 运行 java 应用程序,并且此云运行服务的并发设置为 1。每当它通过 http 端点接收到消息时,应用程序都会触发运行 X 时间并返回结果。
I would like to understand the below items:我想了解以下项目:
Thank you谢谢
I will start by answering the second question:我将从回答第二个问题开始:
Given you already have set concurrency
( Maximum requests per container
in the console) to 1.鉴于您已经将
concurrency
(控制台中Maximum requests per container
)设置为 1。
the concurrency for this cloud run service is set to 1.
此云运行服务的并发设置为 1。
You will get an error code 429 for the new request, only if you have set max-instances
( Maximum number of instances
in the console).仅当您设置了
max-instances
(控制台中的Maximum number of instances
)时,您才会收到新请求的错误代码 429。
Ref: https://cloud.google.com/run/docs/troubleshooting#429参考: https://cloud.google.com/run/docs/troubleshooting#429
Otherwise and back to your first question: if max-instances
> 1 a new Cloud Run instance will be created and the second request will suffer the container/application startup time.否则,回到您的第一个问题:如果
max-instances
> 1,将创建一个新的 Cloud Run 实例,并且第二个请求将受到容器/应用程序启动时间的影响。
This being said, if you are using Cloud Run, you are using a webserver like springboot and/or tomcat behind.话虽这么说,如果您使用的是 Cloud Run,那么您正在使用像 springboot 和/或 tomcat 这样的网络服务器。 Such server will be setup to handle concurrent requests with a thread-per-connection model and a default value of 200 for
server.tomcat.max-threads
.这样的服务器将设置为处理并发请求,每个连接的线程数为 model,
server.tomcat.max-threads
的默认值为 200。 So why not profit from this model, and increase concurrency
, if your request are not dealing with shared resources.那么,如果您的请求不处理共享资源,为什么不从这个 model 中获利,并增加
concurrency
。 Of course try to use non-blocking reactive programming model to reduce the number of threads and their memory footprint.当然尝试使用非阻塞反应式编程 model 来减少线程数量及其 memory 占用空间。
But if, for your requirement, you need to keep concurrency at 1, in this case Cloud Function will be a better choice , for these reasons:但是,如果根据您的要求,您需要将并发保持在 1,在这种情况下,Cloud Function 将是更好的选择,原因如下:
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.