Hi,
Recently we had a requirement to read each account record and create 4 related child records for each of them. First we wrote a console app that will loop through each of the account records and will create corresponding records. The tool was working fine however it’s execution was very slow. It was talking around 5 hours to process 10000 Account records and create corresponding 40000 child records.
To fine tune the performance, we implemented the Parallel.ForEach.
We got the performance improvement, however, we were getting the following error
The communication object, System.ServiceModel.Security.TransportSecurityProtocol, cannot be used for communication because it has been Aborted.
And because of this, we had few Account records which had one, two or three records instead of total 4 related records as required. (as the child records might be getting created by separate thread).
For e.g. we can see that for Account Number 98208 we have four records created one at 8:33, then another one at 8:36, 8:38 and 8:41. (gap of minimum 2 minutes). So if there was an exception we had account records created with less than 4 child records.
We solved this issue by using ExecuteTransactionRequest, and creating all the child records as part of the transaction so that we either have all the 4 records created or none.
All the child records were getting created at the same time
We also got huge performance improvement, the code that was initially taking 5 hours to process 10000 records, was now taking only 1 hour to process them.
Few points to remember:-
- ExecuteMultipleRequest can contain ExecuteTransactionRequest and not vice versa.
- Batch Size of 1000 applies to both. In Online the max parallel request could be 2.
- ExecuteTransactionRequest can have mix of Create and Update Request.
Hope it helps..
Very cool.
LikeLike
Hi Nishant,
Nice article.
You can split records of 1000 or 2000 each and send request at a time using execute multiple , it will take less time .One web request how many records you are sending using execute multiple
LikeLike
Hey Nishant, Is it possible to do parallel.for in plugin ??
Bizarre question with lot of eyebrows raised – but dare i ask is that possible ? I have a scenario where around 250 child records and a parent record to be created in a sync model
LikeLiked by 1 person
The main issue here would be 2 min timeout of plugin
LikeLike
https://docs.microsoft.com/en-us/powerapps/developer/data-platform/best-practices/business-logic/avoid-batch-requests-plugin
LikeLike
Better we avoid it..
LikeLike