NHibernate - slow to Update, Delete records

435 views
Skip to first unread message

Sambha

unread,
Apr 6, 2011, 8:51:20 PM4/6/11
to nhusers
Hi, does anybody knows why it takes me 4 to 6 second to run this code?

EmployeeLanguages empl =
(EmployeeLanguages)session.Load(typeof(EmployeeLanguages),
Emplanguage.Id);

I only have 34 records on that table and if I have to update more
records then I have to wait lots.


Fabio Maulo

unread,
Apr 7, 2011, 2:49:11 PM4/7/11
to nhu...@googlegroups.com
because that session.Load imply the session-factory creation ?
because the server is at Kathmandu ?



--
You received this message because you are subscribed to the Google Groups "nhusers" group.
To post to this group, send email to nhu...@googlegroups.com.
To unsubscribe from this group, send email to nhusers+u...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/nhusers?hl=en.




--
Fabio Maulo

brendan richards

unread,
Apr 7, 2011, 8:55:55 PM4/7/11
to nhusers
Have you got any logging plumbed in? If so are you logging NHibernate
at DEBUG level to somewhere slow?

Sambha

unread,
Apr 11, 2011, 12:21:04 AM4/11/11
to nhusers
because that session.Load imply the session-factory creation ?
No, session factory is created before that. I am using MySql as my DB

e.g.
using (ISession session =
SnhrmConfig.Factory.OpenSession())
{
using (ITransaction transaction =
session.BeginTransaction())
{
if (CertificateMode.Equals("Update"))
{
// Update employee Certificate in
EmployeeCertificates Table

EmployeeCertificatesAttained empl =
(EmployeeCertificatesAttained)session.Load(typeof(EmployeeCertificatesAttained),
EmpCertificate.Id); //this part takes from 4 to 6 second
empl.EmpId = EmpCertificate.EmpId;
empl.CertificateId =
EmpCertificate.CertificateId;
empl.DateAttained =
EmpCertificate.DateAttained;
empl.ExpiryDate =
EmpCertificate.ExpiryDate;
empl.Active = EmpCertificate.Active;
session.Update(empl, EmpCertificate.Id);
transaction.Commit();
IsUpdated = true;
}
else
{
// Insert new record in
EmployeeCertificates Table
object obj =
session.Save(EmpCertificate) ;//Save Certificate Object into database
transaction.Commit();//commit transaction
IsUpdated = true;
return IsUpdated;
}
}
}
return IsUpdated;
}


because the server is at Kathmandu ?
MySQL DB is Local on my Computer



Message has been deleted

Sambha

unread,
Apr 11, 2011, 10:42:38 PM4/11/11
to nhusers
Nop, My new PC is very fast.

brendan richards

unread,
Apr 11, 2011, 11:33:03 PM4/11/11
to nhusers
You could try adding some logging.

Add the following snippets to your web.config or app.config file.

...
<configSections>
<section name="log4net"
type="log4net.Config.Log4NetConfigurationSectionHandler,log4net"/>
</configSections>
...

<log4net>
<appender name="RollingFile"
type="log4net.Appender.RollingFileAppender">
<file value="c:\\log\myApp.log"/>
<appendToFile value="true"/>
<datePattern value="yyyyMMdd"/>
<rollingStyle value="Date"/>
<filter type="log4net.Filter.LevelRangeFilter">
<acceptOnMatch value="true"/>
<levelMin value="DEBUG"/>
<levelMax value="FATAL"/>
</filter>
<layout type="log4net.Layout.PatternLayout">
<conversionPattern value="%-5p %d %5rms %-22.22c{1} %-18.18M - %m
%n"/>
</layout>
</appender>
<root>
<level value="INFO"/>
<appender-ref ref="RollingFile"/>
</root>
<logger name="NHibernate">
<level value="DEBUG"/>
</logger>
</log4net>

and then call the following line when your application starts:

log4net.Config.XmlConfigurator.Configure();

This will write a detailed log to c:\log\myApp.log

If it's NHibernate that's taking the time, you'll see what it's doing.
If there's a gap in log then the bottleneck is in the database.

To turn down the log verbosity for NHibernate level change this :
<logger name="NHibernate">
<level value="WARN"/>
</logger>

Brendan.

Sambha

unread,
Apr 12, 2011, 9:35:03 PM4/12/11
to nhusers
Ok I'll try and let you know

Sambha

unread,
Apr 13, 2011, 2:14:32 AM4/13/11
to nhusers
Actually that is why it takes so long to update an delete. Because of
<log4net>. It was already there on my app.config and I didn't know.
NHiberante was setup for somebody else before I got this project. It
was appending the log file every time and it was incredibly big.
Thanks

On Apr 12, 1:33 pm, brendan richards <bren...@openthought.com> wrote:

brendan richards

unread,
Apr 14, 2011, 12:04:02 AM4/14/11
to nhusers
lol - that's what I was fishing for in my earlier post!

Turn down the verbosity and you're good to go!
Reply all
Reply to author
Forward
0 new messages