Very poor performance when using Glassfish 3.1.2 and Java EE + Hibernate

I came across very poor performance of the Java EE (EJB + JSF) and Hibernate (3.6.8.Final and 4.1.7.Final) applications on Glassfish 3.1.2. Sending about 300 queries to choose from takes about 20 seconds. This is unacceptable.

I have exactly the same application deployed to JBoss and TomEE. There, 300 queries to choose from takes about 1.5 seconds.

I found some answers on Google that can hibernate.show_sql true or hibernate.hbm2ddl make the application slow. But this is not true. I disabled hibernate.show_sql , but that doesn't matter. Moreover, these options are true in the JBoss and TomEE versions and work more than 10 times faster! I thought this was a problem between Glasfish and Hibernate. But I have the following application with the same business logic, the same DAO with EntityManager provided by Hibernate but configured with Spring. And the performance is great. This is strange, isn't it?

persistence.xml from defect version:

 <?xml version="1.0" encoding="UTF-8"?> <persistence xmlns="http://java.sun.com/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="1.0" xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_1_0.xsd"> <persistence-unit name="jee_project" transaction-type="JTA"> <provider>org.hibernate.ejb.HibernatePersistence</provider> <jta-data-source>jdbc/PostgreSQL</jta-data-source> <properties> <property name="hibernate.dialect" value="org.hibernate.dialect.PostgreSQLDialect"/> <property name="hibernate.hbm2ddl.auto" value="update"/> <property name="hibernate.show_sql" value="false"/> <property name="current_session_context_class" value="thread"/> </properties> </persistence-unit> </persistence> 

JDBC configuration in Glassfish

 <jdbc-connection-pool driver-classname="" datasource-classname="org.postgresql.ds.PGConnectionPoolDataSource" res-type="javax.sql.ConnectionPoolDataSource" description="" name="PostgreSQLPool"> <property name="User" value="postgresql"></property> <property name="DatabaseName" value="qazxsw"></property> <property name="LogLevel" value="0"></property> <property name="Password" value="1234"></property> <property name="ServerName" value="localhost"></property> <property name="Ssl" value="false"></property> <property name="ProtocolVersion" value="0"></property> <property name="TcpKeepAlive" value="false"></property> <property name="SocketTimeout" value="0"></property> <property name="PortNumber" value="5432"></property> <property name="LoginTimeout" value="0"></property> <property name="UnknownLength" value="2147483647"></property> <property name="PrepareThreshold" value="5"></property> </jdbc-connection-pool> <jdbc-resource pool-name="PostgreSQLPool" description="" jndi-name="jdbc/PostgreSQL__pm"></jdbc-resource> <jdbc-resource pool-name="PostgreSQLPool" description="" jndi-name="jdbc/PostgreSQL__nontx"></jdbc-resource> 
+4
source share
2 answers

I have found a reason. The answer was hidden in the lists that I pasted above. Three months ago I applied the same application for Glassfish. Then I first used Glassfish. I found on some blog how to install a data source (on localhost: 4848). Suppose my data source was named jdbc/PostgreSQL . Then I get an exception that glass wool cannot find the jdbc/PostgreSQL__pm data source. Somewhere on the Internet, I found information that the __pm suffix is __pm . The next exception was the __nontx suffix. After changing the names, the application started. But also with very low performance.

Now I added a data source named jdbc/PostgreSQL and started working with good performance! How is it possible that the data source name was incorrect, and despite all this worked (slowly)?

0
source

Is your transaction read-only. When your session contains many objects, hibernation can take a long time, performing an automatic dirty check. Your transaction may be in read-only mode under tomcat / jboss, but not under glassy skin

0
source

Source: https://habr.com/ru/post/1437032/


All Articles