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>
source share