NHibernate的的无状态会话的刀片是缓慢的 [英] Inserts of stateless session of NHibernate are slow

查看:261
本文介绍了NHibernate的的无状态会话的刀片是缓慢的的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是一个对夫妇,我正在努力提高NHibernate的插入性能天。

It's been a couple of days that I'm working on improving NHibernate Insert performance.

我在很多帖子读取(如之一)的无状态会话可以插入像1000〜2000年的记录每秒....但是,它可以插入记录1243的最佳时间是9秒多对我来说:

I'd read in many posts (such as this one) that stateless session can insert like 1000~2000 records per second.... However the best time that it could insert 1243 records is more than 9 seconds for me :

var sessionFactory = new NHibernateConfiguration().CreateSessionFactory();
using (IStatelessSession statelessSession = sessionFactory.OpenStatelessSession())
{
   statelessSession.SetBatchSize(adjustmentValues.Count);

   foreach (var adj in adjustmentValues)
      statelessSession.Insert(adj);
}



类:

The class :

public partial class AdjustmentValue : PersistentObject, IFinancialValue
{
    public virtual double Amount { get; set; }
    public virtual bool HasManualValue { get; set; }
    public virtual bool HasScaleValue { get; set; }
    public virtual string Formula { get; set; }
    public virtual DateTime IssueDate { get; set; }

    public virtual CompanyTopic CompanyTopic { get; set; }
}



地图之类的:

Map of the class :

public class AdjustmentValueMap : ClassMap<AdjustmentValue>
{
    public AdjustmentValueMap()
    {
       Id(P => P.Id);

       Map(p => p.Amount);
       Map(p => p.IssueDate);
       Map(p => p.HasManualValue);
       Map(p => p.HasScaleValue);
       Map(p => p.Formula);

       References(p => p.CompanyTopic)
           .Fetch.Join();
    }
}



我缺少的东西吗?
任何想法如何加快插入?

Am I missing something? Any idea how to speed up the inserts?

生成的查询将同如下:

推荐答案

从NHProf的外观结果,你正在使用的身份为您的POID。因此,你可以不采取分批写入的优势。每一次插入/更新/删除是一个单独的命令。这就是为什么要花这么长。

from the looks of your NHProf results you are using identity as your POID. Therefore you cannot take advantage of batched writes. every insert/update/delete is a separate command. that is why it's taking so long.

如果你改变你的POID希洛,GUID或guid.comb并设置批量大小为500或1000,那么你将看到一个大幅改善的写入时间。

if you change your POID to hilo, guid or guid.comb and set the batch size to 500 or 1000 then you will see a drastic improvement in the write times.

这篇关于NHibernate的的无状态会话的刀片是缓慢的的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆