Jump to content

How to increase concurrency on python function app hosted in app service plan?

Featured Replies

Posted

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.

 

 

 

660x321vv2.png.6e5a5cc3d5b63851247813d5558a9737.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

 

711x137vv2.png.cabc4d5d4a3b08c6f1bf40488c53148a.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.

 

largevv2px999.png.2a6a8bbc2f813694a6be5c5451d48b53.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.

 

largevv2px999.png.72476318f0d52fdccc44e5b20334cfc9.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.

 

largevv2px999.png.4763c21cd0bb84d44cd3cdee13cc5521.png

 

Lab4:

 

code:

 

async

 

685x85vv2.png.c79455906d8341d2769f61ebadf1f281.png

 

Configuration:

 

maxConcurrentRequests : 4

FUNCTIONS_WORKER_PROCESS_COUNT=1

PYTHON_THREADPOOL_THREAD_COUNT=1

 

Result:

 

It took 10 seconds to complete the 4 executions.

 

largevv2px999.png.7c57025b94f1371744e0f09627d8082f.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

 

Continue reading...

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...