I faced with very very low performance of Java EE (EJB + JSF) application and Hibernate(3.6.8.Final and 4.1.7.Final) on Glassfish 3.1.2. Sending about 300 select queries takes about 20 seconds. This is unacceptable.
I have exactly the same application deployed on JBoss and TomEE. There, the same 300 select queries takes about 1,5 second.
I found in google some answers that maybe hibernate.show_sql is true or hibernate.hbm2ddl make application soo slow. But it is not true. I turned off hibernate.show_sql but is doesn’t matter. Moreover, these options are true in the JBoss and TomEE versions and it works over 10 times faster!
I thought that this is the issue between Glasfish and Hibernate. But I have the next application with the same business logic, the same DAO with EntityManager provided by Hibernate but configurated with Spring. And the performance is great. It is weird, isn’t it?
persistence.xml from the 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>
Glassfish JDBC configuration
<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>
I found the cause. The answer was hidden in the listings which I pasted above. Three months ago I deployed the same application on Glassfish. Then I used Glassfish first time. I found at some blog how to set datasource (at localhost:4848). Suppose my datasource was named
jdbc/PostgreSQL. Then I get the exception that glassfish cannot find datasourcejdbc/PostgreSQL__pm. Somewhere in Internet I found info that suffix__pmis needed. Next exception was about suffix__nontx. After changing the names, the application started. But also with very low performance.Now I added datasource named
jdbc/PostgreSQLand it starts working with good performance!How it is possible that name of datasource was wrong, and in spite of all it was working (slowly)?