These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 7 posts ] 
Author Message
 Post subject: NHibernate performing horribly!!
PostPosted: Fri Dec 29, 2006 7:31 am 
Newbie

Joined: Sun Jun 25, 2006 9:17 pm
Posts: 7
Location: Tempe, Az
What would be a reasonable expectation as far as performance from NHibernate compared to using ADO.net? The reason I ask is that I benchmarked NHibernate with a query and found it to take 35 seconds to retrieve 900 records. ADO.Net takes .07 seconds to do the same. Is this typical? If not, what should I look into as far as why NHibernate is so slow?


Top
 Profile  
 
 Post subject: Re: NHibernate performing horribly!!
PostPosted: Fri Dec 29, 2006 10:21 am 
Newbie

Joined: Wed Sep 08, 2004 1:23 pm
Posts: 5
pleasekillme wrote:
What would be a reasonable expectation as far as performance from NHibernate compared to using ADO.net? The reason I ask is that I benchmarked NHibernate with a query and found it to take 35 seconds to retrieve 900 records. ADO.Net takes .07 seconds to do the same. Is this typical? If not, what should I look into as far as why NHibernate is so slow?


No, this is not reasonable.

The first thing I would ask is how are you measuring the time? Does the 35 seconds encompass just the query and retrieving the results, or does it also include other operations such as process start or SessionFactory init?

Assuming you are just talking about the query itself, then if you are using SQL Server I would use the sql profiler to see the actual SQL that is being sent to the server.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Dec 29, 2006 11:37 am 
Contributor
Contributor

Joined: Sat Sep 24, 2005 11:25 am
Posts: 198
I am willing to bet that there is a SELECT N+1 that is happening behind the scenes.
Make sure that your assoications are always lazy, enable SQL logs and check to see what is going on.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Dec 29, 2006 1:16 pm 
Newbie

Joined: Wed Aug 16, 2006 8:02 pm
Posts: 11
Test


Top
 Profile  
 
 Post subject:
PostPosted: Fri Dec 29, 2006 5:16 pm 
Newbie

Joined: Sun Jun 25, 2006 9:17 pm
Posts: 7
Location: Tempe, Az
Ayende Rahien wrote:
I am willing to bet that there is a SELECT N+1 that is happening behind the scenes.
Make sure that your assoications are always lazy, enable SQL logs and check to see what is going on.


Okay, this idea sounds like it's on the right track. What's happening is that I have an Item object, and each Item object has Locasion, CasNum and Vendor objects. Lazy loading doesn't seem like it would help here, because I am needing to display all of this data for the user. It loads all of the Item objects with one single select and then loads the child objects using individual selects.

In my mapping file, I have it set to do joins for these child objects, which I think would perform better. What might be causing it to not do joins?

Below is my mapping file:
Code:
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.0" assembly="data" namespace="data" default-cascade="save-update">
   <class name="Item" table="current_inventory">
      <id name="ID" column="item_id" type="Int64" unsaved-value="-1">
         <generator class="sequence">
            <param name="sequence">item_id_seq</param>
         </generator>
      </id>
      <property name="Description" column="description" type="string" />
      <property name="Purity" column="purity" type="double" />
      <property name="cState" column="state" type="Char" />
      <property name="NFPAHealth" column="nfpa_health" type="short" />
      <property name="NFPAFlammability" column="nfpa_flammable" type="short" />
      <property name="NFPAReactivity" column="nfpa_reactivity" type="short" />
      <property name="CatNum" column="cat_num" type="string" />
      <property name="LotNum" column="lot_num" type="string" />
      <property name="Amount" column="amount" type="Decimal" />
      <property name="Quant" column="quant" type="Decimal" />
      <property name="Units" column="units" type="string" />
      <property name="Notes" column="notes" type="string" />
      <property name="LastAction" column="last_change_action" type="string" />
      <property name="LastPurchased" column="last_purchased" type="DateTime" />
      <property name="LastChange" column="last_change" type="DateTime" />
      <property name="Hazard" column="hazard" type="string" />
      <property name="PurchasePrice" column="last_purchase_price" type="Decimal" />
      <many-to-one name="Location" class="Location" column="loc_id" fetch="join"/>
      <many-to-one name="Vendor" class="Vendor" column="vendor_id" cascade="save-update" fetch="join"/>
      <many-to-one name="LastUser" class="User" column="last_change_user" cascade="save-update" fetch="join"/>
      <many-to-one name="CASNum" class="CASNum" column="cas_id" cascade="save-update" fetch="join"/>
   </class>
</hibernate-mapping>


Top
 Profile  
 
 Post subject:
PostPosted: Sat Dec 30, 2006 8:56 am 
Contributor
Contributor

Joined: Sat Sep 24, 2005 11:25 am
Posts: 198
Check the generated SQL, that is the only way you can tell what is going on.
What do the other entities load?


Top
 Profile  
 
 Post subject:
PostPosted: Sun Dec 31, 2006 6:15 am 
Newbie

Joined: Sun Jun 25, 2006 9:17 pm
Posts: 7
Location: Tempe, Az
I checked the SQL, as I said before, the child objects are being loaded with N selects instead of using joins.

What I have is a parent object with 3 child objects. The data for the parent object lives in one table, the data for each of the child objects lives in separate tables (table-per-class semantics basically). It loads the parent objects all at once, but loads each child object individually. To put it in pseudocode:

Code:
//get all parent objects from the table
dataSet = SELECT * FROM [parent object table]
foreach( row in dataSet )
         create parent object

//load all the child objects
foreach ( parent object )
         parent.childObject1 = SELECT * FROM [child object 1 table] WHERE [child object 1].id = [child object 1 table].id //repeat for two more objects



What it seems like it should be doing:

Code:
dataSet = SELECT * FROM [parent object table] LEFT JOIN [child object tables] ON [child object tables].id = [parent object table].childId
foreach( row in dataSet )
         create parent object
         create child object


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 7 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.