15

I have one Azure App Service in which I have created 5 instances using App Service Plan Scale Out option. Now I am not sure how does Azure load balances requests between this instances? I am not seeing any load balancer for it.

Also how can I know that which request is being served by which instance?

Rushi Soni
  • 1,088
  • 1
  • 13
  • 21

1 Answers1

22

The load balancer is created automatically and you can't see it.

Basically it sends the requests to instances at random, though it can be made "sticky" with ARR Affinity. You can find the setting in the App Service's Application Settings:

ARR Affinity toggle in Portal

If it is on, the load balancer will attach a cookie to responses if they don't already have it. It makes it so that future requests hit the same instance. Though of course if the instance is no longer there (because of auto-scale for example), then it will again go to a random instance.

The WEBSITE_INSTANCE_ID environment variable can tell you in the back-end which instance is handling the request. You can find a list of available variables here: https://github.com/projectkudu/kudu/wiki/Azure-runtime-environment

juunas
  • 54,244
  • 13
  • 113
  • 149
  • @juunas when I open CMD/Powershell of App Service, which instance is used? Also when I deploy using Visual Studio publish, will it be deployed to all the scaled out instances? – Rushi Soni Apr 05 '18 at 06:53
  • To the first question, I have no idea :D But yes, you will deploy to all instances. – juunas Apr 05 '18 at 06:54
  • 1
    You can try `echo %WEBSITE_INSTANCE_ID%` in the CMD :) – juunas Apr 05 '18 at 06:54
  • Ya I can always use that, but I was wondering if there is any way to access all instances' CMD/Powershell. – Rushi Soni Apr 05 '18 at 06:56
  • 1
    Hmm.. not sure. Probably not. The filesystem is shared between the instances though. – juunas Apr 05 '18 at 06:57
  • 1
    You can tell Kudu which instance you want to connect to by overriding the cookie. As juunas mentioned, you should never need to do this since the file system is common across instances, mounted over the network (d:\home that is). See David's answer for more - https://stackoverflow.com/a/34833769/4148708 – evilSnobu Apr 05 '18 at 14:51