Preparing ASP.NET Applications For Load Balancing

пятница, 20 августа 2010, Александр Краковецкий

Web farms are used when a singe server can’t process all requests. In this case multiple servers are used for load balancing.

How does it work?

The concept behind Network Load Balancing is pretty simple: Each server in a Load Balancing Cluster is configured with a "virtual" IP address. This IP address is configured on all the servers that are participating in the load balancing "cluster" (a loose term that's unrelated to the Microsoft Cluster Service). Whenever a request is made on this virtual IP a network driver on each of these machines intercepts the request for the IP address and re-routes the request to one of the machines in the Load Balancing Cluster based on rules that you can configure for each of the servers in the cluster. Microsoft this process Network Load Balancing (NLB). Figure 1 shows how the process works graphically. [3]

Figure 1

The same machineKey for all servers in web farm

Every server in the web farm must use the same machineKey (it can be placed in the web.config somewere in the node – this will allow to use web farm for single application):



Please read this article for more details.

If you want to use web farm for all applications installed on the servers you need to configure machineKey directly in the machine.config files for all servers.

Please refer to the http://www.eggheadcafe.com/articles/GenerateMachineKey/GenerateMachineKey.aspx to generate machineKey.

Configure Session State for database

Run the InstallSqlState.sql script on the Microsoft SQL Server where you intend to store session state if you want to use default ASPState database. This script will create the necessary database and database objects. For removing session state support you have to run UninstallSqlState.sql file.

If you want to use your own database – replace all occurrences of "DatabaseNamePlaceHolder" in InstallSqlStateTemplate.sql  by own database name. For removing session state support you have to run UninstallSqlStateTemplate.sql file.

These files are located in the %system_drive%/Windows/Microsoft.NET/Framework64/%.NET_Framework_version% for 64-bit systems and in the %system_drive%/Windows/Microsoft.NET/Framework/%.NET_Framework_version%  for x86 ones.

Also you can configure  your database by using aspnet_regsql tool.

The command line should looks like as the following:

aspnet_regsql -ssadd -d  %your_database_name -S %your_sql_server_name% -sstype c –E

In the web.config you need to configure sessionState:

       mode="SQLServer"
       allowCustomSqlDatabase="true"
       sqlConnectionString="data source=%server_name%;Initial Catalog=%database_name%;User ID=%user%;Password=%password%"
       cookieless="false" />

Don’t forget to write allowCustomSqlDatabase="true" if you are using own database for storing ssession state, otherwise it’s not needed.

For session state to be maintained across different web servers in the web farm, the application path of the website (for example. \LM\W3SVC\2) in the IIS metabase should be identical in all the web servers in the web farm.

All objects must be serializable

Ensure that all objects that are used are checked as [Serializable]. Also if you try to store instance of a class that is not marked as serializable into a session variable, the request returns without an error. However, Asp.net actually fails to save the session data and blocks subsequent requests in the same session. (Because the class is not marked as serializable).

All files must be synchronized

You need to ensure that the all files are present in the right path on all the servers, and that their contents are continuously in sync. You can copy files to servers by using any standard file copy or synchronization method (e.g. msdeploy tool).

References for more info:

  1. WEB farm - Load Balancing in Asp.net
  2. Exploring Session in ASP.Net
  3. Web Farming with the Network Load Balancing Service in Windows Server 2003
  4. ASP.NET SQL Server Registration Tool (Aspnet_regsql.exe)

Компании из статьи


Microsoft Украина


Сайт:
http://www.microsoft.com/ukr/ua/

Microsoft Украина Украинское подразделение компании Microsoft.

Ищите нас в интернетах!

Комментарии

Свежие вакансии