Reputation: 22114
I have a scenario where one of my Class has a static member whose value I can set from a Function App. Suppose another Function App belonging to same App Service Plan also uses this same class and also sets/relies on the value of the static member. Now, if the two function apps never run simultaneously, we have no issue. Also, if they don't run under same instance, then we also have no issue as each running instance will have their own definition of the class.
My question is, do each Function App from same App Service run on different instance?
I understand redesigning will eliminate any possible issues, but I am just curious on the interaction between Function Apps in same App Service.
Upvotes: 4
Views: 1524
Reputation: 470
My question is, do each Function App from same App Service run on different instance?
I don't think this is possible, just as others have answered. All function apps are run on all the instances provisioned by your App Service Plan. But.. having said that, using per app scaling it is possible to limit the number of instance that a particular app service can be run on during scale out. I have not used this for Function Apps backed by App Service Plan; but an interesting read [https://learn.microsoft.com/en-us/azure/app-service/manage-scale-per-app]
From MS docs
When using App Service, you can scale your apps by scaling the App Service plan they run on. When multiple apps are run in the same App Service plan, each scaled-out instance runs all the apps in the plan.
Per-app scaling can be enabled at the App Service plan level to allow for scaling an app independently from the App Service plan that hosts it. This way, an App Service plan can be scaled to 10 instances, but an app can be set to use only five.
Further, to your query on my comment; I think there are two cases here
a) Multiple Function Apps using the same App Service Plan using shared static class with static member
b) Multiple functions within the same Function App using shared static class with static member.
In both cases your static members are not shared. They are per function scope only. Just to be sure, I created two functions, FunctionA and FunctionB under a Function App (FunctionApp1). In both the functions, I refer to a static class Static1. I noticed that changes I make to the static members from FunctionA is not visible to FunctionB.
However, the static member state is preserved between multiple invocations of the same function under the Function App
I found a somewhat related question here https://stackoverflow.com/a/44971720/5344880
one another case would be different Function Apps using the same shared static class and I am reasonably sure that in this case the static class's static member's state is not shared.
Upvotes: 2
Reputation: 31
I think it will be better for you to understand the process boundaries.
You have an Azure Function App (FuncApp1.azurewebsites.net) that may have one or more functions hosted on an App Service Plan. You're mentioning that you have another Azure Function App (FuncApp2.azurewebsites.net) with one or more of it's own set of functions hosted on the same App Service Plan. Is this correct?
FuncApp1 will have it's own process id, memory/cpu consumption, and threads on some machine in the cloud and the same for FuncApp2. The static member basically exists independently in two separate programs. In the case where your function app may scale out, each new instance will most likely have it's own process id, etc.
So NO your function apps will not step on each other. Your only concern should be if the static member is thread safe within the same process id. In what scenario are you relying on a static member that may be altered per request? Some incrementing ID?
Upvotes: 2
Reputation: 15639
Each function app from same App Service plan will run on every instances.
For example, if you have an app service plan which has 3 instances, your function app will run on each instances.
So for your question
do each Function App from same App Service run on different instance?
The answer is no, function apps from same App Service will run on the same instance.
Upvotes: 0