37
votes

Is there a way to change the current 5 minutes timeout limit for Azure Functions running under the Consumption plan ?

For some data analytics computations 5 minutes is not enough time.

The alternative of using webjobs doesn't allow parallel execution of the function.

3
Changed the answer to 10 min as this option was added to the servicedonquijote

3 Answers

61
votes

(Other answer is a bit confusing, so writing instead of editing a lot)

Azure Functions can now run up to 10 minutes using the consumption plan by adding the functionTimeout setting to your host.json file:

In a serverless Consumption plan, the valid range is from 1 second to 10 minutes, and the default value is 5 minutes.

In both Premium and Dedicated (App Service) plans, there is no overall limit, and the default value is 30 minutes. A value of -1 indicates unbounded execution, but keeping a fixed upper bound is recommended

Source: https://docs.microsoft.com/en-us/azure/azure-functions/functions-host-json#functiontimeout

File: host.json

// Value indicating the timeout duration for all functions.
// Set functionTimeout to 10 minutes
{
    "functionTimeout": "00:10:00"
}

Source:
https://buildazure.com/2017/08/17/azure-functions-extend-execution-timeout-past-5-minutes/
https://github.com/Azure/azure-webjobs-sdk-script/wiki/host.json

9
votes

Currently there's no way to have a function running for more than 5 minutes on Consumption plan. You can check the team's answer in here:

The reason we timeout at 5 minutes with the Dynamic plan is because under the Dynamic plan, the VM that is hosting your function will shut down (roughly) 5 minutes after the last trigger fired. Enforcing the timeout like we're doing today is a way to provide a consistent experience with logging that explains why the function stopped running. Before this, you would see functions simply disappear mid-invocation without any indication of why. We're evaluating improvements in this area and will update when we have more concrete details.

Long-running functions that cannot be decomposed down into smaller chunks will run into issues running in the Dynamic plan currently. However, there are often solutions for breaking down single long-running functions into smaller, quicker functions. For example, if you have a function that kicks off a long operation elsewhere, then polls for completion, could you get an 'operationId' from that operation, then put it in a Service Bus scheduled message (or even in a Queue message with an invisibility timeout), and have a second 'CheckStatus' function that reads those messages and polls for completion

https://github.com/Azure/azure-webjobs-sdk-script/issues/18

and also https://github.com/Azure/Azure-Functions/issues/75

UPDATE

Azure Functions can now run up to 10 minutes using the consumption plan: https://docs.microsoft.com/en-us/azure/azure-functions/functions-host-json#functiontimeout

0
votes

Here the complete host.json, recarding to the Microsoft Docs:

Don't forget to restart the Function to reload the Configuration!

{
   "version":"2.0",
   "managedDependency":{
      "Enabled":true
   },
   "extensionBundle":{
      "id":"Microsoft.Azure.Functions.ExtensionBundle",
      "version":"[2.*, 3.0.0)"
   },
   "functionTimeout": "00:05:00"
}

Another trick is, only to define the required Az-Modules in requirements.psd1 and not all of them:

Bad:

# This file enables modules to be automatically managed by the Functions service.
# See https://aka.ms/functionsmanageddependency for additional information.
#
@{
    # For latest supported version, go to 'https://www.powershellgallery.com/packages/Az'. 
    # To use the Az module in your function app, please uncomment the line below.
    'Az' = '6.*'
}

Good:

# This file enables modules to be automatically managed by the Functions service.
# See https://aka.ms/functionsmanageddependency for additional information.
#
@{
    # For latest supported version, go to 'https://www.powershellgallery.com/packages/Az'. 
    # To use the Az module in your function app, please uncomment the line below.
    # 'Az' = '6.*'
    'Az.Accounts'  = '2.*'
    'Az.Resources' = '4.*'
    'Az.Monitor'   = '2.*'
}