cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
bondy_07
Frequent Visitor

Apply for each is very slow

Hello,

 

I am using Apply for Each to loop through the records and some conditions in LOOP. My observation is that the Flow gets stuck up in Apply for Each and takes 30 mins for looping through 150 records.

Any help is appreciated for improving the performance of the Flow

29 REPLIES 29
MattWeston365
Memorable Member
Memorable Member

Hi @bondy_07 the amount of time the looping takes will depend on the actions which are contained within the loop. When I'm working on my Flows, I always try to limit the number of steps that are in each loop.

 

Another consideration is concurrency. By default the loop will process sequentially, whereas, assuming you're using an apply to each loop, I can change the concurrency to allow side by side iterations of the loop. To do this

  1. click on the ellipsis (...) in the top right corner of your loop
  2. Select settings
  3. Switch the concurrency control on (toggle switch)
  4. Either leave the degree of parallelism as it is (default 20) or up it as you see fit.

Give that a go and see if that brings the run time down.

Hi, @MattWeston365  this didn`t help.....

Hi @bondy_07 can you please post a screenshot of your Flow actions? If you can post one screenshot which just outlines the overall Flow, and one which shows the execution times for each of the steps please?

Anonymous
Not applicable

I agree with this. I am insert 13,000 records into a sharepoint list. Entire payload converted into JSON is 10 MB.  With parallelism set to the maximum of 50 it takes 30 minutes to complete.  That is not an acceptable amount of time. A couple of minutes, maybe.

I have the same issue. I'm testing flows, while developing them. I need to iterate through a small array for 20 items that was already retreived. It takes more than 10 minutes for it to go through. I never saw it to be that slow before.

 

I'm experiencing a similar issue in speed. I have a loop with 8 actions contained within that is meant to loop through several hundred CSV values and store in an array on it's way to JSON. It takes ~30 minutes sequentially and upwards of 1.25 hours at full concurrency. I understand the reasoning to keep the loop as simple as possible, but what stumps me is that concurrency is slower than sequential. That doesn't make much sense to me...

 

2020-03-20 19_38_54-Edit your flow _ Power Automate.png2020-03-20 19_39_42-Run History _ Power Automate.png

Can anybody explain what is the root cause for these delays ? Seconds, I can understand, minutes is just baffling.

Stephane

Anonymous
Not applicable

Yes, the unexplainable slowness of Power Automate flows is something that's rankled me, as well.

While it's not a solution, per se, one way to mitigate the time it takes to complete a "apply to each" loop is to limit the number of iterations it needs to complete. I do this by always using a "filter" action immediately before the loop, and then feeding the loop with the result of that filter. You will often need to get creative with your filter conditions, but it can significantly reduce the amount of time it takes for your flow to complete.

Another trick I've found is to break up the loop into multiple loops (again, using the filter action to break up the data). If, for example, you use a condition inside your loop to do one thing to some data and another thing to the rest of the data, perform this data separation outside of the loop using a pair of filter actions, and then run two loops in parallel, each taking the result of one of the filter actions. This avoids the use of a conditional inside the loop, which can halve the time to complete.

Something like this...

Screenshot 2021-04-30 151519.png

 

Whenever something is slow, it makes me wonder if between certain steps the workflow engine is doing transactional writing of data to a persistent storage, in case it needs to restart due to some failure. At least, that's what I learned from my Biztalk years. There should be a way to tell the engine not to bother with that and just restart from the saved state before the apply to each.

Anonymous
Not applicable

Or it could be Microsoft being...well...Microsoft, and not bothering to implement anything correctly. >_>

Seriously, I've seen better code come out of an eight year-old. Microsoft's dev teams ought to be ashamed of themselves.

vargasjo
Frequent Visitor

today im getting random slows on appy to each, on a flow that was always working ok, im guessing right now its something microsoft related, to accelerate de process im cancelling manually the stucked flow and resubmitting.

carudev
Advocate II
Advocate II

Hi guys! 

 

I have a flow that makes a REST request to update items in a Sharepoint list. I have about 5k items on the list and my flow is taking more than a day to execute: one day and 18 hours on average. Is there any way to decrease this time?

 

PS: I already put the flow parallelism at maximum. 😕

Thank you all! 

Anonymous
Not applicable

Hi, @carudev!

When you say you've "put the flow parallelism at maximum," do you mean you've set the concurrence of an apply to each block to 50, or that you've created hundreds (whatever the maximum is) of parallel branches within the flow?

Since a REST call (I assume you're using the send HTTP request action here) can be used for only one item at-a-time, there's no way to speed up this action itself. However, you could try running more than one of them simultaneously. In your flow, use filters to break up your array of items into multiple sets—say, one set could have the first 100 items, then the next set could have the next 100, and so on. Then, in parallel branches, send each set through an apply to each action with the REST call inside. While the concurrence limit of each apply to each action will still keep things slow, you'll be running more than one of them at any time, which could speed things up. Remember to set the concurrence of the apply to each blocks to 50, and it's fine to have all your branches be identical and performing the same task. What we're trying to accomplish is tricking Power Automate into thinking it's doing different things with each branch.

For a diagram of how this might work, see my screenshot above from 30 April 2021.

Another issue might be how quickly SharePoint is responding, especially if you're sending it 5k+ REST reuests.

jhfin
New Member

Hi @carudev ,


I have also struggled with slow operations against Sharepoint. Currently I believe batching might be the solution.

 

I have tested this with Graph API using Powershell. I have also written a blog post about it: https://jb1c.blog/2021/05/18/using-graphapi-for-exporting-importing-editing-gigantic-sharepoint-list...

 

Microsoft has also a nice tutorial on doing something similar with the flow: Create a Microsoft Graph JSON Batch Custom Connector for Power Automate - Microsoft Graph | Microsof...

 

That requires using registered AzureAD application but fortunately it is now possible to have one with a reasonable permissions: https://developer.microsoft.com/en-us/graph/blogs/controlling-app-access-on-specific-sharepoint-site...

 

I'm currently planning to try this out with the flow, but building batches from json needs some more designing. Anyways my experience with the Powershell is promising!

 

Hope this helps!

Hi @carudev 

 

I have just done a blog post and video which covers using Power Automate delete items from a SharePoint list using the Batch API. It is much faster than the standard method.

 

I am also going to do a separate video on creating and updating items, but the concept will be similar for all cases. Might be a good place for you to start.

 

Blog: tachytelic.net

YouTube: https://www.youtube.com/c/PaulieM/videos

If I answered your question, please accept it as a solution 😘

Anonymous
Not applicable

Hi,

 

I have found that using Variables inside apply to each functions slow it down considerably. This is because the Flow has to "Lock" the variable while it is in use and this adds time to the run. Concurrency will make the situation worse in these cases as each concurrent action is raised as a separate "mini flow" when being run and each "mini flow" has to wait for the variable to become unlocked and then has to lock it for its run, do its actions and then unlock it again.

 

I have found that minimising the use of variables can significantly reduce run times. I have found that using Compose actions are far quicker, although you may need to evaluate this depending on your needs. 

 

I have also found that table actions tend to be mush faster as well. One example was I needed to update records in sharepoint in bulk. I used a select command to build a JSON input with graph bulk commands and then ran a single bulk graph command to do my inputs (up to 20 a time), instead of using an apply to each, this reduced my import times from approx 4 hours per 1000 to about 10 minutes.

 

Have a look at the blog here, there is some really good info about Flow performance improvements:
https://sharepains.com/2018/10/15/microsoft-flow-improve-your-flows-performance-in-a-few-easy-steps/

 

Anonymous
Not applicable


@Anonymous wrote:

...each concurrent action is raised as a separate "mini flow" when being run and each "mini flow" has to wait for the variable to become unlocked and then has to lock it for its run, do its actions and then unlock it again.

While this is technically true, it's a very niche case. The variable in-question is "locked" only while a CRUD operation is being actively applied to it, not for the entire run of that particular instance. That takes almost no time at all, and running concurrent "mini flows" will use the same variable space simultaneously while running. That's why a tooltip appears when you add a "Set variable" control within an "Apply to each" container, telling you to set the concurrency to 1. Multiple concurrent runs of that container—depending on what happens within the container—will use and/or overwrite the variable while another instance of that container is still using it. So, the time impact of accessing variables within an "Apply to each" container is negligible. The real time hit comes from more compute-heavy operations like file I/O, complex calculations, or branched and nested conditional statements (conditionals are an interesting case in themselves, since every branch needs to be computed whether or not it's actually executed).

Anonymous
Not applicable

Hi @Anonymous That's not my experience, almost every time I have tried to use a variable in an apply to each, my flow grinds to a halt and adds huge amounts of time.

In the example given above by Alan Sanchez, every action in the loop is actioning a variable, so whilst it seems negligible on a single action, when you have a loop with 4 variable actions and then a loop inside that with 3 variable actions, all of a sudden that negligible delay becomes huge delays. Even 1 extra second per loop can add hours to the run if you have thousands of iterations. For example, 3600 records with 1 extra second will add an hour to the run time.

 

All I am saying is try to reduce the amount of variable actions, try using a compose action if you don't need to make amendments and also try using array actions instead of loops as they can do thousands of edits in a second. I am not saying that variables are bad or useless, just expect your flow to take longer to run. And yes, there are also 10 other things that can slow it down, but again in the example above, they are not using conditions, file IO, complex calcs (Its all string amendments) or heavy computational stuff, they are just using variables to amend JSON strings. My answer was specific to the example given and my response was not based on the technicality, but my experience with using variables in flow.

 

@Alan_Sanchez you have have better luck using this guide to convert your csv into json, it uses a select / join action instead of variables and a loop, I have it in use in one of my flows and it regularly does 10,000+ records (csv to JSON) in a matter of 20-30 seconds. You may need to modify the replace commands to meet your needs, if you need help, let me know.
https://sharepains.com/2020/03/09/read-csv-files-from-sharepoint/

 

Thanks for the tip @Anonymous. I'll try this on my next flow where this is needed and share my feedback.

Helpful resources

Announcements

Community will be READ ONLY July 16th, 5p PDT -July 22nd

Dear Community Members,   We'd like to let you know of an upcoming change to the community platform: starting July 16th, the platform will transition to a READ ONLY mode until July 22nd.   During this period, members will not be able to Kudo, Comment, or Reply to any posts.   On July 22nd, please be on the lookout for a message sent to the email address registered on your community profile. This email is crucial as it will contain your unique code and link to register for the new platform encompassing all of the communities.   What to Expect in the New Community: A more unified experience where all products, including Power Apps, Power Automate, Copilot Studio, and Power Pages, will be accessible from one community.Community Blogs that you can syndicate and link to for automatic updates. We appreciate your understanding and cooperation during this transition. Stay tuned for the exciting new features and a seamless community experience ahead!

Summer of Solutions | Week 4 Results | Winners will be posted on July 24th

We are excited to announce the Summer of Solutions Challenge!    This challenge is kicking off on Monday, June 17th and will run for (4) weeks.  The challenge is open to all Power Platform (Power Apps, Power Automate, Copilot Studio & Power Pages) community members. We invite you to participate in a quest to provide solutions to as many questions as you can. Answers can be provided in all the communities.    Entry Period: This Challenge will consist of four weekly Entry Periods as follows (each an “Entry Period”)   - 12:00 a.m. PT on June 17, 2024 – 11:59 p.m. PT on June 23, 2024 - 12:00 a.m. PT on June 24, 2024 – 11:59 p.m. PT on June 30, 2024 - 12:00 a.m. PT on July 1, 2024 – 11:59 p.m. PT on July 7, 2024 - 12:00 a.m. PT on July 8, 2024 – 11:59 p.m. PT on July 14, 2024   Entries will be eligible for the Entry Period in which they are received and will not carryover to subsequent weekly entry periods.  You must enter into each weekly Entry Period separately.   How to Enter: We invite you to participate in a quest to provide "Accepted Solutions" to as many questions as you can. Answers can be provided in all the communities. Users must provide a solution which can be an “Accepted Solution” in the Forums in all of the communities and there are no limits to the number of “Accepted Solutions” that a member can provide for entries in this challenge, but each entry must be substantially unique and different.    Winner Selection and Prizes: At the end of each week, we will list the top ten (10) Community users which will consist of: 5 Community Members & 5 Super Users and they will advance to the final drawing. We will post each week in the News & Announcements the top 10 Solution providers.  At the end of the challenge, we will add all of the top 10 weekly names and enter them into a random drawing.  Then we will randomly select ten (10) winners (5 Community Members & 5 Super Users) from among all eligible entrants received across all weekly Entry Periods to receive the prize listed below. If a winner declines, we will draw again at random for the next winner.  A user will only be able to win once overall. If they are drawn multiple times, another user will be drawn at random.  Individuals will be contacted before the announcement with the opportunity to claim or deny the prize.  Once all of the winners have been notified, we will post in the News & Announcements of each community with the list of winners.   Each winner will receive one (1) Pass to the Power Platform Conference in Las Vegas, Sep. 18-20, 2024 ($1800 value). NOTE: Prize is for conference attendance only and any other costs such as airfare, lodging, transportation, and food are the sole responsibility of the winner. Tickets are not transferable to any other party or to next year’s event.   ** PLEASE SEE THE ATTACHED RULES for this CHALLENGE**   Week 1 Results: Congratulations to the Week 1 qualifiers, you are being entered in the random drawing that will take place at the end of the challenge.   Community MembersNumber SolutionsSuper UsersNumber Solutions Deenuji 9 @NathanAlvares24  17 @Anil_g  7 @ManishSolanki  13 @eetuRobo  5 @David_MA  10 @VishnuReddy1997  5 @SpongYe  9JhonatanOB19932 (tie) @Nived_Nambiar  8 @maltie  2 (tie)   @PA-Noob  2 (tie)   @LukeMcG  2 (tie)   @tgut03  2 (tie)       Week 2 Results: Congratulations to the Week 2 qualifiers, you are being entered in the random drawing that will take place at the end of the challenge. Week 2: Community MembersSolutionsSuper UsersSolutionsPower Automate  @Deenuji  12@ManishSolanki 19 @Anil_g  10 @NathanAlvares24  17 @VishnuReddy1997  6 @Expiscornovus  10 @Tjan  5 @Nived_Nambiar  10 @eetuRobo  3 @SudeepGhatakNZ 8     Week 3 Results: Congratulations to the Week 3 qualifiers, you are being entered in the random drawing that will take place at the end of the challenge. Week 3:Community MembersSolutionsSuper UsersSolutionsPower Automate Deenuji32ManishSolanki55VishnuReddy199724NathanAlvares2444Anil_g22SudeepGhatakNZ40eetuRobo18Nived_Nambiar28Tjan8David_MA22   Week 4 Results: Congratulations to the Week 4 qualifiers, you are being entered in the random drawing that will take place at the end of the challenge. Week 4:Community MembersSolutionsSuper UsersSolutionsPower Automate Deenuji11FLMike31Sayan11ManishSolanki16VishnuReddy199710creativeopinion14Akshansh-Sharma3SudeepGhatakNZ7claudiovc2CFernandes5 misc2Nived_Nambiar5 Usernametwice232rzaneti5 eetuRobo2   Anil_g2   SharonS2  

Check Out | 2024 Release Wave 2 Plans for Microsoft Dynamics 365 and Microsoft Power Platform

On July 16, 2024, we published the 2024 release wave 2 plans for Microsoft Dynamics 365 and Microsoft Power Platform. These plans are a compilation of the new capabilities planned to be released between October 2024 to March 2025. This release introduces a wealth of new features designed to enhance customer understanding and improve overall user experience, showcasing our dedication to driving digital transformation for our customers and partners.    The upcoming wave is centered around utilizing advanced AI and Microsoft Copilot technologies to enhance user productivity and streamline operations across diverse business applications. These enhancements include intelligent automation, AI-powered insights, and immersive user experiences that are designed to break down barriers between data, insights, and individuals. Watch a summary of the release highlights.    Discover the latest features that empower organizations to operate more efficiently and adaptively. From AI-driven sales insights and customer service enhancements to predictive analytics in supply chain management and autonomous financial processes, the new capabilities enable businesses to proactively address challenges and capitalize on opportunities.    

Updates to Transitions in the Power Platform Communities

We're embarking on a journey to enhance your experience by transitioning to a new community platform. Our team has been diligently working to create a fresh community site, leveraging the very Dynamics 365 and Power Platform tools our community advocates for.  We started this journey with transitioning Copilot Studio forums and blogs in June. The move marks the beginning of a new chapter, and we're eager for you to be a part of it. The rest of the Power Platform product sites will be moving over this summer.   Stay tuned for more updates as we get closer to the launch. We can't wait to welcome you to our new community space, designed with you in mind. Let's connect, learn, and grow together.   Here's to new beginnings and endless possibilities!   If you have any questions, observations or concerns throughout this process please go to https://aka.ms/PPCommSupport.   To stay up to date on the latest details of this migration and other important Community updates subscribe to our News and Announcements forums: Copilot Studio, Power Apps, Power Automate, Power Pages

Users online (1,519)