Scaling synchronous IO-bound Python apps in Azure functions

TIL: By default, an Azure function host instance has a single language worker process that runs function invocations in a thread pool with at most min(32, os.cpu_count() + 4)1 worker threads.

Ideally, if your app is IO-bound, you’d use coroutines that will run in an event loop (async functions), but if you’re working with non-async legacy code, the cheapest option might be to play with the two application settings

to ramp up the number of processes (max: 10) and threads (max: 32), and measure the throughput. More info on improving throughput of Python Azure functions can be found in Azure’s documentation.


  1. This is the default value of max_workers on the ThreadPoolExecutor since Python 3.8. os.cpu_count() returns the number of logical CPUs on your system, so the thread pool has at least 5 threads by default, increasing with the number of CPUs up to a maximum total of 32 threads.↩︎