Recently we have been receiving a lot of questions on how to integrate Telerik’s ASP.NET controls in a Load Balanced Environment. So, we have decided to shed some light on the subject in this blog post. More and more web developers decide to distribute workload across multiple computers, network links, or other resources, because this is one of the most efficient ways to avoid overload, minimize the response time and in the same time achieve optimal resource utilization and maximize network throughput. Brace yourself for a short journey through the web backend ecosystem.
WebGarden is the scenario in which a single physical machine is used for multiple worker processes running simultaneously. Each worker process is responsible for handling all kinds of requests, responses, session data, cache data, etc. and all the ASP.NET functionality inside IIS runs under the scope of the worker process. By default, every application pool contains a single worker process. A WebSite containing multiple worker processes is called a WebGarden.
Put simply – if you increase the number of worker processes for a given ApplicationPool you get a WebGarden.
WebFarm is called a hosting environment consisting of multiple web servers. All servers in this architecture are connected through a virtual IP behind a Load Balancer, which routes the incoming requests to the servers within the WebFarm. Whenever a client request is received, it will go through the Load Balancer (LB) and then, based on the load of each server, the LB will distribute the request to the corresponding machine. In order to share one and the same Session data, all servers should be configured to use identical machine key.
The Machine Key element configures the keys that are used for encryption and decryption of forms authentication cookie data and ViewState data, verification of the out-of-process session state identification, etc.
In standard applications it is configured automatically and it is different for every single WebApplication.
In a WebFarm configuration, however, to get your site running properly on all the machines you must manually generate specific values for validation and decryption keys and you must use those values on all computers in the WebFarm (i.e. configure the <machineKey> in all web.config files with the same values).
The main reason for using one and the same machine key is the inconsistency in the SessionState – the Session depends a lot on the machine key to keep all the needed data in the SessionState. If you keep the keys with the automatically generated values, every server will access only his own Session data and this will lead to discrepancies between the loaded resources. If there is a reason to use different machine keys, a custom implementation of session state should be provided.
You could see bellow how the Telerik’s ASP.NET ImageEditor might look if the machine key is not set manually, making the control not able to load its resources properly:
The basic steps you should follow in order to manually configure the keys, are:
All you need to do after that is to copy the above generated machine key and add it to the web.config files of the application in all of your servers.
Finally – we get to the main point of the post :-) There are some configurations which have to be made in order to make RadControls work properly in a Load Balanced Environment:
At the end if our short journey we know much more of the surrounding web ecosystem. You should take full advantage of it and provide your customers the best possible experience. Leave a comment below if this helped you get started or you’ve had an interesting case you got running!
Veselina Raykova is a Support Officer in the ASP.NET AJAX division. In her work she is mainly responsible for RadImageEditor, RadFileExplorer and RadSplitter. Apart from work she enjoys photography, design and cooking.
Subscribe to be the first to get our expert-written articles and tutorials for developers!