Spring Boot应用程序可以同时处理多个请求吗? [英] Can Spring Boot application handle multiple requests simultaneously?

查看:652
本文介绍了Spring Boot应用程序可以同时处理多个请求吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Spring Boot开发Rest API,该API已部署在AWS Beanstalk上.潜在地,该服务每天将受到成千上万客户的青睐.因此,我想了解Spring Boot处理多个请求的功能.

I am developing Rest APIs with Spring Boot which is deployed on AWS Beanstalk. Potentially, the service will be getting hits from thousands of clients every day. Therefore I would like to understand capability of Spring Boot of handling multiple requests.

根据我在> Boot引导中:同时处理多个请求如何在春季启动中使用线程安全控制器 ,似乎Spring Boot可以在控制器为线程安全的同时并发处理请求.

From what I read in Spring-Boot: Handle multiple requests concurrently and How to have thread safe controller in spring boot, it seems Spring Boot can handle requests concurrently while controller being thread safe.

但是,如果同时向同一端点发出两个请求以进行更新,那么控制器是一次接一个地处理请求还是与两个并行线程同时处理?如果是后者,则每个线程是否都有其自己的实体管理器?有没有一种方法可以实现一个线程池,以根据EC2实例的容量限制线程数?顺便说一句,如何根据估计的请求量来决定应该从一个实例开始做多大?

If two requests are made to the same endpoint for updates at the same time though, does the controller deal with the requests one after another or simultaneously with two threads in parallel? If latter, does each thread has its own entity manager? Is there a way to implement a thread pool to limit the number of threads based on the capacity of the EC2 instance? By the way, how do I decide how big of an instance should I start with based on the estimated volumn of requests?

推荐答案

是的,Spring Boot可以同时处理请求! 您可以通过在application.propertiesapplication.yml中添加server.tomcat.max-threads来限制并发请求的数量. Spring将管理连接池并处理实体管理器的分配(根据您在属性中指定的最小和最大连接数). 我相信您可以在这里了解更多信息:

Yes, Spring boot can handle simultaneously requests! You can limit the number of concurrent requests by adding server.tomcat.max-threads to your application.properties or application.yml. Spring will manage a pool of connections and handle the distribution of entity managers (according to the minimum and maximum of connections you specify in your properties). I believe you can read more about it here: When are connections returned to the connection pool with Spring JPA (Hibernate) Entity Manager?

这篇关于Spring Boot应用程序可以同时处理多个请求吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆