1

If I schedule a timer triggered Azure function to run every second and my function is taking 2 seconds to execute, will I just get back-to-back executions or will some execution queue eventually overflow?

Background:

We have an timer triggered Azure function that is currently executing every 30 seconds and is checking for new rows in a database table. If there are new rows, the data will be processed and the rows will be marked as handled.

If there are no new rows the execution is very fast. If there are 500 new rows (which is the max we are fetching at the moment) the execution takes about 20-25 seconds.

We would like to decrease the interval to one second to reduce the latency or row processing.

Update: I want back-to-back executions and I want to avoid overlapping executions.

Mathias Rönnlund
  • 4,078
  • 7
  • 43
  • 96
  • 1
    Its not clear to me whether you want them to run concurrently (overlapping) or not. By default they can be. If you dont want that, look at Durable Functions. There you can build a chain that will only execute sequentially – silent Aug 20 '21 at 07:42

1 Answers1

1

Multiple azure functions can run concurrently. This is means you can still trigger the function again while the previous triggered function is still running. They will both run concurrently. They will only queue up if you setup options to run only 1 function at a time on 1 instance but doesn't look like you want that.

With concurrency, this means that 2 functions will read the same table on the DB at the same time. So you should read your table with UPDLOCK option LINK. This will prevent the subsequent triggered function from reading the same rows that were read in the previous function.

In short, the answer to your question is neither. If your functions overlap, by default, you will get multiple functions running at the same time. LINK

To achieve back to back execution for time triggers, set WEBSITE_MAX_DYNAMIC_APPLICATION_SCALE_OUT and FUNCTIONS_WORKER_PROCESS_COUNT as 1 in the application settings configuration. This will ensure only 1 function executes runs at a time . See this LINK.

Anupam Chand
  • 2,209
  • 1
  • 5
  • 14
  • So to get back-to-back execution and avoid overlapping executions, I just have to make sure that we only have one instance running? For service bug triggered functions we can set maxConcurrentCalls, but how to limit the instances for timer triggered functions? – Mathias Rönnlund Aug 23 '21 at 10:03
  • 1
    To achieve back to back execution for time triggers, set WEBSITE_MAX_DYNAMIC_APPLICATION_SCALE_OUT and FUNCTIONS_WORKER_PROCESS_COUNT as 1 in the application settings configuration. This will ensure only 1 function executes runs at a time . See this https://learn.microsoft.com/en-us/azure/azure-functions/functions-app-settings. – Anupam Chand Aug 24 '21 at 03:03
  • @MathiasRönnlund I hope you have got the answer you were looking for. If yes, kindly mark the reply as the answer so everyone will know that this question has been closed. – Anupam Chand Aug 27 '21 at 02:20
  • I think that your comment is the answer, so if you update your answer I will gladly mark it as the answer. – Mathias Rönnlund Sep 01 '21 at 05:33