English 中文(简体)
如何确保与MassTransit Saga公司的良好表现,
原标题:How to ensure good performance with a MassTransit Saga that adds an item to an NHibernate-persisted IList

我有一个有3个州的传奇

    public static State Initial { get; set; }
    public static State ReceivingRows { get; set; }
    public static State Completed { get; set; }

它从初始版本转换为接收记录, 当它得到一个 BofMessage ( Bof = 文件起始处) 。 在 BofMessage 之后, 它会收到大量 RowMessage, 其中每个文件在平坦文件中描述一行 。 一旦所有RowMessage 发送, 就会发送一个 EofMessage, 并对状态进行修改 。 观察 - 查看 - 显示 - 显示 - 显示 - 显示 - 显示 - 显示 - 显示 - 显示 - 显示 - 显示 - 显示 - 显示 - 显示 - 显示 - 显示 - 显示 - 显示 - 显示 - 显示 - 显示 - 显示 - 显示 - 显示 - 显示 - 显示 - 显示 - 显示 - 显示 - 显示

static void DefineSagaBehavior()
{
    Initially(When(ReceivedBof)
        .Then((saga, message) => saga.BeginFile(message))
        .TransitionTo(ReceivingRows));

    During(ReceivingRows, When(ReceivedRow)
        .Then((saga, message) => saga.AddRow(message)));

    During(ReceivingRows, When(ReceivedRowError)
        .Then((saga, message) => saga.RowError(message)));

    During(ReceivingRows, When(ReceivedEof)
        .Then((saga, message) => saga.EndFile(message))
        .TransitionTo(Completed));
}

public override void OnAddRow(ParcelRowMessage message)
{
    // ensure isCauvReturned is "Y"
    var fields = message.Value;
    var isCauvReturned = fields[33] == "Y";
    if (!isCauvReturned)
        return;

    // add row with just parcel number
    var parcelNumber = fields[1];
    var row = parcelNumber;
    _rows.Add(row);
}

使用 NHProf 调查显示,每行添加一个“ 强” 的行,导致该行的 " 强 " / " 强 " 列表:

A) 从数据库中选择

B) 从数据库中删除

C) 重新输入数据库。

这对我来说似乎是非常糟糕的行为。 添加一行所需要的只是... 那么, 在数据库中添加一行! 添加操作实际上是我对行列表所做的唯一一件事 。 当我们在列表中有 10,000 秒的项目时, 这不会缩放 。

有没有人知道怎么让这个 假象更正常的性能行为吗?

BTW - 这里如何绘制 IList 的地图, 如果你需要的话 -

        HasMany(x => x.Rows)
            .Table("OwnerHistorySagaRow")
            .KeyColumn("CorrelationId")
            .Element("Row")
            .Cascade.AllDeleteOrphan();

谢谢!

问题回答

我知道这是一个死的东西, 但这里是真正的答案 得到一个袋子正确工作。

Bag(x => x.Rows, c =>
{
    c.Key(k =>
    {
        k.Column("RowCorrelationId");
        k.ForeignKey("FK_State_Row");
        k.NotNullable(true);
    });
    c.Fetch(CollectionFetchMode.Join);
    c.Lazy(CollectionLazy.NoLazy);
    c.Cascade(Cascade.All);
}, r => r.OneToMany());

Rows 的类别类型是 liist<Row> 。





相关问题
nHibernate one-to-many inserts but doesnt update

Instead of getting into code, I have a simple question. Default behavior for a simple one-to-many is that it inserts the child record then updates the foreign key column with the parent key. Has ...

How Do I copy an existing nhibernate object as a new object?

I a persisted NHibernate object that I would like to repersist as a new entity. How do I get NHibernate to save this object as if it was a new? I am thinking I might create a session interceptor to ...

join across databases with nhibernate

I am trying to join two tables that reside in two different databases. Every time, I try to join I get the following error: An association from the table xxx refers to an unmapped class. If the ...

WPF - MVVM - NHibernate Validation

Im facing a bit of an issue when trying to validate a decimal property on domain object which is bound to a textbox on the view through the viewmodel. I am using NHibernate to decorate my property on ...

NHibernate Search in a List using ICriteria

I have my class X : public class ClassX { public virtual IList<ClassY> ListY { get; set; } ... } My ClassX mapping (using Fluent) ... HasMany<ClassX>(x => x.ListY ) ....