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

Exclusive LIVE Community Event: Power Apps Copilot Coffee Chat with Copilot Studio Product Team

It's time for the SECOND Power Apps Copilot Coffee Chat featuring the Copilot Studio product team, which will be held LIVE on April 3, 2024 at 9:30 AM Pacific Daylight Time (PDT).     This is an incredible opportunity to connect with members of the Copilot Studio product team and ask them anything about Copilot Studio. We'll share our special guests with you shortly--but we want to encourage to mark your calendars now because you will not want to miss the conversation.   This live event will give you the unique opportunity to learn more about Copilot Studio plans, where we’ll focus, and get insight into upcoming features. We’re looking forward to hearing from the community, so bring your questions!   TO GET ACCESS TO THIS EXCLUSIVE AMA: Kudo this post to reserve your spot! Reserve your spot now by kudoing this post.  Reservations will be prioritized on when your kudo for the post comes through, so don't wait! Click that "kudo button" today.   Invitations will be sent on April 2nd.Users posting Kudos after April 2nd at 9AM PDT may not receive an invitation but will be able to view the session online after conclusion of the event. Give your "kudo" today and mark your calendars for April 3, 2024 at 9:30 AM PDT and join us for an engaging and informative session!

Tuesday Tip: Unlocking Community Achievements and Earning Badges

TUESDAY TIPS are our way of communicating helpful things we've learned or shared that have helped members of the Community. Whether you're just getting started or you're a seasoned pro, Tuesday Tips will help you know where to go, what to look for, and navigate your way through the ever-growing--and ever-changing--world of the Power Platform Community! We cover basics about the Community, provide a few "insider tips" to make your experience even better, and share best practices gleaned from our most active community members and Super Users.   With so many new Community members joining us each week, we'll also review a few of our "best practices" so you know just "how" the Community works, so make sure to watch the News & Announcements each week for the latest and greatest Tuesday Tips!     THIS WEEK'S TIP: Unlocking Achievements and Earning BadgesAcross the Communities, you'll see badges on users profile that recognize and reward their engagement and contributions. These badges each signify a different achievement--and all of those achievements are available to any Community member! If you're a seasoned pro or just getting started, you too can earn badges for the great work you do. Check out some details on Community badges below--and find out more in the detailed link at the end of the article!       A Diverse Range of Badges to Collect The badges you can earn in the Community cover a wide array of activities, including: Kudos Received: Acknowledges the number of times a user’s post has been appreciated with a “Kudo.”Kudos Given: Highlights the user’s generosity in recognizing others’ contributions.Topics Created: Tracks the number of discussions initiated by a user.Solutions Provided: Celebrates the instances where a user’s response is marked as the correct solution.Reply: Counts the number of times a user has engaged with community discussions.Blog Contributor: Honors those who contribute valuable content and are invited to write for the community blog.       A Community Evolving Together Badges are not only a great way to recognize outstanding contributions of our amazing Community members--they are also a way to continue fostering a collaborative and supportive environment. As you continue to share your knowledge and assist each other these badges serve as a visual representation of your valuable contributions.   Find out more about badges in these Community Support pages in each Community: All About Community Badges - Power Apps CommunityAll About Community Badges - Power Automate CommunityAll About Community Badges - Copilot Studio CommunityAll About Community Badges - Power Pages Community

Tuesday Tips: Powering Up Your Community Profile

TUESDAY TIPS are our way of communicating helpful things we've learned or shared that have helped members of the Community. Whether you're just getting started or you're a seasoned pro, Tuesday Tips will help you know where to go, what to look for, and navigate your way through the ever-growing--and ever-changing--world of the Power Platform Community! We cover basics about the Community, provide a few "insider tips" to make your experience even better, and share best practices gleaned from our most active community members and Super Users.   With so many new Community members joining us each week, we'll also review a few of our "best practices" so you know just "how" the Community works, so make sure to watch the News & Announcements each week for the latest and greatest Tuesday Tips!   This Week's Tip: Power Up Your Profile!  🚀 It's where every Community member gets their start, and it's essential that you keep it updated! Your Community User Profile is how you're able to get messages, post solutions, ask questions--and as you rank up, it's where your badges will appear and how you'll be known when you start blogging in the Community Blog. 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.     Password Puzzles? No Problem! Find out how to sync your Azure AD password with your community account, ensuring a seamless sign-in. No separate passwords to remember! Job Jumps & Email Swaps Changed jobs? Got a new email? Fear not! You'll find out how to link your shiny new email to your existing community account, keeping your contributions and connections intact. Username Uncertainties Unraveled Picking the perfect username is crucial--and sometimes the original choice you signed up with doesn't fit as well as you may have thought. There's a quick way to request an update here--but remember, your username is your community identity, so choose wisely. "Need Admin Approval" Warning Window? If you see this error message while using the community, don't worry. A simple process will help you get where you need to go. If you still need assistance, find out how to contact your Community Support team. Whatever you're looking for, when it comes to your profile, the Community Account Support Knowledge Base article is your treasure trove of tips as you navigate the nuances of your Community Profile. It’s the ultimate resource for keeping your digital identity in tip-top shape while engaging with the Power Platform Community. So, dive in and power up your profile today!  💪🚀   Community Account Support | Power Apps Community Account Support | Power AutomateCommunity Account Support | Copilot Studio  Community Account Support | Power Pages

Super User of the Month | Chris Piasecki

In our 2nd installment of this new ongoing feature in the Community, we're thrilled to announce that Chris Piasecki is our Super User of the Month for March 2024. If you've been in the Community for a while, we're sure you've seen a comment or marked one of Chris' helpful tips as a solution--he's been a Super User for SEVEN consecutive seasons!   Since authoring his first reply in April 2020 to his most recent achievement organizing the Canadian Power Platform Summit this month, Chris has helped countless Community members with his insights and expertise. In addition to being a Super User, Chris is also a User Group leader, Microsoft MVP, and a featured speaker at the Microsoft Power Platform Conference. His contributions to the new SUIT program, along with his joyous personality and willingness to jump in and help so many members has made Chris a fixture in the Power Platform Community.   When Chris isn't authoring solutions or organizing events, he's actively leading Piasecki Consulting, specializing in solution architecture, integration, DevOps, and more--helping clients discover how to strategize and implement Microsoft's technology platforms. We are grateful for Chris' insightful help in the Community and look forward to even more amazing milestones as he continues to assist so many with his great tips, solutions--always with a smile and a great sense of humor.You can find Chris in the Community and on LinkedIn. Thanks for being such a SUPER user, Chris! 💪 🌠  

Tuesday Tips: Community Ranks and YOU

TUESDAY TIPS are our way of communicating helpful things we've learned or shared that have helped members of the Community. Whether you're just getting started or you're a seasoned pro, Tuesday Tips will help you know where to go, what to look for, and navigate your way through the ever-growing--and ever-changing--world of the Power Platform Community! We cover basics about the Community, provide a few "insider tips" to make your experience even better, and share best practices gleaned from our most active community members and Super Users.   With so many new Community members joining us each week, we'll also review a few of our "best practices" so you know just "how" the Community works, so make sure to watch the News & Announcements each week for the latest and greatest Tuesday Tips!This Week: Community Ranks--Moving from "Member" to "Community Champion"   Have you ever wondered how your fellow community members ascend the ranks within our community? What sets apart an Advocate from a Helper, or a Solution Sage from a Community Champion? In today’s #TuesdayTip, we’re unveiling the secrets and sharing tips to help YOU elevate your ranking—and why it matters to our vibrant communities. Community ranks serve as a window into a member’s role and activity. They celebrate your accomplishments and reveal whether someone has been actively contributing and assisting others. For instance, a Super User is someone who has been exceptionally helpful and engaged. Some ranks even come with special permissions, especially those related to community management. As you actively participate—whether by creating new topics, providing solutions, or earning kudos—your rank can climb. Each time you achieve a new rank, you’ll receive an email notification. Look out for the icon and rank name displayed next to your username—it’s a badge of honor! Fun fact: Your Community Engagement Team keeps an eye on these ranks, recognizing the most passionate and active community members. So shine brightly with valuable content, and you might just earn well-deserved recognition! Where can you see someone’s rank? When viewing a post, you’ll find a member’s rank to the left of their name.Click on a username to explore their profile, where their rank is prominently displayed. What about the ranks themselves? New members start as New Members, progressing to Regular Visitors, and then Frequent Visitors.Beyond that, we have a categorized system: Kudo Ranks: Earned through kudos (teal icons).Post Ranks: Based on your posts (purple icons).Solution Ranks: Reflecting your solutions (green icons).Combo Ranks: These orange icons combine kudos, solutions, and posts. The top ranks have unique names, making your journey even more exciting! So dive in, collect those kudos, share solutions, and let’s see how high you can rank!  🌟 🚀   Check out the Using the Community boards in each of the communities for more helpful information!  Power Apps, Power Automate, Copilot Studio & Power Pages

Find Out What Makes Super Users So Super

We know many of you visit the Power Platform Communities to ask questions and receive answers. But do you know that many of our best answers and solutions come from Community members who are super active, helping anyone who needs a little help getting unstuck with Business Applications products? We call these dedicated Community members Super Users because they are the real heroes in the Community, willing to jump in whenever they can to help! Maybe you've encountered them yourself and they've solved some of your biggest questions. Have you ever wondered, "Why?"We interviewed several of our Super Users to understand what drives them to help in the Community--and discover the difference it has made in their lives as well! Take a look in our gallery today: What Motivates a Super User? - Power Platform Community (microsoft.com)

Users online (6,466)