It’s been a while since I’ve developed any Azure Functions. There was a time, where I was knocking them out very regularly. Well this week whilst working on a new project I jumped back into PowerShell Azure Functions, and cloud being cloud they’ve moved on in recent times. PowerShell is now a supported language (with the release of PowerShell 7) which is awesome. Goodbye Experimental Language warnings. However I quickly ran into what appears to be a common(ish) issue on the Azure Functions Consumption Plan of PowerShell Azure Functions Concurrency.
Background
The particular scenario I had is;
- an Azure Function App that contains three PowerShell Functions
- these functions were often being executed simultaneously
- under the Azure Function App Consumption Plan there is only a single CPU available
- by default the FUNCTIONS_WORKER_PROCESS_COUNT application setting is 1 and the PSWorkerInProcConcurrencyUpperBound is also 1
- the combination of these factors meant my functions were timing out
The Error and Symptoms
When I looked in the event logs, when concurrent requests were being made I was seeing timeouts and the following error.
“Azure PowerShell Function is queuing requests as there are no available runspaces”.
![](https://blog.darrenjrobinson.com/wp-content/uploads/2020/10/Azure-PowerShell-Function-is-queuing-requests-as-there-are-no-available-runspaces.png)
The Resolution
The resolution that worked for me after a lot of reading and understanding the profile of my Functions was to set;
- FUNCTIONS_WORKER_PROCESS_COUNT = 4
- PSWorkerInProcConcurrencyUpperBound = 4
These are Application Settings. You configure them on your Azure Function App. For more information on these settings refer to the documentation here. If you encounter this problem a configuration that works for you will depend on how many functions you have, how long they run for and the concurrency across them.
![](https://blog.darrenjrobinson.com/wp-content/uploads/2020/10/Azure-PowerShell-Function-Concurrency-Application-Settings.png)
Summary
If you are running multiple PowerShell Azure Functions in the same Azure Function App on the Consumption Plan there is a high chance you are going to run into an issue with PowerShell Azure Functions Concurrency. You will need to workout the profile of your functions and update the Functions_Worker_Process_Count and PSWorkerInProcConcurrencyUpperBound Application Configuration settings accordingly.