Mathias Rönnlund
Mathias Rönnlund

Reputation: 4855

Executing Azure Function back to back

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.

Upvotes: 1

Views: 894

Answers (1)

Anupam Chand
Anupam Chand

Reputation: 2722

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.

Upvotes: 1

Related Questions