NHibernate is not suited for fast bulk operations. If you need performance
then work out-side of nhibernate. Your test case is about retrieving 75.000
records. This is not really a nhibernate scenario. NHibernate needs to
track each entity it dehydrates which ofcourse creates a lot of overhead.

On Mon, Mar 19, 2012 at 4:46 AM, Chinna <[email protected]> wrote:

> Hi All,
>
> I have been evaluating the performance of NHibernate and ADO.NET. I
> have created a test application which has an Employee table with
> 75,000 records. When I try to get data using NHibernate it is very
> slow compare to ADO.NET, it’s about 290% (approx.) slower.
>
> The average performance of NHibernate to bind 75,000 records is 2535
> milliseconds .
> The average performance of ADO.net  to bind 75,000 records is 867
> milliseconds.
>
> I can understand that NHibernate is a Wrapper to ADO.NET but you
> cannot pay the price of 300% for retrieval
>
> We tried the optimization tips for NHibernate from Internet. Here are
> some
> 1)      Use of Stateless Session
> 2)      Use of Named Query
> 3)      Session Flushing
> 4)      Using Stored Procedure
> 5)      Using Recompiled option
>
> As per my experience time is getting consumed when building the
> objects in memory .Also the query which is getting fired from
> NHibernate and SQL in Profiler has differences. Does not make any
> difference if executed again and again .
>
> Query Executed in SQL Manually :
> Select ID, Name, DateOfJoin, DateOfBirth, DepartmentID, Status from
> Employee : Duration 516
>
> Query Executed in SQL by NHibernate  :
> Select this._ID as ID2_0_, this_.Name as Name2_0_, this_.DateOfJoin as
> DateOfJoin2_0_, this_.DateOfBirth as DateOfBirth2_0_,
> this_.DepartmentID as DepartmentID2_0_, this_.Status as Status2_0_
> from dbo.Employee this_: Duration 1538
>
> Kindly suggest any other mechanism for increasing the performance.
> What should be the ideal performance difference when using ORM?
>
> Please find the code below….
>
> //Employee Class
>  public class Employee
>    {
>        public virtual int ID { get; set; }
>        public virtual string Name { get; set; }
>        public virtual DateTime DateOfJoin { get; set; }
>        public virtual DateTime DateOfBirth { get; set; }
>        public virtual string DepartmentID { get; set; }
>        public virtual string Status { get; set; }
>    }
>
> //NHibernate Mapping
>
>   public EmployeeMap()
>    {
>        Table("Employee");
>        Id(p => p.ID).GeneratedBy.Increment();
>        Map(p => p. Name);
>        Map(p => p. DateOfJoin);
>        Map(p => p. DateOfBirth);
>        Map(p => p. DepartmentID);
>        Map(p => p. Status);
>    }
>
> //Building Session Factory
>
>   public static ISessionFactory SessionFactory
>        {
>            get
>            {
>                if (_sessionFactory == null)
>                {
>                    _sessionFactory = Fluently.Configure()
>
>  .Database(MsSqlConfiguration.MsSql2008.ConnectionString(c
> => c.FromConnectionStringWithKey("Connection")))
>                                      .Mappings(m =>
> m.FluentMappings.AddFromAssemblyOf<Employee>())
>                                      .BuildSessionFactory();
>                }
>
>                return _sessionFactory;
>
>            }
>        }
>
>
> //Fetching data using CreateQuey
>
>    using (IStatelessSession session =
> SessionManager.SessionFactory.OpenStatelessSession())
>          {
>                 IList<Employee> lstEmployee = session.CreateCriteria<
> Employee >().List<Employee>();
>                   return lstEmployees.ToList<Employee>();
>
>          }
>
> //Fetching data using Create Query
>
>    using (IStatelessSession session =
> SessionManager.SessionFactory.OpenStatelessSession())
>          {
>                 IList<Employee> lstEmployee =
> session.CreateQuery("from Employee ").
> List<Employee>();
>                   return lstEmployees.ToList<Employee>();
>
>          }
>
>
>
>
> //Fetching Data using ADO.net
>    DataTable dtEmployees = /*Data is fetched from ADO.net using SQL
> Query*/;
>            List<Employee> lstEmployee = new List<Employee>();
>
>            foreach (DataRow dr in dtEmployees.AsEnumerable())
>            {
>                Employee employee = new Employee
>                {
>                    ID = dr.Field<int>("ID"),
>                    Name = dr.Field<decimal>("Name"),
>                    DateOfJoin = dr.Field<int>("DateOfJoin"),
>                    DateOfBirth = dr.Field<int>("DateOfBirth"),
>                    DepartmentID = dr.Field<int>("DepartmentID"),
>                    Status = dr.Field<DateTime>("Status"),
>                };
>                lstEmployee.Add(Employee);
>            }
>
> --
> 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.
>
>


-- 
Ramon

-- 
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.

Reply via email to