I am having an extremely low performance when I am working with NHibernate, I am trying to write objects to the database, a single write per object (That's the scenario I need to support, I can't use batch write).
I am getting about 70 writes per seconds for a simple object (Calling the method Write(object) I've written below.
I don't think my machine or database is causing this slow performance, I've tried it on several machines.
I've attached the relevent code and mapping file,
I've tried to profile the code and I noticed that the line tx.Commit() is consuming about 90-95% of entire code runtime.
I've tried to disable second layer cache and query cache and it doesn't seem to help.
Does anyone know about this issue? is this the performance I am supposed to expect or am I doing something wrong?
NHibernate version:
1.2.1 GA
Mapping documents:
Code:
<?xml version="1.0" ?>
<hibernate-configuration xmlns="urn:nhibernate-configuration-2.2" >
<session-factory>
<property name="use_reflection_optimizer">false</property>
<property name="dialect">NHibernate.Dialect.MySQLDialect</property>
<property name="connection.provider">NHibernate.Connection.DriverConnectionProvider</property>
<property name="connection.driver_class">NHibernate.Driver.MySqlDataDriver</property>
<property name="connection.connection_string">Server=localhost;Database=dotnetpersistency;User ID=root;Password=eitan1324;CharSet=utf8</property>
<property name="cache.provider_class">NHibernate.Cache.NoCacheProvider</property>
<property name="cache.use_second_level_cache">false</property>
<property name="cache.use_query_cache">false</property>
<property name="hbm2ddl.auto">create</property>
<mapping file="ComplexPerson.hbm.xml" />
</session-factory>
</hibernate-configuration>
ComplexPerson.hbm.xml
<?xml version="1.0"?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" assembly="Ponos" namespace="Ponos">
<class name="Ponos.ComplexPerson" table="COMPLEXPERSON">
<id name="Name" column="Name" type="string">
<generator class="assigned"/>
</id>
<property name="Age" />
<property name="ClientId" />
<component
name="Address"
insert="true"
update="true">
<property name="StreetNameAndNumber"/>
</component>
</class>
</hibernate-mapping>
Code between sessionFactory.openSession() and session.close():Code:
public void Write(object pono)
{
ITransaction tx = null;
ISession session = _sessionFactory.OpenSession();
try
{
tx = session.BeginTransaction();
object id = GetId(pono);
if (id == null)
return;
session.SaveOrUpdateCopy(pono);
tx.Commit();
}
catch (Exception e)
{
if (tx != null)
tx.Rollback();
throw new Exception("Can't execute write:", e);
}
finally
{
CloseSession(session);
}
}
Name and version of the database you are using:
MySQL 5.1