Skip to main content

Very low performance with Glassfish 3.1.2 and Java EE + Hibernate

1 reply [Last post]
lancerx
Offline
Joined: 2010-04-22

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 set on true or hibernate.hbm2ddl make application soo slow. But it is not the reason. 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?

persistance.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>

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
al130959
Offline
Joined: 2005-09-28

Am 06.10.2012 21:58, schrieb :
> 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.
Please try and run your code on Glassfish using a Java profiler of your
choice in CPU profiling mode to see where you are losing all that time.

If you can't make any sense out of the results yourself, then please
report back to this list where all the time gets lost according to the
profiler - we then may be able to help you figure out what is going
wrong here...

> 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?
Yes, it indeed is. Completely unexpected. That's why you need to use the
CPU profiler to see what is going on.

HTH & best regards,

Andreas

--
Andreas Loew | Senior Java Architect
ORACLE Germany