Some of you who develop on Azure's App Service platform may have noticed this new switch in Application Settings:
So what is ARR Affinity and why does it improve performance?
If ARR Affinity is enabled, the IIS server acting as the load balancer will place a cookie on responses that causes a user to always hit the same instance within their session. This is good for legacy application compatibility as they may not have been designed with load balancing in mind.
But if your app has been designed for load balancing (i.e. your app is stateless, session state stored elsewhere), you should disable this.
So how can it improve performance? By disabling ARR Affinity, the load balancer is free to distribute the traffic as it wants. This means each instance's individual workload is much more even.
It's nice we finally got a switch for this as previously you would either have to open Resource Explorer and edit the app (note the clientAffinityEnabled flag):
The other option would be to set a response header "Arr-Disable-Session-Affinity: true". Like this:
<system.webServer> <httpProtocol> <customHeaders> <add name="Arr-Disable-Session-Affinity" value="true" /> </customHeaders> </httpProtocol> </system.webServer>
While ARR Affinity helps with compatibility, it cannot be a final solution for an app. For one thing, you cannot enable Auto-scale as it would all come crashing down when one of the instances gets put down by auto-scale. And hardware failures happen, an instance might get killed because of that as well.
Bottom line: Enable ARR Affinity if your app stores state on the instance, otherwise disable it.