2011/11/8 Michael Powell <[email protected]>:
> Hello,
>
> I've got an NHibernate performance optimization question. I believe what I
> am seeing has to do with SaveOrUpdate() latency, but I'm not 100% sure of
> it.
>
> What's going on is this: I've got a data service which job it is to factory
> create a bunch of data for test and/or production environments. I do this an
> IList<> at a time and SaveOrUpdate() that enumeration of data in one
> transaction.
>
> What I am seeing is that my service count of processed data items keeps on
> increasing, which is good. That's what I want to have happen.
>
> However, what is not so good is that my backend database (MySQL) count is
> not increasing nearly as quickly. So I'm thinking there is some latency
> between SaveOrUpdate() and when the record(s) actually hit the database.

Latency is perhaps not the correct word to use. SaveOrUpdate() does
not guarantee that SQL will be executed before it returns, or even
within a certain time frame. Nothing will be sent to the database
until NHibernate has a reason to flush.


> So... My question is this, I don't want to slow down the service more than
> is necessary, but I believe it would be helpful for the service not to get
> so far ahead of the database.
>
> So... Can I do a Session Flush? Or other type operation along these lines?

You can do flush explicitly, but what you absolutely wants to do is
make sure you don't keep objects around in the session longer than
they are needed. All loaded objects tracked by the session will
contribute to increase the time taken by flush (to detect changes),
and flush may easily be called multiple times depending on usage. So
either close/+reopen the session between each batch, or call Clear()
on it. You might also want to look at ISession.FlushMode to disable
auto flush in order to ensure there will only be one flush per batch.

>
> Another thing might be to abandon Sessions altogether and go direct through
> a Sql DbCommand, for that matter.

That could certainly be the fastest way, but will bypass any logic you
may have in your domain model, so this is of course a tradeoff.


/Oskar

-- 
You received this message because you are subscribed to the Google Groups 
"Fluent NHibernate" 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/fluent-nhibernate?hl=en.

Reply via email to