12

I've just noticed recently, that Azure functions acquired a 5 min timeout on the dynamic pricing tier somewhere along the timeline. As I've been busy doing other things, this flew under my radar, until I noticed some long running functions not completing.

So I went digging, and found out that there are two pricing tiers - the dynamic and the app service based. The site is a bit vague on the whole concept, but as I understand it, this is how it stands:

Dynamic: Charged per usage time and memory allocation by the user. 5 minute timeout (so useless for one time long running operations now).

App service: Either a basic or standard tier VM, running full time, waiting for triggers. No timeout to speak of.

Now the first disappoints me, as I saw functions as a solution for my jobs that need to be fired once or twice per year, but then take a day or two to complete (comprehensive backup and data packaging for export).

The second confuses me - does this mean, that the stateless function now runs as a web app and I am to be charged for it as such? If this is the case, the whole concept of functions is now useless for my purposes, unless I implement a Cell processor, firing 80000 function instances upon a trigger to get the work done on time. If that's even possible.

Could someone please explain the model behind Functions pricing and what the best solution for my problem would be?

Thank you.

JasonX
  • 461
  • 5
  • 16
  • 1
    What's the point of using Functions for something that runs once or twice a year and takes days?? You are *not* taking advantage of pay-what-you-use this way – Panagiotis Kanavos Nov 25 '16 at 17:07
  • I agree with @PanagiotisKanavos, that's not what Azure Functions is made for. Also see https://docs.microsoft.com/en-us/azure/azure-functions/functions-best-practices – Kai Walter Nov 27 '16 at 15:08
  • 2
    @KaiWalter, let me clarify - it's not a long running process that occurs annually, it's _expected_ to occur annually. It might occur three times in the next five minutes, or never in the next five years. It is a user demanded large task, and as such, it makes no sense to pay for a computational resource to stand by all the time, as we only need it on demand. And that is (or at least was) one of the ideas behind Functions at some point. Apart from dirty hacks (creating a service, running it, then disposing after completion), is there an alternative? – JasonX Nov 28 '16 at 07:05
  • 2
    Just as a +1 for the original question - I have a task that runs with an unknown regularity and can take over an hour. In all other regards it's a perfect job for functions - it's transforming a dataset into a different format and saving it in a storage bucket for later download. If I'm paying for the compute resources, why on earth should there be an arbitrary five minute maximum? – Chris Rae Mar 11 '17 at 06:28

4 Answers4

4

The Azure Batch Service is what you're after.

Basically, you can spin up the compute resources required, when required - and you only pay for the compute time that you use, the Batch Service itself (which provides all sorts of goodness such as error detection, retries, automatic scaling) does not incur an additional charge. (It has its own API, by the way - so you can completely automate it, if required)

You can install custom software on each VM in the pool before it starts performing work.

You can let the batch service scale automatically based on a customisable rule, or you can just create a pool of a fixed size and scale it manually.

https://azure.microsoft.com/en-gb/services/batch/

Update - according to comments on this GitHub issue, if your Function App is using an existing App Service Plan, then the timeout doesn't apply. Seemingly, the dynamic option or "Consumption Plan" timeout is to do with the timeout of underlying platform VM instances. So, that might be another route: pay for an app service plan, then you get to use Function App goodness without timeouts.

Nathan
  • 5,729
  • 2
  • 29
  • 60
1

Functions are designed to handle short tasks (under 5 minutes). But there are workarounds. You can create an ARM Template to deploy a Function App with a Web App service Tier and delete it after the processing is done. You can use webjobs instead of functions (but you still have to pay for the Web App).

Nathan
  • 5,729
  • 2
  • 29
  • 60
4c74356b41
  • 59,484
  • 5
  • 63
  • 109
1

As someone on this thread said you should try looking at azure automation or something if your process is less frequently used and moreover takes a days to complete.

Without knowning exactly the scale (# of files / source and destination of file and backup) You could break the solution into smaller chunks (tasks => functions) and deploy the chunks in separate app plans

  1. Master

    • This would be responsible for figuring out a roster of line items that need to be backed-up.
    • The master would simply raise a ticket in a queue or do a http ping to a worker.
    • This master function then can be deployed in a what is called "Application Service Plan" and can run for more than 5 minutes!!
  2. Worker

    • This would be actually responsible for backup of a single unit of work.
    • This worker function can be deployed into a what is now called as a "Consumption Plan" previously known as "Dynamic Plan".
    • On a consumption plan (AFAIK) you could have 32 instance of the azure function running in parallel.
    • You can even clone the worker function app thereby take backup of 32/64/128 work units in parallel

It makes complete sense from a monetary point of view that on a Consumption Plan where you are charged by the about of Gb/s (memory and time of execution used) that the host prevents long running executions from happening.

Hope this helps

frictionlesspulley
  • 8,030
  • 12
  • 59
  • 102
1

This thread deserves a bit more clarity. Firstly, If your function call takes some time to complete, you are going to want it to be async. Secondly, If you do make it async, it will not timeout after 5 mins.

Give it a shot :P

DateTime d = DateTime.Now;
Task t = new Task(() =>
{
    log.Info("Doing long task");
    for (int cnt = 0; cnt < 100; cnt++)
    {
        log.Info(DateTime.Now.Subtract(d).ToString());
        System.Threading.Thread.Sleep(10000);
    }
});
t.Start();

I am currently running them on a consumption plan for more than 5 mins, as per my post. There is a timeout, but it’s not on execution time obviously since I am running them longer than 5 mins. The time out is in the calling mechanism that executes the function. If you make it async, the caller returns and the function continues to execute. It is a common practice to put long running tasks on a separate thread/process than the calling thread/process. Keeping the orchestration layer of the function platform from blocking for long periods of time just makes sense. You should not block the calling layer for long running functions as it will seriously degrade the platform.

  • William, Azure functions (on the default Consumption Plan), have a 5 minute timeout. https://github.com/Azure/azure-webjobs-sdk-script/issues/18 – Nathan Mar 03 '17 at 09:08
  • 3
    Hi William, thanks for the edit for clarity on what you meant. If what you're proposing does indeed work (I'm not saying it doesn't), then it's certainly not the intended behaviour from everything I've read thus far. Maybe you should ask the azure-functions team for clarification? Until then, I wouldn't really recommend it as a reliable solution: one patch/fix to the platform and your code will go splat.... and probably without you realising it for a while. – Nathan Mar 06 '17 at 09:47
  • 2
    This comment on a MSFT bug thread suggests to me that this answer does not work unless you have the Azure console connected to the VM at the same time. https://github.com/Azure/Azure-Functions/issues/75#issuecomment-285392193 – Chris Rae Apr 03 '17 at 22:11
  • follow up to this conversation, Azure Functions host.json now has a configuration parameter for time out. "In Dynamic SKUs, the valid range is from 1 second to 10 minutes and the default value is 5 minutes. In Paid SKUs there is no limit and the default value is null (indicating no timeout)". https://github.com/Azure/azure-webjobs-sdk-script/wiki/host.json – Nathan Jun 20 '17 at 07:43
  • 1
    This seems a hack till the time Azure blocks it. – Joy George Kunjikkuru Nov 21 '17 at 19:31
  • 6
    Hi there, I work on the Azure Functions team. I'd like to clarify that we do not recommend this pattern - if our infrastructure thinks that your function has completed, then we might spin down that specific instance, killing any background processing that is still running. This might be working for you today but could be broken at any time as we optimize our infrastructure. – Paul Batum Jan 10 '18 at 01:16