1
I’m setting up a WS server with Java, and I’m seeing some problems, like login via POSTMAN, is taking between 6000 to 7500 ms to respond, and what it really does, is around 50 ms.
After being able to set up log4, most of the delay is in: org.hibernate.dialect.Dialect
until org.hibernate.jpa.internal.util.LogHelper
and also
INFO org.hibernate.dialect.Dialect
until org.hibernate.jpa.internal.EntityManagerFactoryRegistry
.
Follow below the entire log stack:
018-01-31 14:21:38 INFO org.hibernate.jpa.internal.util.LogHelper - HHH000204: Processing PersistenceUnitInfo [
name: persistence_unit_meudb
...]
2018-01-31 14:21:38 WARN org.hibernate.orm.connections - HHH10001002: Using Hibernate built-in connection pool (not for production use!)
2018-01-31 14:21:38 INFO org.hibernate.orm.connections - HHH10001005: using driver [com.mysql.jdbc.Driver] at URL [jdbc:mysql://localhost:3306/meudb]
2018-01-31 14:21:38 INFO org.hibernate.orm.connections - HHH10001001: Connection properties: {user=root, password=****}
2018-01-31 14:21:38 INFO org.hibernate.orm.connections - HHH10001003: Autocommit mode: false
2018-01-31 14:21:38 INFO org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl - HHH000115: Hibernate connection pool size: 20 (min=1)
2018-01-31 14:21:38 INFO org.hibernate.dialect.Dialect - HHH000400: Using dialect: org.hibernate.dialect.MySQLDialect
2018-01-31 14:21:42 INFO org.hibernate.jpa.internal.util.LogHelper - HHH000204: Processing PersistenceUnitInfo [
name: persistence_unit_meudb
...]
2018-01-31 14:21:42 WARN org.hibernate.orm.connections - HHH10001002: Using Hibernate built-in connection pool (not for production use!)
2018-01-31 14:21:42 INFO org.hibernate.orm.connections - HHH10001005: using driver [com.mysql.jdbc.Driver] at URL [jdbc:mysql://localhost:3306/meudb]
2018-01-31 14:21:42 INFO org.hibernate.orm.connections - HHH10001001: Connection properties: {user=root, password=****}
2018-01-31 14:21:42 INFO org.hibernate.orm.connections - HHH10001003: Autocommit mode: false
2018-01-31 14:21:42 INFO org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl - HHH000115: Hibernate connection pool size: 20 (min=1)
2018-01-31 14:21:42 INFO org.hibernate.dialect.Dialect - HHH000400: Using dialect: org.hibernate.dialect.MySQLDialect
2018-01-31 14:21:45 WARN org.hibernate.jpa.internal.EntityManagerFactoryRegistry - HHH000436: Entity manager factory name (persistence_unit_meudb) is already registered. If entity manager will be clustered or passivated, specify a unique value for property 'hibernate.ejb.entitymanager_factory_name'
Antes do Try: 2018-01-31 14:21:45.345
2018-01-31 14:21:45 INFO org.hibernate.hql.internal.QueryTranslatorFactoryInitiator - HHH000397: Using ASTQueryTranslatorFactory
Hibernate:
select
[ Campos ]
from
tbusuario usuario0_
where
usuario0_.login=?
Antes do Return: 2018-01-31 14:21:45.387
2018-01-31 14:21:45 INFO org.hibernate.orm.connections - HHH10001008: Cleaning up connection pool [jdbc:mysql://localhost:3306/meudb]
2018-01-31 14:21:45 INFO org.hibernate.orm.connections - HHH10001008: Cleaning up connection pool [jdbc:mysql://localhost:3306/meudb]
Antes do Return: 2018-01-31 14:21:45.389
I wonder if there are any settings to do in persistence or library that will make this process faster.
Follow my persistence.xml:
<?xml version="1.0" encoding="UTF-8"?>
<persistence xsi:schemaLocation="http://java.sun.com/xml/ns/persistence
http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd"
version="2.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://java.sun.com/xml/ns/persistence">
<persistence-unit name="persistence_unit_meudb" transaction-type="RESOURCE_LOCAL">
<provider>org.hibernate.ejb.HibernatePersistence</provider>
<properties>
<property name="hibernate.dialect" value="org.hibernate.dialect.MySQLDialect"/>
<property name="javax.persistence.jdbc.driver" value="com.mysql.jdbc.Driver"/>
<property name="javax.persistence.jdbc.url" value="jdbc:mysql://localhost:3306/meudb"/>
<property name="javax.persistence.jdbc.user" value="root"/>
<property name="javax.persistence.jdbc.password" value="root"/>
<property name="hibernate.show_sql" value="true"/>
<property name="hibernate.format_sql" value="true"/>
<property name="hibernate.hbm2ddl.auto" value="update"/>
</properties>
</persistence-unit>
</persistence>
Tomcat, already solved one of the problems that is to create more than 1 connection per request, was creating a class that creates the connections and passes this data to the respective daos.
– Felipe Junges
Hi Felipe, so this kind of homemade solutions are usually the bottleneck. You can set up your datasource directly on Tomcat. That way Tomcat himself maintains a Connection Pools with open connections in background. Documentation: https://tomcat.apache.org/tomcat-9.0-doc/jdbc-pool.html . JTA or Spring declarative annotations also help greatly in the development and correct administration of transactions.
– Anthony Accioly
I took a look at the documentation you sent me, and looked for other articles, but I didn’t understand how I could apply Datasource to my application. Ps: Maven usage for dependency management.
– Felipe Junges