question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Logic App Standard - Slow Performance - Loops

See original GitHub issue

Creating a simple workflow which has actions to create an array of x items, loop through the items and add the current time into another array variable the performance seems extremely slow/limited. I’ve amended multiple host settings which are mentioned to increase throughput (Such as Jobs.BackgroundJobs.NumWorkersPerProcessorCount) and also concurrency settings with no significant impact. When setting the for each loop concurrency to its max(50 concurrent iterations) it completes the workflow in the following approximate times:

500 items: 30 seconds 1000 items: 2+ minutes 5000 items: 30 minutes

I’d expect all of these to be less than a minute with some of the lower end being within milliseconds. There does not appear to be an issue with the underlying compute as the % CPU and Memory do not exceed 70% and the plan never scales even under load which feels like there is either limitations of the product, configuration restricting throughput or a potential bottleneck somewhere such as the associated storage account.

I know that there is a SplitOn() feature which can be used to separate workflows for processing but I have a requirement to extract 100,000’s of messages from a Service Bus and transform them into a single batch. I’m hoping to understand if there is an issue with configuration which can be updated to massively improve the throughput or whether the limitation is due to the product and if we need to switch to using Azure Functions.

An example workflow which can be used for testing is below:

{
    "definition": {
        "$schema": "https://schema.management.azure.com/providers/Microsoft.Logic/schemas/2016-06-01/workflowdefinition.json#",
        "actions": {
            "Compose": {
                "inputs": "@variables('testArray')",
                "runAfter": {
                    "For_each": [
                        "Succeeded"
                    ]
                },
                "type": "Compose"
            },
            "Execute_JavaScript_Code": {
                "inputs": {
                    "code": "return Array.from({length: 5000}, (x, i) => i);"
                },
                "runAfter": {
                    "Initialize_variable": [
                        "Succeeded"
                    ]
                },
                "type": "JavaScriptCode"
            },
            "For_each": {
                "actions": {
                    "Append_to_array_variable": {
                        "inputs": {
                            "name": "testArray",
                            "value": "@{items('For_each')}: @{utcNow()}"
                        },
                        "runAfter": {},
                        "type": "AppendToArrayVariable"
                    }
                },
                "foreach": "@outputs('Execute_JavaScript_Code')",
                "runAfter": {
                    "Execute_JavaScript_Code": [
                        "Succeeded"
                    ]
                },
                "type": "Foreach"
            },
            "Initialize_variable": {
                "inputs": {
                    "variables": [
                        {
                            "name": "testArray",
                            "type": "array"
                        }
                    ]
                },
                "runAfter": {},
                "type": "InitializeVariable"
            }
        },
        "contentVersion": "1.0.0.0",
        "outputs": {},
        "triggers": {
            "Recurrence": {
                "recurrence": {
                    "frequency": "Day",
                    "interval": 15
                },
                "type": "Recurrence"
            }
        }
    },
    "kind": "Stateful"
}

Issue Analytics

  • State:closed
  • Created a year ago
  • Reactions:2
  • Comments:6 (1 by maintainers)

github_iconTop GitHub Comments

1reaction
asmasoncommented, Jun 9, 2022

Some great advice here. I had a workflow with nested foreach loops, it was just adding strings to an array variable and doing string concatenation. I had just 1 iteration of the outer foreach, then 100 iterations of the inner foreach. It took 5 minutes to run the workflow. So I replaced both of the foreach actions with Inline Javascript ones. Now my workflow takes 3 seconds. 😃

0reactions
github-actions[bot]commented, Oct 27, 2022

This issue was closed because it has been inactive for 7 days since being marked as stale.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Using Inline Code instead of a Foreach Loop for better ...
The foreach loop with variables is slow by design, because each time the array variable is updated there is a round trip to...
Read more >
Logic Apps - foreach loop very slow
I've noticed that looping (using foreach) in Azure Logic Apps is very slow. As an example I've looped over a http result containing...
Read more >
Logic App - For each loop dog slow? : r/AZURE
I have a logic app that deletes old storage blobs using the rest api. Using an Until loop, I get all the blobs...
Read more >
Azure Logic App Best practices: #18 Foreach Parallelism
Your logic app first runs all the actions inside the loop and then checks the condition or state. If the condition is met,...
Read more >
Logic Apps - foreach loop very slow - appsloveworld.com
The reason it is slow is because the concurrency for loops is default of 20 and max of 50. The best way around...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found