I have a simple application that does like searches and read only operations on a Sql view of 100,000 rows. The application runs on a j2ee cluster with 2 nodes and I have 200 concurrent users during peak time .The performance considerably degrades at load.
I was wondering if Hibernate + OS Cache/EHCache is a good candidate for solving this as compared to a direct JDBC DB search solution.
I understand that even though I cache the results, the searches still have to go against the databse every time. The searches are taking >2 secs with the direct db call which increases up to 8 secs at peak load. I was wondering if using Hibernate and 2nd level caching would provide better performance because of optimized memory management of result objects. I may not use the query cache effectively because the search criteria are too random. I also have a limitation on the memory footprint of the 2nd level cache to not exceed 50MB. (caching the entire view costs around 170MB) so I am trying to use the disk overflow feature of the caching framework (Eh or Os cache).
Please advise. Thanks in advance.
Hibernate version: 3.0.5
Mapping documents:
Code:
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE hibernate-configuration PUBLIC
"-//Hibernate/Hibernate Configuration DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
<session-factory>
<property name="show_sql">false</property>
<property name="format_sql">false</property>
<property name="hibernate.use_sql_comments">false</property>
<property name="hibernate.generate_statistics">false</property>
<property name="hibernate.max_fetch_depth">1</property>
<property name="hibernate.cache.use_second_level_cache">true</property>
<property name="hibernate.cache.use_query_cache">true</property>
<property name="hibernate.cglib.use_reflection_optimizer">true</property>
<property name="connection.datasource">jdbc/xyzdatasource</property>
<property name="hibernate.jdbc.fetch_size">100</property>
<property name="hibernate.dialect">org.hibernate.dialect.SQLServerDialect</property>
<property name="hibernate.cache.provider_class">com.mycache.OSCacheProvider</property>
<property name="hibernate.cache.use_minimal_puts">false</property>
<property name="hibernate.cache.use_structured_entries">true</property>
<!-- Mapping files -->
<mapping resource="DataView.hbm.xml" />
</session-factory>
</hibernate-configuration>
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<!-- Generated Apr 20, 2006 11:47:00 AM by Hibernate Tools 3.1.0.beta4 -->
<hibernate-mapping>
<class name="com.test.XYZ" table="DataView" >
<cache usage="read-only"/>
<id name="id1" type="string" column="col1"/>
<!-- 44 properties follow-->
<property name="attribute1" type="timestamp"><column name="col2" length="23" /></property>
.
.
.
</class>
</hibernate-mapping>
Code between sessionFactory.openSession() and session.close():Code:
Session session = HibernateUtil.currentSession();
Criteria searchCriteria = session.createCriteria(XYZ.class);
searchCriteria.add(Restrictions.eq("col10","value10"));
if(null!=value20){
searchCriteria.add(Expression.ilike("col20", value20+"%"));
}if(null!=value21){
searchCriteria.add(Expression.ilike("col21", value21+"%"));
}
searchCriteria.addOrder(Order.asc("col22"));
searchCriteria.addOrder(Order.asc("col23"));
searchCriteria.addOrder(Order.asc("col24"));
searchCriteria.setMaxResults(100);
searchCriteria.setCacheable(true);
resultList = searchCriteria.list();
session.flush();
}catch(Exception se){
se.printStackTrace();
throw new Exception("Error while doing db work");
}finally{
HibernateUtil.closeSession();
}
Full stack trace of any exception that occurs:
none
Name and version of the database you are using:
MS SQL Server 2000
The generated SQL (show_sql=true):
select top 100 this_.col1 as col1_, from DataView this_
where this_.col10_ = > and lower(this_.col21) like ? order by this_.col 22 asc, this_.col21 asc, this_.col24 asc
Debug level Hibernate log excerpt:
error