How to optimize Logic App with Dependent For Loops (Without Concurrency) to Improve Performance

Tharani 20 Reputation points
2024-10-01T16:05:55.57+00:00

Hi everyone,

I'm working on a Logic App that contains three large for loops, each with logic that depends on the output of the previous iterations. Currently, it takes about 8-10 minutes to run, and I’m looking for ways to improve the performance and throughput.

I've tried enabling concurrency, but due to the dependencies between iterations (I need values from previous iterations for calculations in each loop), running the loops concurrently hasn't been feasible. I'm aiming to at least cut the run time by half.

Does anyone have suggestions for optimizing the performance in this kind of scenario where iterations are dependent on each other? Any insights into refactoring or improving efficiency would be greatly appreciated!

Thanks in advance!

User's image

User's image

Azure Logic Apps
Azure Logic Apps
An Azure service that automates the access and use of data across clouds without writing code.
3,543 questions
0 comments No comments
{count} votes

Accepted answer
  1. Khadeer Ali 5,990 Reputation points Microsoft External Staff Moderator
    2024-10-22T06:03:20.1466667+00:00

    Hi Tharani,

    Welcome to the Microsoft Q&A Platform! Thank you for asking your question here.

    Understanding the Challenge:

    You have a Logic App with three large dependent for loops, each requiring values from previous iterations. You are correct that Concurrency is not feasible due to these dependencies. The current run time is 8-10 minutes, and you aim to reduce it significantly.

    We can implement various strategies to optimize the performance.

    Profiling and Bottleneck Identification:

    • Use Logic App monitoring tools (Azure Monitor, Logic App Diagnostics) to identify the most time-consuming steps within the loops.
    • Focus on optimizing these bottlenecks first.

    Batching and Parallelism:

    • If possible, batch operations within each loop to reduce the number of API calls or function executions.
    • Explore opportunities for limited parallelism within each loop, such as processing multiple items in parallel while maintaining dependencies.

    Data Structure Optimization:

    • Consider using more efficient data structures (e.g., dictionaries, sets) to store and retrieve intermediate results within the loops.
    • Avoid unnecessary data copying or conversions.

    Caching:

    • Implement caching mechanisms to store frequently used values and avoid redundant calculations.
    • Use Azure Cache for Redis or other caching services for external storage.

    Code Optimization:

    • Review the code within the loops for potential optimizations, such as:
      Using more efficient algorithms or data structures.
      Avoiding unnecessary calculations or function calls.
      Minimizing the number of API calls or external service interactions.

    Leverage Azure Functions:

    • If applicable, offload computationally intensive tasks to Azure Functions, which can be scaled independently and offer better performance.

    Parallel Processing (If Dependencies Allow):

    • If dependencies between loops are limited, consider running some loops in parallel using Azure Batch or other parallel processing services.

    Consider Azure Durable Functions:

    • For complex workflows with orchestration and state management, explore Azure Durable Functions, which can help manage dependencies and improve scalability. If you find this answer helpful, please click "Accept Answer" and kindly upvote it.
    1 person found this answer helpful.

0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.