Performance check between For loop and Destination Rule – Plan per Slot (No Destinations) with dynamic slot count.

Performance check between  For loop and Destination Rule – Plan per Slot (No Destinations) with dynamic slot count.

In practical scenarios, we come across the situation where we need to perform the task for number of users or a specific number of time. For such scenarios, we need to iterate for each item so that we can take required action for them.

For example I would like to add details for number of products returned by SMO. As number of products returned by SMO can be more than one, so I need to iterate for each item returned by SMO and then add it’s details in table.

Now question is how we can achieve this?
Obviously by using “for loop”.

As a Techie, while coding or designing My basic responsibilities are to provide efficient, reliable and fast execution code.

Execution time of code doesn’t matter for some applications, but some time it affects performance. So, we always need to look around for other possible solutions.

But is there a way around without for loop?
Answer is Yes. Using Destination Rule (Plan Per Slot – no Destinations)

So, I can do this using any one of the following two ways:

  • ForEach loop
  • Destination Rule (Plan Per Slot – no Destinations)

As I previously told I need more efficient solution for my problem. So let’s check with small Workflow, which one is more efficient.

I have designed a workflow having both for loop and Using Destination Rule (Plan Per Slot – no Destinations), to perform comparison on execution time taken by each.

Img1

Activity 1:  This activity Records the time stamp which I am going to use as start time for my “for loop”.

Activity 2:  This activity has For loop event which get source from SMO and returns two Outcomes based on received result from SMO.

Img2

Activity 3:  This activity records the products details into table (here with products name I am passing time stamp so that we can trace it exactly time taken by each iteration)

Img3.jpg

 Activity 4: This activity records the time stamp, which I will use as End time for my “for loop” and Start time for “Destination Rule”.

Activity 5: This activity has “Destination Rule Plan per slot (no Destinations).

(To enable this option please check advanced option and click next)

In destination Rule, I have selected option “select a list field to determine how many slots should be created.”  And used same SMO which was used in “for loop” (gives returns the list of products).

 Img4

Now I am required to record All products details to table. And to achieve same, I have used SMO event where I am passing every product details to SMO event so that it can be recorded in Audit table.

Accessed items in Instance Data Field under tab Activity Destination Instance in Workflow Context Browser.

 Img5.jpg

Activity 6: This activity records the time stamp, which I will use as End time for “Destination Rule”.

 

Conclusion:

After running It I got below results, With Execution time difference in both

For loop have took 5 seconds to log 10 items to data base where as the other method Destination Rule method took just 1 second to log 10 items.

So conclusion here is Destination Rule method is much faster than for loop.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s