Hi Itzik, Many thanks for your detailed explanation. Actually I had tried all these options before hand but did not get the performance as expected. There was not much significant improvement. So I just followed Ayende's blog http://ayende.com/blog/4137/nhibernate-perf-tricks and that did the trick. I could insert the same number of rows (9000) in just 3 seconds which was earlier taking 2 mins.
Thanks again. I will come up with more on this if I find anything. On Dec 25, 2:21 pm, Itzik Saban <[email protected]> wrote: > Hi Sudripto, > > First of all, you'd better use StatelessSession for that kind of operations. > > But you must remember an *important rule: *do not mix between > the insertions. I'll explain: > Suppose you have 100,000 customers and 3 orders per customer (300,000 > orders). and you've defined a batch-size of 1000. Now, you'd better *not *do > that: > > foreach(customer c in customers) > { > session.Insert(c); > foreach(order o in customer.orders) > { > session.Insert(o); > } > > } > > Why? because this will produce 200,000 round trips to the DB(!!!) and not > 400 as you would expect it. > So, you'd better do that: > > foreach(customer c in customers) > { > session.Insert(c); > > } > > foreach(customer c in customers) > { > foreach(order o in customer.orders) > { > session.Insert(o); > } > > } > > This will produce 400 round trips to the DB as expected. > > also, to improve performance: > > 1. set show-sql = false > 2. disable NH logs > 3. Use transaction > > I was planing to publish a post about it in the following days, and i will. > > 2011/12/23 Sudripto <[email protected]> > > > > > > > > > > > Hi All, > > > Myself Sudripto from Aspire Systems India. My company has recently > > started working on Incorporating NHibernate for a DataLayer Module. As > > requested I have created 2 prototypes for pumping huge data in some > > tables. I have created a Data Access Object Library, A data Domain > > library, A NUnit test Application and a Winform Application with a > > Grid and some Insert Buttons. > > > The issue I am facing here is that While I call the session.Save > > function from NUnit I can insert 8000 rows in 4 secs. While the same > > call from Winforms for same number of rows is taking 20 mins. > > > I am doing Batch insert on both occasions. Both are calling the > > session.Save inside a method in the common DataAccessObject library as > > below. > > > /// <summary> > > /// Insert Objects in Batch and then Commit > > /// </summary> > > /// <param name="objectList">List of Objects to Insert in > > Batch</param> > > public void AddInBatch(IList<T> objectList) > > { > > ISession session = SessionManager.Instance.Session; > > //IStatelessSession statelessSession = > > SessionManager.Instance.StatelessSession; > > ITransaction transaction = null; > > try > > { > > if (objectList.Count > 0) > > { > > transaction = session.BeginTransaction(); > > //transaction = > > statelessSession.BeginTransaction(); > > foreach (var objectType in objectList) > > { > > session.Save(objectType); > > //statelessSession.Insert(objectType); > > } > > transaction.Commit(); > > } > > } > > catch (Exception) > > { > > HandleError(transaction); > > throw; > > } > > } > > > I also tried with StatelessSession and had set the following in the > > Winform applications configuration file > > <property name="adonet.batch_size">100</property>. But did not get any > > kind of significant improvement. > > > I further tried the same tests using Nhibernate profiler. I got the > > results as follows > > > 1. average insert statement in milliseconds from Winforms ---- 47 > > seconds for 9000 rows > > 2. average insert statement in milliseconds from Nunit---- 3 seconds > > for 9000 rows > > > Another point to Note over here is that in Nh Profiler The NUnit > > insert is showing an Alert: [Using a single session in multiple > > threads is likely a bug] > > > I will be very grateful if someone can give some insight on this. > > Thanks in Advance > > > Regards, > > Sudripto > > > -- > > You received this message because you are subscribed to the Google Groups > > "nhusers" group. > > To post to this group, send email to [email protected]. > > To unsubscribe from this group, send email to > > [email protected]. > > For more options, visit this group at > >http://groups.google.com/group/nhusers?hl=en. > > -- > Itzik Saban > > my blog <http://itziksaban.blogspot.com/> -- You received this message because you are subscribed to the Google Groups "nhusers" group. To post to this group, send email to [email protected]. To unsubscribe from this group, send email to [email protected]. For more options, visit this group at http://groups.google.com/group/nhusers?hl=en.
