Improve the Performance Using Degree of Parallelism
Azure Logic Apps naturally includes looping constructs that allow to iterate over a collection of records. For scenarios that require iterative processing, this is a really simple pattern. For example, if we need to copy records from an Excel spreadsheet to an Azure SQL Database, an Apply to each action will be placed on the Logic Apps design surface and will iterate through all of the Excel rows and perform database inserts for each record.
While Logic Apps makes it very simple to enable this Excel to Azure SQL scenario, it may take more time than you would typically anticipate if you have a single thread processing records. The reason is, for each insert into the Azure SQL database, a call is being made. The next record in the record set will not be inserted until the previous record has either succeeded or failed.
Let’s take a look at the following example, using the default configuration, it will take approximately 37 seconds to insert 256 records from an Excel spreadsheet to an Azure SQL database.
Using the default behavior, we can see some parallel processing occurring. As a result, some reasonable performance.
If we require singleton-like processing, we can configure Degree of Parallelism to be set to 1. If we want more parallelism, beyond the default value of 20, we can increase this value up to 50.
When we change this configuration, to have a single degree of parallelism, we will discover our throughput is significantly reduced. While the number in the image shows 1 minute, that number is rounded. The actual duration listed in our run history is 1:45.
Configuring parallelism is an important feature to understand. It has a direct impact on how a loop will be processed.
For processes that require first-in, first-out behavior, we want to set Degree of Parallelism to 1. For processes that do not require in-order delivery, we are free to modify our Degree of Parallelism. However, it is important to understand the connectors we are using may have rate limits imposed. This may mean that having a lower parallelism value will perform better than a larger value as we may avoid rate limits that will force retries from Logic Apps. For this reason, it is important to test with business scenarios to have the most predictable outcome.