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.

DenisMolodtsov
Kudo Kingpin
Kudo Kingpin

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.

 
Alan_Sanchez
Helper II
Helper II

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

bouillons
Helper V
Helper V

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

 

bouillons
Helper V
Helper V

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!

Paulie78
Super User
Super User

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 Roundup: A Look Back at Our Last 10 Tuesday Tips

As we continue to grow and learn together, it's important to reflect on the valuable insights we've shared. For today's #TuesdayTip, we're excited to take a moment to look back at the last 10 tips we've shared in case you missed any or want to revisit them. Thanks for your incredible support for this series--we're so glad it was able to help so many of you navigate your community experience!   Getting Started in the Community An overview of everything you need to know about navigating the community on one page!  Community Links: ○ Power Apps ○ Power Automate  ○ Power Pages  ○ Copilot Studio    Community Ranks and YOU Have you ever wondered how your fellow community members ascend the ranks within our community? We explain everything about ranks and how to achieve points so you can climb up in the rankings! Community Links: ○ Power Apps ○ Power Automate  ○ Power Pages  ○ Copilot Studio    Powering Up Your Community Profile Your Community User Profile is how the Community knows you--so it's essential that it works the way you need it to! From changing your username to updating contact information, this Knowledge Base Article is your best resource for powering up your profile. Community Links: ○ Power Apps ○ Power Automate  ○ Power Pages  ○ Copilot Studio    Community Blogs--A Great Place to Start There's so much you'll discover in the Community Blogs, and we hope you'll check them out today!  Community Links: ○ Power Apps ○ Power Automate  ○ Power Pages  ○ Copilot Studio    Unlocking Community Achievements and Earning Badges Across the Communities, you'll see badges on users profile that recognize and reward their engagement and contributions. Check out some details on Community badges--and find out more in the detailed link at the end of the article! Community Links: ○ Power Apps  ○ Power Automate  ○ Power Pages  ○ Copilot Studio    Blogging in the Community Interested in blogging? Everything you need to know on writing blogs in our four communities! Get started blogging across the Power Platform communities today! Community Links: ○ Power Apps  ○ Power Automate  ○ Power Pages  ○ Copilot Studio   Subscriptions & Notifications We don't want you to miss a thing in the community! Read all about how to subscribe to sections of our forums and how to setup your notifications! Community Links: ○ Power Apps  ○ Power Automate  ○ Power Pages  ○ Copilot Studio   Getting Started with Private Messages & Macros Do you want to enhance your communication in the Community and streamline your interactions? One of the best ways to do this is to ensure you are using Private Messaging--and the ever-handy macros that are available to you as a Community member! Community Links: ○ Power Apps  ○ Power Automate  ○ Power Pages  ○ Copilot Studio   Community User Groups Learn everything about being part of, starting, or leading a User Group in the Power Platform Community. Community Links: ○ Power Apps  ○ Power Automate  ○ Power Pages  ○ Copilot Studio   Update Your Community Profile Today! Keep your community profile up to date which is essential for staying connected and engaged with the community. Community Links: ○ Power Apps  ○ Power Automate  ○ Power Pages  ○ Copilot Studio   Thank you for being an integral part of our journey.   Here's to many more Tuesday Tips as we pave the way for a brighter, more connected future! As always, watch the News & Announcements for the next set of tips, coming soon!    

Calling all User Group Leaders and Super Users! Mark Your Calendars for the next Community Ambassador Call on May 9th!

This month's Community Ambassador call is on May 9th at 9a & 3p PDT. Please keep an eye out in your private messages and Teams channels for your invitation. There are lots of exciting updates coming to the Community, and we have some exclusive opportunities to share with you! As always, we'll also review regular updates for User Groups, Super Users, and share general information about what's going on in the Community.     Be sure to register & we hope to see all of you there!

April 2024 Community Newsletter

We're pleased to share the April Community Newsletter, where we highlight the latest news, product releases, upcoming events, and the amazing work of our outstanding Community members.   If you're new to the Community, please make sure to follow the latest News & Announcements and check out the Community on LinkedIn as well! It's the best way to stay up-to-date with all the news from across Microsoft Power Platform and beyond.    COMMUNITY HIGHLIGHTS   Check out the most active community members of the last month! These hardworking members are posting regularly, answering questions, kudos, and providing top solutions in their communities. We are so thankful for each of you--keep up the great work! If you hope to see your name here next month, follow these awesome community members to see what they do!   Power AppsPower AutomateCopilot StudioPower PagesWarrenBelzDeenujialexander2523ragavanrajanLaurensMManishSolankiMattJimisonLucas001AmikcapuanodanilostephenrobertOliverRodriguestimlAndrewJManikandanSFubarmmbr1606VishnuReddy1997theMacResolutionsVishalJhaveriVictorIvanidzejsrandhawahagrua33ikExpiscornovusFGuerrero1PowerAddictgulshankhuranaANBExpiscornovusprathyooSpongYeNived_Nambiardeeksha15795apangelesGochixgrantjenkinsvasu24Mfon   LATEST NEWS   Business Applications Launch Event - On Demand In case you missed the Business Applications Launch Event, you can now catch up on all the announcements and watch the entire event on-demand inside Charles Lamanna's latest cloud blog.   This is your one stop shop for all the latest Copilot features across Power Platform and #Dynamics365, including first-hand looks at how companies such as Lenovo, Sonepar, Ford Motor Company, Omnicom and more are using these new capabilities in transformative ways. Click the image below to watch today!   Power Platform Community Conference 2024 is here! It's time to look forward to the next installment of the Power Platform Community Conference, which takes place this year on 18-20th September 2024 at the MGM Grand in Las Vegas!   Come and be inspired by Microsoft senior thought leaders and the engineers behind the #PowerPlatform, with Charles Lamanna, Sangya Singh, Ryan Cunningham, Kim Manis, Nirav Shah, Omar Aftab and Leon Welicki already confirmed to speak. You'll also be able to learn from industry experts and Microsoft MVPs who are dedicated to bridging the gap between humanity and technology. These include the likes of Lisa Crosbie, Victor Dantas, Kristine Kolodziejski, David Yack, Daniel Christian, Miguel Félix, and Mats Necker, with many more to be announced over the coming weeks.   Click here to watch our brand-new sizzle reel for #PPCC24 or click the image below to find out more about registration. See you in Vegas!       Power Up Program Announces New Video-Based Learning Hear from Principal Program Manager, Dimpi Gandhi, to discover the latest enhancements to the Microsoft #PowerUpProgram. These include a new accelerated video-based curriculum crafted with the expertise of Microsoft MVPs, Rory Neary and Charlie Phipps-Bennett. If you’d like to hear what’s coming next, click the image below to find out more!   UPCOMING EVENTS Microsoft Build - Seattle and Online - 21-23rd May 2024 Taking place on 21-23rd May 2024 both online and in Seattle, this is the perfect event to learn more about low code development, creating copilots, cloud platforms, and so much more to help you unleash the power of AI.   There's a serious wealth of talent speaking across the three days, including the likes of Satya Nadella, Amanda K. Silver, Scott Guthrie, Sarah Bird, Charles Lamanna, Miti J., Kevin Scott, Asha Sharma, Rajesh Jha, Arun Ulag, Clay Wesener, and many more.   And don't worry if you can't make it to Seattle, the event will be online and totally free to join. Click the image below to register for #MSBuild today!   European Collab Summit - Germany - 14-16th May 2024 The clock is counting down to the amazing European Collaboration Summit, which takes place in Germany May 14-16, 2024. #CollabSummit2024 is designed to provide cutting-edge insights and best practices into Power Platform, Microsoft 365, Teams, Viva, and so much more. There's a whole host of experts speakers across the three-day event, including the likes of Vesa Juvonen, Laurie Pottmeyer, Dan Holme, Mark Kashman, Dona Sarkar, Gavin Barron, Emily Mancini, Martina Grom, Ahmad Najjar, Liz Sundet, Nikki Chapple, Sara Fennah, Seb Matthews, Tobias Martin, Zoe Wilson, Fabian Williams, and many more.   Click the image below to find out more about #ECS2024 and register today!     Microsoft 365 & Power Platform Conference - Seattle - 3-7th June If you're looking to turbo boost your Power Platform skills this year, why not take a look at everything TechCon365 has to offer at the Seattle Convention Center on June 3-7, 2024.   This amazing 3-day conference (with 2 optional days of workshops) offers over 130 sessions across multiple tracks, alongside 25 workshops presented by Power Platform, Microsoft 365, Microsoft Teams, Viva, Azure, Copilot and AI experts. There's a great array of speakers, including the likes of Nirav Shah, Naomi Moneypenny, Jason Himmelstein, Heather Cook, Karuana Gatimu, Mark Kashman, Michelle Gilbert, Taiki Y., Kristi K., Nate Chamberlain, Julie Koesmarno, Daniel Glenn, Sarah Haase, Marc Windle, Amit Vasu, Joanne C Klein, Agnes Molnar, and many more.   Click the image below for more #Techcon365 intel and register today!     For more events, click the image below to visit the Microsoft Community Days website.      

Tuesday Tip | Update Your Community Profile Today!

It's time for another TUESDAY TIPS, your weekly connection with the most insightful tips and tricks that empower both newcomers and veterans in the Power Platform Community! Every Tuesday, we bring you a curated selection of the finest advice, distilled from the resources and tools in the Community. Whether you’re a seasoned member or just getting started, Tuesday Tips are the perfect compass guiding you across the dynamic landscape of the Power Platform Community.   We're excited to announce that updating your community profile has never been easier! Keeping your profile up to date is essential for staying connected and engaged with the community.   Check out the following Support Articles with these topics: Accessing Your Community ProfileRetrieving Your Profile URLUpdating Your Community Profile Time ZoneChanging Your Community Profile Picture (Avatar)Setting Your Date Display Preferences Click on your community link for more information: Power Apps, Power Automate, Power Pages, Copilot Studio   Thank you for being an active part of our community. Your contributions make a difference! Best Regards, The Community Management Team

Hear what's next for the Power Up Program

Hear from Principal Program Manager, Dimpi Gandhi, to discover the latest enhancements to the Microsoft #PowerUpProgram, including a new accelerated video-based curriculum crafted with the expertise of Microsoft MVPs, Rory Neary and Charlie Phipps-Bennett. If you’d like to hear what’s coming next, click the link below to sign up today! https://aka.ms/PowerUp  

Super User of the Month | Ahmed Salih

We're thrilled to announce that Ahmed Salih is our Super User of the Month for April 2024. Ahmed has been one of our most active Super Users this year--in fact, he kicked off the year in our Community with this great video reminder of why being a Super User has been so important to him!   Ahmed is the Senior Power Platform Architect at Saint Jude's Children's Research Hospital in Memphis. He's been a Super User for two seasons and is also a Microsoft MVP! He's celebrating his 3rd year being active in the Community--and he's received more than 500 kudos while authoring nearly 300 solutions. Ahmed's contributions to the Super User in Training program has been invaluable, with his most recent session with SUIT highlighting an incredible amount of best practices and tips that have helped him achieve his success.   Ahmed's infectious enthusiasm and boundless energy are a key reason why so many Community members appreciate how he brings his personality--and expertise--to every interaction. With all the solutions he provides, his willingness to help the Community learn more about Power Platform, and his sheer joy in life, we are pleased to celebrate Ahmed and all his contributions! You can find him in the Community and on LinkedIn. Congratulations, Ahmed--thank you for being a SUPER user!

Users online (4,305)