Transferred from: http://blog.csdn.net/shaunfang/article/details/9091491
Azure provides free load balancing for websites, cloud services, and virtual machines. What we need to pay attention to about load balancing is its handling of the session. In general, the traditional load balancer has a mechanism called session sticky (sticky), that is, according to the user's session information to forward the user request to a fixed machine, so that if the application on the server side store session information, Then the user interacts with the server will be smooth, otherwise, the user session is lost and the application of logical exceptions
On azure, the load balancer for cloud services and virtual machines is purely network-level, and its equalization mechanism is to rotate the request to the backend server without supporting session stickiness. This requires the background server is stateless, that is, regardless of the customer request to any one server, can be processed correctly. If the existing application is stateful, there are two workarounds:
- The session information is shared among all servers. Implementation methods include: Distributed cache (such as Memcache,azure Caching), Session persistence (. NET and Java both support the use of databases to store session information, while Azure also supports persisting. NET session information with cache and Azure storage: http://blogs.msdn.com/b/cie/archive/2013/05 /17/session-state-management-in-windows-azure-web-roles.aspx)
- Configure your own load Balancing cluster on a virtual machine, such as squid (Linux), IIS ARR (Windows). Microsoft's Msopentech team provides a way to automatically configure IIS arr: https://github.com/MSOpenTech/WindowsAzureToolkitForEclipseWithJava/tree/ Master/utils/arrconfigurationagent. It was originally intended to configure the Java cluster within the cloud service, or it could be used to configure other IIS clusters
The Web service has a slightly different load balancer, and its load balancing is implemented by IIS arr, so it natively supports session sticky. The implementation principle is to add arraffinity this cookie in each response, so that the next time the same user's request is identified and sent to the last server. That is, regardless of whether the app is actively writing cookies or accessing Session,iis, it maintains the server's binding relationship for each user.