Closed sdoeringNew closed 4 years ago
I've used a Docker to provide a MySQL server for the test run:
docker run --name "mysql_demo" -e MYSQL_ROOT_PASSWORD=root -p 3306:3306 -d mysql/mysql-server:8.0.19
// wait a bit
docker exec -i "mysql_demo" mysql --user=root --password=root -e "CREATE DATABASE demo"
docker exec -i "mysql_demo" mysql --user=root --password=root -e "CREATE USER 'demo'@'%' IDENTIFIED BY 'demo'"
docker exec -i "mysql_demo" mysql --user=root --password=root -e "GRANT ALL PRIVILEGES ON *.* TO 'demo'@'%'"
The problem does not occur with tomcat-jdbc connection pool. The problem does not occur with a different database as H2 or PostgreSQL.
Thanks for the report but given the the problem does not occur with another connection pool or another database, I don't see how it can be related to Spring Boot. Please consider reporting that problem to the HikariCP project or MySQL. I'd ask on StackOverflow first to see if someone in the community can help you.
Should the default connection pool be changed?
As MySQL and MariaDB are the most used databases and Spring Boot is fairly popular it is not good that the default pool is unstable on a bit of high load.
I don’t think so. Let’s confirm the issue first and we can take it from there. Feel free to add a link of what you’ve reported so that we can follow along.
Isn't the provided test application confirmation enough? What else do you need for confirmation?
This is the Spring Boot issue tracker and I've already indicated in my first comment what I'd recommend doing:
Please consider reporting that problem to the HikariCP project or MySQL. I'd ask on StackOverflow first to see if someone in the community can help you.
So you can confirm it's an HikariCP issue? I haven't been able to.
Currently I assume something about the ID generation. If I remove the @GeneratedValue
and set the ID myself the provided test application works.
Edit: My amateurish opinion is now that all connections have been pulled from the pool. Thus leaving no possibility to get another connection to get and set the next value for the table-based HiLo sequence. That's the reason the other databases are not affected as they have a real sequence.
So you can confirm it's an HikariCP issue? I haven't been able to.
No. If I did, I would have shared that information with you. Spring Boot is configuring the infrastructure and such an issue is too low-level for it to be involved.
Paging @mp911de in case that rings a bell on the Spring Data front.
Now that I know it's something ID generation related I can confirm the issue with the Tomcat JDBC pool, too. If I set the maxActive to ten (default: 50) the problem occurs with that pool, too.
So it's not necessary to change the default pool. ^^
It's a known Hibernate issue: https://hibernate.atlassian.net/browse/HHH-11825 Open for years and no real solution or workaround.
Thanks for your time. :+1:
How to solve this problem?
The problem occur with a database as MySQL. The problem does not occur with a database as Oracle.
code:
Session openSession = entityManagerFactory.unwrap(SessionFactory.class).openSession();
openSession.setHibernateFlushMode(FlushMode.MANUAL);
openSession.beginTransaction();
error: o.h.e.j.s.SqlExceptionHelper : SQL Error: 0, SQLState: null o.h.e.j.s.SqlExceptionHelper : HikariPool-1 - Connection is not available, request timed out after 30000ms.
o.s.b.a.j.DataSourceHealthIndicator : DataSource health check failed org.springframework.jdbc.CannotGetJdbcConnectionException: Failed to obtain JDBC Connection; nested exception is java.sql.SQLTransientConnectionException: HikariPool-1 - Connection is not available, request timed out after 30000ms. at org.springframework.jdbc.datasource.DataSourceUtils.getConnection(DataSourceUtils.java:82) ~[spring-jdbc-5.3.4.jar:5.3.4]
@15pkzhaozhu please ask questions on StackOverflow.
The default pool size on HikariCP is ten. If an instant high load with more than ten threads occurs the connection pool can't acquire a connection in time. That's 30 seconds until it timeouts altough the request itself would take far less than a second.
I've created and attached an application with Spring Boot 2.2.6 and a SpringBootTest: demo.tar.gz
There are many errors during the test run:
And this stacktrace is printed:
I did some further tests...
The problem does not occur with tomcat-jdbc connection pool. The problem does not occur with a different database as H2 or PostgreSQL. The problem does not occur if the pool size is set higher.