How to increase concurrency on python function app hosted in app service plan?
Published Jul 24 2023 12:26 AM 2,013 Views
Microsoft

There are multiple ways to increase the concurrency of python function app. I drew an architecture diagram, which can give us an overall understanding of the function app.

 

Tony_Ju_0-1690180358215.png

Based on the diagram, we can see we could increase function app concurrency by increasing instance count, python worker count and thread count. To better understand this, I build several labs to validate this. I will not demonstrate instance count as it is easy to understand. All these labs are having 4 concurrent incoming requests and each request takes 10 seconds to complete.

 

Lab1:

code:

sync

Tony_Ju_1-1690180745882.png

Configuration:

maxConcurrentRequests : 4
FUNCTIONS_WORKER_PROCESS_COUNT=1
PYTHON_THREADPOOL_THREAD_COUNT=1

Result:

It took 40 seconds to complete the 4 executions. We can see these 4 executions were triggered at the same time, this is because the function host level is using async. But actually these executions are executed one by one.

Tony_Ju_2-1690180923702.png

Lab2:

code: The same as Lab1.

Configuration:

maxConcurrentRequests : 4
FUNCTIONS_WORKER_PROCESS_COUNT=1
PYTHON_THREADPOOL_THREAD_COUNT=2

Result:

It took 20 seconds to complete the 4 executions.

Tony_Ju_3-1690181157611.png

 

Lab3:

code: The same as Lab1.

Configuration:

maxConcurrentRequests : 4
FUNCTIONS_WORKER_PROCESS_COUNT=2
PYTHON_THREADPOOL_THREAD_COUNT=2

Result:

It took 10 seconds to complete the 4 executions.

Tony_Ju_4-1690181254452.png

Lab4:

code:

async

Tony_Ju_5-1690181354661.png

Configuration:

maxConcurrentRequests : 4
FUNCTIONS_WORKER_PROCESS_COUNT=1
PYTHON_THREADPOOL_THREAD_COUNT=1

Result:

It took 10 seconds to complete the 4 executions.

Tony_Ju_6-1690181444004.png

 

Conclusion:

1.We can increase the concurrency by increasing FUNCTIONS_WORKER_PROCESS_COUNT and PYTHON_THREADPOOL_THREAD_COUNT. Just note that we can configure the concurrent setting in host.json file. This is the bottleneck of the concurrency. 

2.It is more recommended to use async method instead of sync method as async has better performance than sync with the same configuration.

 

Reference link:

Azure Functions HTTP triggers and bindings | Microsoft Learn

Improve throughput performance of Python apps in Azure Functions | Microsoft Learn

 

 

Co-Authors
Version history
Last update:
‎Jul 24 2023 12:26 AM
Updated by: