Azure Functions

PowerShell Azure Functions Concurrency

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”.

Azure PowerShell Function is queuing requests as there are no available runspaces

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.

Azure PowerShell Function Concurrency Application Settings

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.

Darren Robinson

Bespoke learnings from a Microsoft Identity and Access Management Architect using lots of Microsoft Identity Manager, Azure Active Directory, PowerShell, SailPoint IdentityNow and Lithnet products and services.

Recent Posts

Visualising your IP Address using PowerShell and AI

A few weeks back the Microsoft AI Tour was in Sydney Australia. There was a…

3 weeks ago

Where the heck is the PowerShell Module loading from?

If you're anything like me you always have PowerShell open, and often both PowerShell and…

4 months ago

Express Verified ID Setup

Decentralised Identity is a technology I'm passionate about and have written many posts and tools…

5 months ago

Orchestrating 1Password with PowerShell

Over two years ago I authored a PowerShell Module that enabled the automation of 1Password.…

8 months ago

Entra ID Tenant ID & Custom Domains PowerShell Module

Buried in my PowerShell Snippets Vol 4 post from 2021 is the PowerShell script and…

8 months ago

Windows Subsystem for Linux instance has terminated

Short post on how to recovery from "The Windows Subsystem for Linux instance has terminated"…

9 months ago

This website uses cookies.