I am trying to reduce my script runtime, because I got the error timeout 10:00 on Azure Functions Consumption Plan (my current runtime is 16 minutes).
My question:
If I use Durable Functions Fan In/Out to divide executing task in multiple executions parallel, it will reduce my runtime ?
My possible solution (doubt):
If I divide my database update in parts and execute all in parallel yield context.df.Task.all(parallelTasks);
, this time will reduce?
const df = require("durable-functions");
module.exports = df.orchestrator(function*(context) {
const parallelTasks = [];
// Get a list of N work items to process in parallel.
const workBatch = yield context.df.callActivity("getDatabaseInformations");
for (let i = 0; i < workBatch.length; i ) {
parallelTasks.push(context.df.callActivity("updateMyDatabase", workBatch[i]));
}
yield context.df.Task.all(parallelTasks);
});
CodePudding user response:
In general Azure Functions Premium allow for higher timeout values. So, if you don't want to deal with the issue, just upgrade ;-)
Azure Durable Functions might or might not reduce your total runtime. BUT every "Activity Call" is a new function execution with an own timeout.
Either Fanning out or even calling activities it in serial will prevent timeout issue as long the called activity will not extend the timeout period for functions.
If, however you have an activity which will run for an extended period, you will need premium functions anyway. But your solution with "batch" processing looks quite promising to avoid this.
CodePudding user response:
Making use of the fan-out/fan-in approach, you will run tasks in parallel instead of sequentially so the duration of the execution will be the duration of your longest single task to execute. It's the best approach to use if the requests do not require information from each other to process.
You could make use of Task Asynchronous Programming (TAP) to build tasks, call relevant methods and wait for all tasks to finish if you don't want them to be on Durable Functions