Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
926 views
in Technique[技术] by (71.8m points)

multithreading - Azure Functions concurrency: maxConcurrentRequests vs FUNCTIONS_WORKER_PROCESS_COUNT

How to see difference between maxConcurrentRequests vs FUNCTIONS_WORKER_PROCESS_COUNT in terms of concurrency and limits for Azure Functions.

We can find some definitions at https://docs.microsoft.com/en-us/azure/azure-functions/functions-best-practices that I have pasted below:

Use multiple worker processes

By default, any host instance for Functions uses a single worker process. To improve performance, especially with single-threaded runtimes like Python, use the FUNCTIONS_WORKER_PROCESS_COUNT to increase the number of worker processes per host (up to 10). Azure Functions then tries to evenly distribute simultaneous function invocations across these workers.

The FUNCTIONS_WORKER_PROCESS_COUNT applies to each host that Functions creates when scaling out your application to meet demand.

Configure host behaviors to better handle concurrency

The host.json file in the function app allows for configuration of host runtime and trigger behaviors. In addition to batching behaviors, you can manage concurrency for a number of triggers. Often adjusting the values in these options can help each instance scale appropriately for the demands of the invoked functions.

Settings in the host.json file apply across all functions within the app, within a single instance of the function. For example, if you had a function app with two HTTP functions and maxConcurrentRequests requests set to 25, a request to either HTTP trigger would count towards the shared 25 concurrent requests. When that function app is scaled to 10 instances, the ten functions effectively allow 250 concurrent requests (10 instances * 25 concurrent requests per instance).

Other host configuration options are found in the host.json configuration article https://docs.microsoft.com/en-us/azure/azure-functions/functions-host-json.

{
    "extensions": {
        "http": {
            "routePrefix": "api",
            "maxOutstandingRequests": 200,
            "maxConcurrentRequests": 100,
            "dynamicThrottlesEnabled": true,
            "hsts": {
                "isEnabled": true,
                "maxAge": "10"
            },
            "customHeaders": {
                "X-Content-Type-Options": "nosniff"
            }
        }
    }
}

EDIT: <Its not related to question, but its good to know that to>

From https://docs.microsoft.com/en-us/azure/azure-functions/functions-bindings-http-webhook-trigger?tabs=csharp#limits

Limits

The HTTP request length is limited to 100 MB (104,857,600 bytes), and the URL length is limited to 4 KB (4,096 bytes). These limits are specified by the httpRuntime element of the runtime's Web.config file.

If a function that uses the HTTP trigger doesn't complete within 230 seconds, the Azure Load Balancer will time out and return an HTTP 502 error. The function will continue running but will be unable to return an HTTP response. For long-running functions, we recommend that you follow async patterns and return a location where you can ping the status of the request. For information about how long a function can run, see Scale and hosting - Consumption plan.

question from:https://stackoverflow.com/questions/66046653/azure-functions-concurrency-maxconcurrentrequests-vs-functions-worker-process-c

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

How to see difference between maxConcurrentRequests vs FUNCTIONS_WORKER_PROCESS_COUNT in terms of concurrency and limits for Azure Functions.

  • Both parameters work independently.
  • Both work at host level. Not per function, not per function app, but per host.

I.e. maxConcurrentRequests is enforced across all function executions within a host irrespective of FUNCTIONS_WORKER_PROCESS_COUNT.

Few things in case it's not clear:

  • If Azure decides that your App needs to scale and creates a new host, and say there are two hosts, then values of these params are applied per host not across host.
  • If your App has multiple Functions then maxConcurrentRequests applies to-all/across Functions within this host, not per Function.
  • Default and allowed value vary by plan/language-runtime:
    • maxConcurrentRequests: The default for a Consumption plan is 100. The default for a Dedicated plan is unbounded (-1).
    • FUNCTIONS_WORKER_PROCESS_COUNT: ...default value of 1. The maximum value allowed is 10. ... This setting applies to all non-.NET languages.

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

2.1m questions

2.1m answers

60 comments

57.0k users

...