Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Azure function: limit the number of calls per second

I have an Azure function triggered by queue messages. This function makes a request to third-party API. Unfortunately this API has limit - 10 transactions per second, but I might have more than 10 messages per second in service bus queue. How can I limit the number of calls of Azure function to satisfy third-party API limitations?

like image 535
Andrei Avatar asked Mar 17 '18 18:03

Andrei


People also ask

Do Azure Functions have a time limit?

Longer run durationFunctions in a Consumption plan are limited to 10 minutes for a single execution. In the Premium plan, the run duration defaults to 30 minutes to prevent runaway executions. However, you can modify the host.

How do I throttle Azure function?

In order to limit inbound HTTP traffic or a number of incoming messages from EventHub, there is a need to edit the host. json configuration file of Azure Function. Bear in mind that online edit in SCM or Portal will restart an application.

How do I scale an Azure function?

✔ Scales automatically, even during periods of high load. Automatically scales based on demand using pre-warmed workers, which run applications with no delay after being idle, runs on more powerful instances, and connects to virtual networks.

How do I increase the timeout on my Azure function?

json. In a recent update, the Azure Functions team at Microsoft has added a configuration option that enables an Azure Functions App to have the timeout increased. To implement this, the functionTimeout property within the host. json file for an Azure Function App can be set to a timespan duration of 10 minutes.


1 Answers

Unfortunately there is no built-in option for this.

The only reliable way to limit concurrent executions would be to run on a fixed App Service Plan (not Consumption Plan) with just 1 instance running all the time. You will have to pay for this instance.

Then set the option in host.json file:

"serviceBus": {
    // The maximum number of concurrent calls to the callback the message
    // pump should initiate. The default is 16.
    "maxConcurrentCalls": 10
}

Finally, make sure your function takes a second to execute (or other minimal duration, and adjust concurrent calls accordingly).

As @SeanFeldman suggested, see some other ideas in this answer. It's about Storage Queues, but applies to Service Bus too.

like image 86
Mikhail Shilkov Avatar answered Sep 24 '22 12:09

Mikhail Shilkov