简体   繁体   English

Undertow与Spring Boot应用程序一起使用时的问题

[英]Issue when Undertow used with spring boot app

I have a spring boot app running with default embedded tomcat (with tomcat jdbc connection pooling). 我有一个使用默认嵌入式tomcat(带有tomcat jdbc连接池)运行的spring boot应用程序。 It is production and running fine. 这是生产和运行良好。 I am using mysql as my database. 我正在使用mysql作为数据库。

I am now doing some stress testing in my test environment and trying to see if I get any obvious benefit if I switch from embedded Tomcat to embedded Undertow . 我现在正在测试环境中进行一些压力测试,并尝试查看如果从嵌入式Tomcat切换到嵌入式Undertow,是否可以获得任何明显的好处。 People claim to get visible improvement in their throughput by doing this due to the asynchronous nature of undertow request handling. 人们声称这样做是由于underwow请求处理的异步特性,因此可以显着提高吞吐量。

I know how to exclude tomcat and add undertow to boot app. 我知道如何排除tomcat并将undertow添加到启动应用程序。 After doing that, I am trying to run my stress-testing script to roughly generate 500 requests per second, run it for 5 minutes under this load and see how it behaves. 之后,我尝试运行压力测试脚本,以大致每秒生成500个请求,在此负载下运行5分钟,并查看其行为。 When I do this, after initial few seconds, I start getting jdbc exceptions as given below intermittently. 当我这样做时,在最初的几秒钟后,我开始间歇性地收到如下的jdbc异常。

 org.springframework.transaction.CannotCreateTransactionException: Could not open JPA EntityManager for transaction; nested exception is javax.persistence.PersistenceException: org.hibernate.exception.JDBCConnectionException: Unable to acquire JDBC Connection 
     at org.springframework.orm.jpa.JpaTransactionManager.doBegin(JpaTransactionManager.java:431) ~[spring-orm-4.3.2.RELEASE.jar!/:4.3.2.RELEASE]
     at org.springframework.transaction.support.AbstractPlatformTransactionManager.getTransaction(AbstractPlatformTransactionManager.java:373) ~[spring-tx-4.3.2.RELEASE.jar!/:4.3.2.RELEASE]
     at org.springframework.transaction.interceptor.TransactionAspectSupport.createTransactionIfNecessary(TransactionAspectSupport.java:426) ~[spring-tx-4.3.2.RELEASE.jar!/:4.3.2.RELEASE]
     at org.springframework.transaction.interceptor.TransactionAspectSupport.invokeWithinTransaction(TransactionAspectSupport.java:275) ~[spring-tx-4.3.2.RELEASE.jar!/:4.3.2.RELEASE]
     at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:96) ~[spring-tx-4.3.2.RELEASE.jar!/:4.3.2.RELEASE]
     at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179) ~[spring-aop-4.3.2.RELEASE.jar!/:4.3.2.RELEASE]
     at org.springframework.dao.support.PersistenceExceptionTranslationInterceptor.invoke(PersistenceExceptionTranslationInterceptor.java:136) ~[spring-tx-4.3.2.RELEASE.jar!/:4.3.2.RELEASE]
     at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179) ~[spring-aop-4.3.2.RELEASE.jar!/:4.3.2.RELEASE]
     at org.springframework.data.jpa.repository.support.CrudMethodMetadataPostProcessor$CrudMethodMetadataPopulatingMethodInterceptor.invoke(CrudMethodMetadataPostProcessor.java:133) ~[spring-data-jpa-1.10.2.RELEASE.jar!/:na]
    at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179) ~[spring-aop-4.3.2.RELEASE.jar!/:4.3.2.RELEASE]

It means jdbc connection can not be acquired. 这意味着无法获取jdbc连接。

NOTE : If I remove embedded undertow and again add embedded tomcat to my app, then same test runs fine without any jdbc-connection related exceptions. 注意 :如果我删除嵌入式underwow,然后再次将嵌入式tomcat添加到我的应用程序,则相同的测试运行良好,没有任何与jdbc-connection相关的异常。

My underlying Tomcat-jdbc-pool has 100 db-connection. 我的底层Tomcat-jdbc-pool有100个db-connection。 For undertow, I tried with 100 worker threads and 100 io-threads. 对于undertow,我尝试使用100个工作线程和100个io线程。

I also tried using HikariCP instead of default tomcat-jdbc-pooling. 我还尝试使用HikariCP代替默认的tomcat-jdbc-pooling。 I tried HikariCP with maximumPoolSize=100 and connectionTimeOut=60000. 我尝试了HikariCP,其中maximumPoolSize = 100和connectionTimeOut = 60000。 Again embedded-Tomcat+HikariCP runs fine under this stress-test. 再次,嵌入式Tomcat + HikariCP在此压力测试下运行良好。 But embedded-Undertow+HikariCP gives similar exceptions. 但是Embedded-Undertow + HikariCP给出了类似的例外。

So there is something different happening when I bring in Undertow in the picture. 因此,当我将Undertow带入图片中时,会发生一些不同的事情。 But I am not able to understand it. 但是我听不懂。 Please note that these exceptions come intermittently, but come for sure in every run of my stress-test when Undertow is used. 请注意,这些例外情况是间歇性发生的,但是在使用Undertow的每次压力测试中,都可以肯定地得到这些例外。

I generally searched for such issues. 我通常会搜索此类问题。 In general I don't find such common crib for Undertow. 总的来说,我找不到Undertow的普通婴儿床。

Any help to analyse the situation will save lot of time. 分析情况的任何帮助将节省大量时间。

First of you you might be better off changing things one at a time to reduce potential issues. 首先,您最好一次更改一项以减少潜在的问题。

Undertow - 100 IO threads is way too many. 不足-100个IO线程太多了。 You should probably stick with the default here which is I believe 1 IO thread per core. 您可能应该在这里使用默认值,即每个内核1个IO线程。 IO threads only job is to manage the open connections and handle any non blocking work. IO线程的唯一工作是管理打开的连接并处理任何非阻塞性工作。 JDBC SQL queries are blocking so you need to ensure any endpoint that blocks will dispatch the request to the worker threads. JDBC SQL查询正在阻塞,因此您需要确保任何阻塞的端点都会将请求分派到工作线程。 You can use the BlockingHandler for this, I'm not sure how to do it with Spring. 您可以为此使用BlockingHandler,但我不确定如何使用Spring。 Again 100 worker threads might be a bit excessive the default is a lot lower I believe 20-30 range. 同样,100个工作线程可能有点多余,默认值要低很多,我相信20-30范围。 Make sure this is working correctly with your existing connection pool BEFORE switching to HikariCP. 在切换到HikariCP之前,请确保这在您现有的连接池中正常运行。 I would suggest just leaving the thread pools at their defaults to start and make sure you are dispatching to the worker threads. 我建议仅将线程池保留为默认值以启动,并确保您正在分派到工作线程。

HikariCP - 100 connections is also a lot for HikariCP unless you have tons of very very long running queries. HikariCP-除非您有大量非常长时间运行的查询,否则HikariCP也会有100个连接。 More info about connection pool sizing . 有关连接池大小的更多信息。

Don't try changing both at the same time. 不要尝试同时更改两者。 It will be harder to track down what is going on in that scenario. 追踪这种情况下发生的事情将更加困难。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 在Spring Boot中配置Undertow RequestEncodingHandler - Configuring Undertow RequestEncodingHandler in Spring Boot Spring RestTemplate 在 Spring 引导控制台应用程序中使用时会超时 - Spring RestTemplate gives timeout when used in Spring Boot console app 在Spring Boot中为Undertow启用HTTP 2.0 - Enable HTTP 2.0 for Undertow in Spring Boot Undertow和Tomcat的Spring Boot .war上下文路径 - Spring Boot .war context path for Undertow and Tomcat 在 spring boot 嵌入式 undertow 上将 http 重定向到 https - Redirect http to https on spring boot embedded undertow Spring Boot SSL TCPClient ~ StompBrokerRelayMessageHandler ~ ActiveMQ ~ Undertow - Spring Boot SSL TCPClient ~ StompBrokerRelayMessageHandler ~ ActiveMQ ~ Undertow 在 Spring Boot 应用程序中配置 Spring Security 时,如何在没有 @Configuration 的类中使用 @Bean? - How @Bean is used in a class without @Configuration when configuring Spring Security in a Spring Boot app? 与 Spring Boot 应用程序一起使用的 Dockerfile 在哪里? - Where is the Dockerfile used with Spring Boot app? 在build.gradle中提供了runtime spring-boot-starter-undertow,但是:bootRun仍然使用Tomcat而不是undertow - providedRuntime `spring-boot-starter-undertow` in `build.gradle` but `:bootRun` still using Tomcat instead of undertow 运行 Spring Boot APP 时的 Spring Boot 问题 - Spring Boot Issue while Running the Spring Boot APP
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM