c# - NHibernate suddenly very slow - inexplicable behaviour -


i know popular issue , various solutions have been proposed others, mine different.

firstly started happening since 2 days ago , nothing has changed in nhibernate layer explain such change in behaviour.

i used dottrace , drill down , found cached queries take 70 seconds perform (i.e. getallcountries() method returns list of country objects).

70 seconds pretty insane such simple query doesn't have external references.

dottrace reveals called cachedcountryservice should return list immediately. instead leads countryservice performs 70 second read.

the database mysql.

an attached image of dottrace report

an attached image of dottrace report

the country object looks this:

   public class countrymapping : classmap<country>     {         public countrymapping()         {             table("ma_tbl_country");              id(t => t.id, "id");             map(t => t.code, "code");             map(t => t.name, "name");             map(t => t.match, "`match`");              references(t => t.riskgroup).column("riskid");              hasmanytomany(t => t.paymentoptions)                 .table("ma_tbl_country_payment_option")                 .parentkeycolumn("country_id")                 .childkeycolumn("payment_option_id").cascade.saveupdate();         }     } 

the initializer doesn't affect country object although office , account used in anoher nhibernate query performs poorly (takes 30 seconds).

 public nhibernateinitializer()         {             base.             extraconfiguration =                 t =>                     t.mappings(s => s.fluentmappings.addfromassemblyof<dal.mappings.officemapping>().conventions.add(typeof(disablelazyloadconvention)))                     .mappings(s => s.fluentmappings.addfromassemblyof<accountmapping>().conventions.add(autoimport.never()));         } 

and defaultlazyconvention part of internal library this:

  public class disablelazyloadconvention : ihibernatemappingconvention, iconvention<ihibernatemappinginspector, ihibernatemappinginstance>, iconvention   {     public void apply(ihibernatemappinginstance instance)     {       instance.not.defaultlazy();     }   } 

update:

i added sql level profiling , results buffling.

i have 2 different projects running same code , 324 sql queries in slow projects taking 100 seconds run , 324 identical queries in other project taking 1 second!

so believe problem nhibernate configuration, rather code because these 2 set of queries identical using same domain models. they're using same database same db user.

from dottrace screenshot, please notice initializenonlazycollections taking of time.

the disablelazyloadconvention being applied more office. being applied classmaps in same assembly officemapping. conventions used apply mappings in wide paintbrush strokes across entire application. example, can use them things "whenever see datetime property name ends 'utc', map using .customtype("utcdatetime")."

if need apply special mappings 1 class, in classmap (for fluent mappings) or in iautomappingoverride (for auto mapping). if want change mapping every class, that's when use conventions.

remove .conventions.add(typeof(disablelazyloadconvention)) nhibernate initialization code, , replace more targeted calls .not.lazyload() in officemapping.


Comments

Popular posts from this blog

html - How to style widget with post count different than without post count -

How to remove text and logo OR add Overflow on Android ActionBar using AppCompat on API 8? -

javascript - storing input from prompt in array and displaying the array -