I have load test fails for simple servlet (the Cat example in hibernate document). I used jmeter to load test with Number of threads: 1000; Ramp-up Period (in second) 1; loop for ever. The test failled with outofmemorry exception, Tomcat refused connection and down.
My code is stored in:
www.ehap.com.au/test.zip
This is the hibernate.cfg.xml
<?xml version='1.0' encoding='utf-8'?>
<!DOCTYPE hibernate-configuration
PUBLIC "-//Hibernate/Hibernate Configuration DTD//EN"
"http://hibernate.sourceforge.net/hibernate-configuration-2.0.dtd">
<hibernate-configuration>
<session-factory>
<!-- Postgresql -->
<property name="hibernate.connection.driver_class">org.postgresql.Driver</property>
<property name="hibernate.connection.url">
jdbc:postgresql://192.168.0.77:5432/ehap?autoReconnect=true
</property>
<property name="hibernate.connection.username"></property>
<property name="hibernate.connection.password"></property>
<property name="dialect">net.sf.hibernate.dialect.PostgreSQLDialect</property>
<property name="show_sql">false</property>
<property name="hibernate.cache.provider_class">
net.sf.hibernate.cache.HashtableCacheProvider
</property>
<property name="show_sql">false</property>
<property name="show_sql">false</property>
<property name="hibernate.transaction.factory_class">net.sf.hibernate.transaction.JDBCTransactionFactory</property>
<property name="hibernate.cache.provider_class">net.sf.ehcache.hibernate.Provider</property>
<property name="hibernate.cache.use_query_cache">true</property>
<property name="hibernate.use_outer_join">false</property>
<property name="hibernate.c3p0.minPoolSize">5</property>
<property name="hibernate.c3p0.maxPoolSize">20</property>
<property name="hibernate.c3p0.timeout">1800</property>
<property name="hibernate.c3p0.max_statement">50</property>
<!-- Mapping files -->
<mapping resource="cats/Cat.hbm.xml"/>
</session-factory>
</hibernate-configuration>
This is the servlet code:
import java.io.*;
import javax.servlet.ServletConfig;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import myUtils.*;
import net.sf.hibernate.*;
import cats.*;
/**
* @author h
*
* To change the template for this generated type comment go to
* Window - Preferences - Java - Code Generation - Code and Comments
*/
public class CatServlet extends HttpServlet
{
public void init(ServletConfig config) throws ServletException
{
//TODO Method stub generated by Lomboz
}
protected void doGet(
HttpServletRequest request,
HttpServletResponse response)
throws ServletException, IOException
{
PrintWriter out = response.getWriter();
out.println("start");
try
{
Session session = HibernateUtil.currentSession();
Transaction tx= session.beginTransaction();
Cat princess = new Cat();
princess.setName("Princess");
princess.setSex('F');
princess.setWeight(7.4f);
session.save(princess);
tx.commit();
HibernateUtil.closeSession();
out.println("end");
}
catch(HibernateException e)
{
out.println(e);
}
//TODO Method stub generated by Lomboz
}
protected void doPost(
HttpServletRequest request,
HttpServletResponse response)
throws ServletException, IOException
{
//TODO Method stub generated by Lomboz
}
}