Forum Discussion
Stopping Spark Session inside/outside ForEach
- 2 years ago
Yes, it sounds like the best option is to not use ForEach in this case, instead have a master notebook and execute all other notebook runs from the master notebook.
Look for mssparkutils.notebook.run(), mssparkutils.notebook.runMultiple() or Threadpooling in the Reddit discussion:
https://www.reddit.com/r/MicrosoftFabric/comments/1eolfda/sparkstop_is_it_needed/.
I noticed mssparkutils.notebook.runMultiple() is a preview feature. I haven't checked the status of the other mentioned features.
Also, I think mssparkutils will be replaced by notebookutils going forward:
NotebookUtils (former MSSparkUtils) for Fabric - Microsoft Fabric | Microsoft Learn
Microsoft Spark Utilities (MSSparkUtils) for Fabric - Microsoft Fabric | Microsoft Learn
I started a discussion on Reddit to try to learn more about the topic:
spark.stop() - is it needed? : r/MicrosoftFabric (reddit.com)
I also noticed there is an alterantive to spark.stop(), which is mssparkutils.session.stop()
Anyway, I'm not sure if it's necessary.
I am still not entirely sure what to believe regarding session start/stop in Fabric.
There is also the option to use a Master notebook and use that notebook to call other notebooks. Then I think you can share the same session among notebooks. I think this approach utilizes the high concurrency feature.
EDIT: I think the Reddit discussion has made me understand more about it. I recommend checking out the Reddit discussion (link above).
frithjof_v thanks for this.
High concurrency is not shipped yet(off-topic)
Therefore, if measures are not taken for a large_array, the pipeline will error out if you are calling a notebook inside forEach for a large array to perform operation on the same table. E.g.
//pseudo code
const large_array = [1,2,...20]
//updates to be utilize in upsert
const updates = updates
//target
const target = delta_fact
//forEach activity in pipeline sequntial execution on a subset of target
forEach eleemnt of large_array {
perform Delta Table Merge sequentially
where each large_array[element] = target[element]
}
- frithjof_v2 years agoCommunity Champion
Yes, it sounds like the best option is to not use ForEach in this case, instead have a master notebook and execute all other notebook runs from the master notebook.
Look for mssparkutils.notebook.run(), mssparkutils.notebook.runMultiple() or Threadpooling in the Reddit discussion:
https://www.reddit.com/r/MicrosoftFabric/comments/1eolfda/sparkstop_is_it_needed/.
I noticed mssparkutils.notebook.runMultiple() is a preview feature. I haven't checked the status of the other mentioned features.
Also, I think mssparkutils will be replaced by notebookutils going forward:
NotebookUtils (former MSSparkUtils) for Fabric - Microsoft Fabric | Microsoft Learn
Microsoft Spark Utilities (MSSparkUtils) for Fabric - Microsoft Fabric | Microsoft Learn