KsV wrote:
Hi,
I really appreciate your time and feedback.
After your reply I checked a few things.
There is something that i wanted to verify, after i have sent the collection for save i.e. have hit UnitOfWork.Comit
It performs its internal actions like OnBeforeEntitySave for the first record, saves it in the DB then goes on for the second one and son.
So this will happen 800 times as if saving in a foreach loop.
Is there any other alternative to this.
Can all 800 inserts happen at once in a single go?
Appreciate your time and help.
Thanks
The OnBeforeEntitySave method is an empty method unless you have overridden it to do logic. The collection is first processed by a graph visitor to see which entities are reachable and changed, and these entities are then sorted in the right order (this is done at the same time using a topological sort, very fast) then each entity is converted into a query and executed within the same transaction over the same connection.
You're using 5.1 which is relatively fast, 5.4 is faster but I wouldn't say it is 1000% faster in this regard. In v5.5, which will reach beta in the next month or so (maybe a little later), we've implemented query batching to batch inserts/updates into 1 query. While testing this, we first did an insert of 1000 rows separately and then with a batch. 1000 rows separately is what you see today, every query is executed separately. This takes over the network about 550ms. Batching this takes about 90ms. So batching helps.
But, and that's my point , is persisting 800 entities like in your case, doesn't take 4 minutes. It shouldn't take more than a few seconds, unless your entities have massive amounts of data inside themselves (like large objects, documents, pictures etc.) and the connection with the database is really slow (network).
You mentioned that the 800 inserts in sql take just a few seconds, how did you measure that? With a sql dump?
Your question regarding OnBeforeEntitySave, you profiled the code and it spent a lot of time in that method?